From patchwork Tue May 30 13:05:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Schmelzer X-Patchwork-Id: 768594 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3wcYl45gFGz9s78 for ; Tue, 30 May 2017 23:06:07 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 7F638C21C6F; Tue, 30 May 2017 13:05:59 +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=none 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 CDB68C21C3D; Tue, 30 May 2017 13:05:55 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 1FF20C21C3D; Tue, 30 May 2017 13:05:54 +0000 (UTC) Received: from mail2.br-automation.com (mail.br-automation.com [213.33.116.60]) by lists.denx.de (Postfix) with ESMTPS id B9B3CC21C3C for ; Tue, 30 May 2017 13:05:53 +0000 (UTC) X-AuditID: c0a80110-569ff70000000e15-35-592d6e2e3381 Received: from brsmtp01.br-automation.com (Unknown_Domain [192.168.1.60]) by mail2.br-automation.com () with SMTP id 5B.C5.03605.E2E6D295; Tue, 30 May 2017 15:05:53 +0200 (CEST) MIME-Version: 1.0 From: Hannes Schmelzer To: u-boot@lists.denx.de Date: Tue, 30 May 2017 15:05:44 +0200 Message-Id: <1496149544-32348-1-git-send-email-hannes.schmelzer@br-automation.com> X-Mailer: git-send-email 1.9.1 X-MIMETrack: Itemize by SMTP Server on BRSMTPINTERN2/InternSMTP(Release 9.0.1FP5|November 22, 2015) at 30/05/2017 15:06:19, Serialize by Router on BRSMTPINTERN2/InternSMTP(Release 9.0.1FP5|November 22, 2015) at 30/05/2017 15:06:24, Serialize complete at 30/05/2017 15:06:24, Itemize by SMTP Server on BRSMTP01/Eggelsberg/AT/B&R(Release 9.0.1FP5|November 22, 2015) at 30.05.2017 15:05:49 X-TNEFEvaluated: 1 X-Disclaimed: 13699 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprMLMWRmVeSWpSXmKPExsVyYAWjja5hnm6kwcRTvBbftmxjtHi7t5Pd gcljdsNFFo+zd3YwBjBFcdmkpOZklqUW6dslcGUcfvmPuWCmaMXvdx3sDYz9Al2MnBwSAiYS 1y9fY+1i5OIQEtjMKPH45EdmkASvgKDEyZlPWEBsNgFriUvXj4DFRQQkJH71X2UEsZkFoiQO nm9iA7GFBbwkzu3fxgpiswioSpz+3s0IMSdIYtaC/0wQ9doSyxa+ZoZYLCdx8thksMUSAh3M Ev8/7INKCEmcXnwWyhaWuLfpJtMERr5ZSG6ahWTWAkamVYziuYmZOUZ6SUW6iaUl+bmJJZn5 eXrJ+bmbGCFBJbCDcfcb7UOMAhyMSjy8Qmm6kUKsiWXFlbmHGCU4mJVEeFfkAIV4UxIrq1KL 8uOLSnNSiw8xSnOwKInzcmmpRgoJpCeWpGanphakFsFkmTg4pRoYNYu/6mcsWrdk3ssIhsVb 9jirG7nXPPZKlirul7EsLmL6+trPUbZXW/P/8ZLt87S7FWKjeNc1m5qlz7nOJsg+ifvjU8O7 pw2T37Dc5CnlurKpPHaFZk/FbIcYuYDgnN4zbvd0wrMWai/ZEMD48andmtuzOXUYd4ZP7tp2 yShwnk66X5+gaJUSS3FGoqEWc1FxIgCv4TRIJgIAAA== Subject: [U-Boot] [PATCH] cmd/fdt: support single value replacement within an array 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: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" With this commit we can modify single values within an array of a dts property. This is useful if we have for example a pwm-backlight where we want to modifiy the pwm frequency per u-boot script. The pwm is described in dts like this: backlight { pwms = <0x0000002b 0x00000000 0x004c4b40>; }; For changing the frequency, here the 3rd parameter, we simply type: fdt set /backlight pwms ; For doing all this we: - backup the property content into our 'SCRATCHPAD' - only modify the array-cell if the new content doesn't start with '?' Signed-off-by: Hannes Schmelzer Reviewed-by: Simon Glass --- cmd/fdt.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/cmd/fdt.c b/cmd/fdt.c index a21415d..e55102a 100644 --- a/cmd/fdt.c +++ b/cmd/fdt.c @@ -257,6 +257,7 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) char *prop; /* property */ int nodeoffset; /* node offset from libfdt */ static char data[SCRATCHPAD]; /* storage for the property */ + const void *ptmp; int len; /* new length of the property */ int ret; /* return value */ @@ -268,13 +269,6 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) pathp = argv[2]; prop = argv[3]; - if (argc == 4) { - len = 0; - } else { - ret = fdt_parse_prop(&argv[4], argc - 4, data, &len); - if (ret != 0) - return ret; - } nodeoffset = fdt_path_offset (working_fdt, pathp); if (nodeoffset < 0) { @@ -286,6 +280,21 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return 1; } + if (argc == 4) { + len = 0; + } else { + ptmp = fdt_getprop(working_fdt, nodeoffset, prop, &len); + if (len > SCRATCHPAD) { + printf("prop (%d) doesn't fit in scratchpad!\n", + len); + return 1; + } + memcpy(data, ptmp, len); + ret = fdt_parse_prop(&argv[4], argc - 4, data, &len); + if (ret != 0) + return ret; + } + ret = fdt_setprop(working_fdt, nodeoffset, prop, data, len); if (ret < 0) { printf ("libfdt fdt_setprop(): %s\n", fdt_strerror(ret)); @@ -766,7 +775,11 @@ static int fdt_parse_prop(char * const *newval, int count, char *data, int *len) cp = newp; tmp = simple_strtoul(cp, &newp, 0); - *(fdt32_t *)data = cpu_to_fdt32(tmp); + if (*cp != '?') + *(fdt32_t *)data = cpu_to_fdt32(tmp); + else + newp++; + data += 4; *len += 4;