From patchwork Mon Sep 4 20:12:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pantelis Antoniou X-Patchwork-Id: 809824 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=konsulko.com header.i=@konsulko.com header.b="Uy4+uqu+"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xmLfR3KjKz9t2R for ; Tue, 5 Sep 2017 06:14:23 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 08474C21F12; Mon, 4 Sep 2017 20:13:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 4B1E5C21F2F; Mon, 4 Sep 2017 20:13:00 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id D172AC21F02; Mon, 4 Sep 2017 20:12:55 +0000 (UTC) Received: from mail-wm0-f48.google.com (mail-wm0-f48.google.com [74.125.82.48]) by lists.denx.de (Postfix) with ESMTPS id 307AAC21C2F for ; Mon, 4 Sep 2017 20:12:54 +0000 (UTC) Received: by mail-wm0-f48.google.com with SMTP id f145so6735094wme.0 for ; Mon, 04 Sep 2017 13:12:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zkVmHlvGrK4jP3lqjdj93xMas1MSP0Ebeyk1NLM8jOc=; b=Uy4+uqu+RyOAmUng1iQeGcNNEtvp6zUNAYgPXDvBmrBhO5jkd9U+gfJEFrUT8OMi8u d4/8eYMQgbUNTWUeEYiwGf5yyf2tDndKP1L3w438A+Kyz4RwGSRlWzl52w4Hog9aGC5A EcySdKwDWFYazOeIECNDaIbJ6SR4dN4n89fYs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zkVmHlvGrK4jP3lqjdj93xMas1MSP0Ebeyk1NLM8jOc=; b=ej+BV/ZuZYhVyaPqMMjZAUcHcUxfRBJlv1U3XT2iTii1iN6VtxSsG/TktIDe3Vor46 N8L8puQqiiKpbIcPMMNWq/fW0n54Jg2t8h32HMOd4TTSTYmjBSZE3FFU45QBuGs8BdZ6 KplrpHpmu+3CIgd4y8qwDPJUMPDw8FRJgdNaqOYw8OuEVIOe9faxe49n/y8Ta/KarVYp UdDa4zBp4lgBZ86tf7wycFIpeWaT2QX+4leHXVu2XXTSBGjAMZPssV+ACLUFPF6WULuw UHGRd7A+kNm2wK+pfFhRcDJERU5IvK8aDENGM6M9LaH8wIdz4K0JL1cbd5tWw4iWuYqV CfeQ== X-Gm-Message-State: AHPjjUjBPW0r1F/2PADVzpVq9Y6WD68vcW/7iR/0mWvbIbQv4cFlDMah XPm/5zXjW+Kr1B7+ X-Google-Smtp-Source: ADKCNb7pVEAmgAlCYi25I9guWMZlJtr48hcpGsWwQMEP8xwNedzTETfd12VEXvtE6tiSNqjc41xRpg== X-Received: by 10.28.69.15 with SMTP id s15mr815452wma.118.1504555973840; Mon, 04 Sep 2017 13:12:53 -0700 (PDT) Received: from localhost.localdomain ([195.97.110.117]) by smtp.gmail.com with ESMTPSA id u8sm3720435wrc.92.2017.09.04.13.12.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Sep 2017 13:12:53 -0700 (PDT) From: Pantelis Antoniou To: Tom Rini Date: Mon, 4 Sep 2017 23:12:10 +0300 Message-Id: <1504555943-12893-2-git-send-email-pantelis.antoniou@konsulko.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1504555943-12893-1-git-send-email-pantelis.antoniou@konsulko.com> References: <1504555943-12893-1-git-send-email-pantelis.antoniou@konsulko.com> Cc: Marek Vasut , Pantelis Antoniou , Tero Kristo , u-boot@lists.denx.de, Maxime Ripard , Stefan Roese , Alan Ott , David Gibson Subject: [U-Boot] [PATCH v3 01/14] Introduce fdt_setprop_placeholder() method X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" In some cases you need to add a property but the contents of it are not known at creation time, merely the extend of it. This method allows you to create a property of a given size (filled with garbage) while a pointer to the property data will be provided. Signed-off-by: Pantelis Antoniou [dwg: Corrected commit message] Signed-off-by: David Gibson Acked-by: Simon Glass Acked-by: Simon Glass --- lib/libfdt/fdt_rw.c | 20 +++++++++++++++++--- lib/libfdt/libfdt.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/lib/libfdt/fdt_rw.c b/lib/libfdt/fdt_rw.c index 80a3212..3dc7752 100644 --- a/lib/libfdt/fdt_rw.c +++ b/lib/libfdt/fdt_rw.c @@ -228,8 +228,8 @@ int fdt_set_name(void *fdt, int nodeoffset, const char *name) return 0; } -int fdt_setprop(void *fdt, int nodeoffset, const char *name, - const void *val, int len) +int fdt_setprop_placeholder(void *fdt, int nodeoffset, const char *name, + int len, void **prop_data) { struct fdt_property *prop; int err; @@ -242,8 +242,22 @@ int fdt_setprop(void *fdt, int nodeoffset, const char *name, if (err) return err; + *prop_data = prop->data; + return 0; +} + +int fdt_setprop(void *fdt, int nodeoffset, const char *name, + const void *val, int len) +{ + void *prop_data; + int err; + + err = fdt_setprop_placeholder(fdt, nodeoffset, name, len, &prop_data); + if (err) + return err; + if (len) - memcpy(prop->data, val, len); + memcpy(prop_data, val, len); return 0; } diff --git a/lib/libfdt/libfdt.h b/lib/libfdt/libfdt.h index f3f9cad..6af94cb 100644 --- a/lib/libfdt/libfdt.h +++ b/lib/libfdt/libfdt.h @@ -1405,6 +1405,37 @@ int fdt_setprop(void *fdt, int nodeoffset, const char *name, const void *val, int len); /** + * fdt_setprop _placeholder - allocate space for a property + * @fdt: pointer to the device tree blob + * @nodeoffset: offset of the node whose property to change + * @name: name of the property to change + * @len: length of the property value + * @prop_data: return pointer to property data + * + * fdt_setprop_placeholer() allocates the named property in the given node. + * If the property exists it is resized. In either case a pointer to the + * property data is returned. + * + * This function may insert or delete data from the blob, and will + * therefore change the offsets of some existing nodes. + * + * returns: + * 0, on success + * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to + * contain the new property value + * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag + * -FDT_ERR_BADLAYOUT, + * -FDT_ERR_BADMAGIC, + * -FDT_ERR_BADVERSION, + * -FDT_ERR_BADSTATE, + * -FDT_ERR_BADSTRUCTURE, + * -FDT_ERR_BADLAYOUT, + * -FDT_ERR_TRUNCATED, standard meanings + */ +int fdt_setprop_placeholder(void *fdt, int nodeoffset, const char *name, + int len, void **prop_data); + +/** * fdt_setprop_u32 - set a property to a 32-bit integer * @fdt: pointer to the device tree blob * @nodeoffset: offset of the node whose property to change