From patchwork Fri Aug 11 08:52:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pantelis Antoniou X-Patchwork-Id: 800471 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="EnN1ckta"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xTJm61Wt9z9t2W for ; Fri, 11 Aug 2017 18:57:10 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id CDB23C21C4F; Fri, 11 Aug 2017 08:56:28 +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_H2, 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 0F1AAC21DD0; Fri, 11 Aug 2017 08:55:53 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id CE827C21DA1; Fri, 11 Aug 2017 08:55:43 +0000 (UTC) Received: from mail-wr0-f175.google.com (mail-wr0-f175.google.com [209.85.128.175]) by lists.denx.de (Postfix) with ESMTPS id A0CBEC21C97 for ; Fri, 11 Aug 2017 08:55:37 +0000 (UTC) Received: by mail-wr0-f175.google.com with SMTP id 33so11109766wrz.4 for ; Fri, 11 Aug 2017 01:55:37 -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=EnN1ckta74p39oxSEGimob5ktDOTZOqizCo4tyi99kWG6LerA3FRNBAf+odWq9GTOa peTMcX5YMCWj6UGr8tM2bNo7pkLTUBhcVTPy3eJ0xa2Qp3MdYv5jvzUGBeuKHosC64Tt RRVsIwzRAFQC6Gh2qoGJc5jE/uR5LrZUmH6Hc= 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=Tfl2K0Ih3UPVfCi82D/91XVObdHfwpbOMh4v7Bcq7iE+1Qa748l8tzCme7oMpBbzol rWXifHhBNPDeRgv+PlVusn/zjBywwouGF5NU98686PscObMSZqL3+PdUcDoUcroo4AkM v/IaHjLC2Yl6Lmrg2e2fm8YVWrB/YJsNFrK5AjveuA9nXbJla/qNkLoYTQnl+uSgP/NJ 0IiGW/HIBeSpgjWGmKrzqv8WFL6CB1NWzx9gZkibRshSvy0PIiCkFBqJhzLF67SiUtYJ nkm06LYCwFae4A2uNbBLjh/ypujteeKc8+rVcOxLtu628W3Zqa11n0ZX7xJokIztKg3S GgUg== X-Gm-Message-State: AHYfb5hAJn5w3h8fhdErH+rM3FtmaqBB/ebgaS0yxRpJuR+/Z4aNxl9W emYGDMIAFS0MZQdt X-Received: by 10.223.161.133 with SMTP id u5mr11654747wru.191.1502441737329; Fri, 11 Aug 2017 01:55:37 -0700 (PDT) Received: from localhost.localdomain ([195.97.110.117]) by smtp.gmail.com with ESMTPSA id o71sm759811wmg.15.2017.08.11.01.55.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 11 Aug 2017 01:55:36 -0700 (PDT) From: Pantelis Antoniou To: Tom Rini Date: Fri, 11 Aug 2017 11:52:39 +0300 Message-Id: <1502441568-22896-2-git-send-email-pantelis.antoniou@konsulko.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1502441568-22896-1-git-send-email-pantelis.antoniou@konsulko.com> References: <1502441568-22896-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 v2 01/10] 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 Reviewed-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