From patchwork Tue Dec 22 10:32:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 346627 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp5206376jai; Tue, 22 Dec 2020 02:33:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJwDWn/ikjG5/cbUndNM3H8NN3TTNj3suYs0ho64mi5ODw4EzuLxy7t97boW9mxyvteB5Dr/ X-Received: by 2002:a05:6402:2074:: with SMTP id bd20mr19401095edb.326.1608633221964; Tue, 22 Dec 2020 02:33:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608633221; cv=none; d=google.com; s=arc-20160816; b=MAAX8CbXCU5soB+ein1dEpnIG0Mcij9kRpjPsrD4qdrn789Aoj+AnU1Yo5eQtgcygN n+apFGlcPrfqv3Hjg9zeyuPJzXVdOuWLB7kx+0vJGxwjvtJlX49rHUXU7PYCNWKj0LBi SQ7381TaKqXJyZCz/AO7KgvcwJrw8PaBAy+TFercFG1FOoJ0/WY67hPSsxHwIB6hAmXY ZRw6YAr0ymqUT0sPSn1XYIunR4xtDbv586PimcABLicIycXyrdKnJLd6u/yHpg2h1Tsy M8o6N/fqcq8sOK1wzbxetocSWekW2/l3Zk/rbRcubSE1SKnlmdieyyPcN14qm+SBc2jk 3l5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:cms-type:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-filter; bh=Y/waDwXRIxPI3QFJoSNfogvymee7lJaGnjDAGLn1kfw=; b=rzFmMMSvPTfqOyjZYrxkawGGeBYqwWcGxUIJgPUcRHIFtN7VsZZG+19TgeG2KTvSJ7 7uaWstiHVXp7be/hTueTGEH/1TNYkGKM2Vt05F1LEQah96gwL+M9JjHspLjO/LSwU7Fn V9xWCO8Rmx1GA/RzFKPA0uzXHa2G9P+9HTZX/dwgkpacKSY4l1IQkJF6FsV2RLH8fD4z nJC7bjNHQ5vCmZmu8Oq+QgvPbeRm7AhauVu1O+BmquulvySfPfRsDcQq5yCo2bSn7/ax SXtdgUt5zC3nacJ5eGgZtAoxnT+xv7amkKd3tr5Xp8Wr8h/DORUkbBSbEfY/xTAGkpd6 vOAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=JVsZl4Qd; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id r2si11842944edv.308.2020.12.22.02.33.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Dec 2020 02:33:41 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=JVsZl4Qd; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 966AF82A63; Tue, 22 Dec 2020 11:33:00 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=samsung.com header.i=@samsung.com header.b="JVsZl4Qd"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CD0CE82A48; Tue, 22 Dec 2020 11:32:46 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 5486582A47 for ; Tue, 22 Dec 2020 11:32:36 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=m.szyprowski@samsung.com Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20201222103235euoutp0213d3202208d1b3097ae53c9a94a4b41e~TA1UZDhpZ0348103481euoutp02k for ; Tue, 22 Dec 2020 10:32:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20201222103235euoutp0213d3202208d1b3097ae53c9a94a4b41e~TA1UZDhpZ0348103481euoutp02k DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1608633155; bh=Y/waDwXRIxPI3QFJoSNfogvymee7lJaGnjDAGLn1kfw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JVsZl4QdRE9DjVdTwGzUDkXtRwo8evx2bda59d0YXfFDrASyAu/dSQhP3JQTiBt88 uGUmlISkj5QiYbmVnKc5HSu7x3NKyIjEshGLQelx7wudv1zkL3cLyM0sLp5/PHH5kN +ylcblrpTvcszMGuhUyewCAjiH56g9Vvg6+p3dGU= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20201222103235eucas1p203a5a1e46f940b54bd68ca50e2efe731~TA1UFpF-u2800528005eucas1p2W; Tue, 22 Dec 2020 10:32:35 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 6E.40.44805.34BC1EF5; Tue, 22 Dec 2020 10:32:35 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20201222103235eucas1p2ce87ebed371fc7279c57f4e368282b2d~TA1TpJEbR1994519945eucas1p2l; Tue, 22 Dec 2020 10:32:35 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20201222103235eusmtrp2166230d24bdc1fb745a9e6620a8c4731~TA1TokwEf1881618816eusmtrp2a; Tue, 22 Dec 2020 10:32:35 +0000 (GMT) X-AuditID: cbfec7f4-b4fff7000000af05-ab-5fe1cb43db2a Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id D3.EB.21957.34BC1EF5; Tue, 22 Dec 2020 10:32:35 +0000 (GMT) Received: from AMDC2765.digital.local (unknown [106.120.51.73]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20201222103234eusmtip24d88711b6da556af0b07a7d768493ef4~TA1TSZ6EJ3106731067eusmtip2L; Tue, 22 Dec 2020 10:32:34 +0000 (GMT) From: Marek Szyprowski To: u-boot@lists.denx.de Cc: Marek Szyprowski , Lukasz Majewski , Marek Vasut , Jaehoon Chung , Bartlomiej Zolnierkiewicz Subject: [PATCH v2 3/5] dfu: add 'SCRIPT' entity Date: Tue, 22 Dec 2020 11:32:22 +0100 Message-Id: <20201222103224.9018-4-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201222103224.9018-1-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA0WSe0iTYRTGfb/L9mlNvlbhyYRqVNBNy6wWWRYFSTcWRIQR6zNfnHll09Su 2sVslZpR2bCSMjLLayZLkulcbTqdXaaVpqYNypWmVEIztpxf1n+/85zncJ7z8jKkuI/yZaLi ErEyjouRCLyo6ue/WpdsNPfKl7Y0zpRW5JXR0reODFr6afA1IS0xdAmlXzPSkXSg9pxwvSD0 psZEhba816LQrKpiJCPDvIIjcEzUIawMWLffS+FM19IJZxan9KV9odNQjkSNPBlgg6Cj4hVS Iy9GzBYh6LEVUHzxA8FVe4OAL74j0LgcxMRI828nzTfuIWhueUz8G9EN3RG4XQJ2GagH1OM8 jQVwZLchN5PsSwSjruVunsouhe6LH8d1ip0HpgIt7WYRGwz96S6a3zYLHpTXkW72ZNdC4d3+ 8bDAnmOgSJP317QJSs8O/+WpYDdWCXn2A9eTWwQ/cApBr6VEyBcXELw+mYd41xp4b3GMRWXG 4i2AspoAXt4AP9uLhG4ZWG94OzCFP8AbcquvkbwsgswMMe+eDxpj6b+19S9ekTyHwvn2DpJ/ oBwE+TXDdA6apfm/rAChYuSDk1SxkVgVGIeT/VVcrCopLtL/QHxsJRr7Bman8YcW3bMP++sR wSA9AoaUTBOt9O2Ri0URXOphrIyXK5NisEqPZjKUxEcUXvVQLmYjuUQcjXECVk50CcbTN414 YL3Rkm+JeBc+2GNt3NIjCxvNsf7Kj4Hu9X79hjMle81RptrasrmHrnS+4XbbtRUDO/w+TyoU 7KqvKNZmT3+32nk109lZsGXP/GgXetoZ/rtGnJjMJXeh/m8kJT8yG08K1rUPWbT3cbdtlceM KeTum1eOKQ2pxmfHFwlSjiguNZbK6m6P3BlR2Df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Syx9oS+eh1P1cKrbZ/8lFabEFd2ravJ6wFe8O+HTVouvLUYNE3+XCzgmfH Wg742iuxFGckGmoxFxUnAgCsLAvm1gIAAA== X-CMS-MailID: 20201222103235eucas1p2ce87ebed371fc7279c57f4e368282b2d X-Msg-Generator: CA X-RootMTR: 20201222103235eucas1p2ce87ebed371fc7279c57f4e368282b2d X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20201222103235eucas1p2ce87ebed371fc7279c57f4e368282b2d References: <20201222103224.9018-1-m.szyprowski@samsung.com> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Define a new 'SCRIPT' type for DFU entities. The downloaded data are treated as simple u-boot's scripts and executed with run_command_list() function. Flashing the 'SCRIPT' entity might result in changing the 'dfu_alt_info' environment variable from the flashed script, so add a global variable for tracking the potential need to reinitialize the dfu_alt_info related structures. Signed-off-by: Marek Szyprowski --- doc/README.dfu | 17 ++++++++++++++++- drivers/dfu/dfu.c | 7 ++++++- drivers/dfu/dfu_mmc.c | 23 +++++++++++++++++++++-- include/dfu.h | 3 +++ 4 files changed, 46 insertions(+), 4 deletions(-) -- 2.17.1 diff --git a/doc/README.dfu b/doc/README.dfu index 6cb1cba9d7..eacd5bbfb4 100644 --- a/doc/README.dfu +++ b/doc/README.dfu @@ -17,7 +17,7 @@ Overview: - The access to mediums is done in DFU backends (driver/dfu) Today the supported DFU backends are: - - MMC (RAW or FAT / EXT2 / EXT3 / EXT4 file system / SKIP) + - MMC (RAW or FAT / EXT2 / EXT3 / EXT4 file system / SKIP / SCRIPT) - NAND - RAM - SF (serial flash) @@ -92,6 +92,7 @@ Commands: fat [mmcpart ] file in FAT partition ext4 [mmcpart ] file in EXT4 partition skip 0 0 ignore flashed data + script 0 0 execute commands in shell with being the GPT or DOS partition index, with being the eMMC hardware partition number. @@ -116,6 +117,20 @@ Commands: "u-boot-.bin raw 0x80 0x800; u-boot-.bin skip 0 0" + When flashing new system image requires do some more complex things + than just writing data to the storage medium, one can use 'script' + type. Data written to such entity will be executed as a command list + in the u-boot's shell. This for example allows to re-create partition + layout and even set new dfu_alt_info for the newly created paritions. + Such script would look like: + --->8--- + setenv dfu_alt_info ... + setenv mbr_parts ... + mbr write ... + --->8--- + Please note that this means that user will be able to execute any + arbitrary commands just like in the u-boot's shell. + "nand" (raw slc nand device) cmd: dfu 0 nand each element in "dfu_alt_info" = diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c index fc32a53323..213a20e7bc 100644 --- a/drivers/dfu/dfu.c +++ b/drivers/dfu/dfu.c @@ -26,6 +26,8 @@ static struct hash_algo *dfu_hash_algo; static unsigned long dfu_timeout = 0; #endif +bool dfu_reinit_needed = false; + /* * The purpose of the dfu_flush_callback() function is to * provide callback for dfu user @@ -139,6 +141,8 @@ int dfu_init_env_entities(char *interface, char *devstr) char *env_bkp; int ret = 0; + dfu_reinit_needed = false; + #ifdef CONFIG_SET_DFU_ALT_INFO set_dfu_alt_info(interface, devstr); #endif @@ -614,7 +618,8 @@ const char *dfu_get_dev_type(enum dfu_device_type t) const char *dfu_get_layout(enum dfu_layout l) { const char *const dfu_layout[] = {NULL, "RAW_ADDR", "FAT", "EXT2", - "EXT3", "EXT4", "RAM_ADDR", "SKIP" }; + "EXT3", "EXT4", "RAM_ADDR", "SKIP", + "SCRIPT" }; return dfu_layout[l]; } diff --git a/drivers/dfu/dfu_mmc.c b/drivers/dfu/dfu_mmc.c index d1af11d94c..e63fa84ce4 100644 --- a/drivers/dfu/dfu_mmc.c +++ b/drivers/dfu/dfu_mmc.c @@ -16,6 +16,7 @@ #include #include #include +#include static unsigned char *dfu_file_buf; static u64 dfu_file_buf_len; @@ -206,6 +207,9 @@ int dfu_write_medium_mmc(struct dfu_entity *dfu, case DFU_FS_EXT4: ret = mmc_file_buf_write(dfu, offset, buf, len); break; + case DFU_SCRIPT: + ret = run_command_list(buf, *len, 0); + break; case DFU_SKIP: ret = 0; break; @@ -221,9 +225,21 @@ int dfu_flush_medium_mmc(struct dfu_entity *dfu) { int ret = 0; - if (dfu->layout != DFU_RAW_ADDR) { - /* Do stuff here. */ + switch (dfu->layout) { + case DFU_FS_FAT: + case DFU_FS_EXT4: ret = mmc_file_buf_write_finish(dfu); + break; + case DFU_SCRIPT: + /* script may have changed the dfu_alt_info */ + dfu_reinit_needed = true; + break; + case DFU_RAW_ADDR: + case DFU_SKIP: + break; + default: + printf("%s: Layout (%s) not (yet) supported!\n", __func__, + dfu_get_layout(dfu->layout)); } return ret; @@ -243,6 +259,7 @@ int dfu_get_medium_size_mmc(struct dfu_entity *dfu, u64 *size) if (ret < 0) return ret; return 0; + case DFU_SCRIPT: case DFU_SKIP: return 0; default: @@ -408,6 +425,8 @@ int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s) dfu->layout = DFU_FS_EXT4; } else if (!strcmp(entity_type, "skip")) { dfu->layout = DFU_SKIP; + } else if (!strcmp(entity_type, "script")) { + dfu->layout = DFU_SCRIPT; } else { pr_err("Memory layout (%s) not supported!\n", entity_type); return -ENODEV; diff --git a/include/dfu.h b/include/dfu.h index 0b1dae0b3b..d18b701728 100644 --- a/include/dfu.h +++ b/include/dfu.h @@ -34,6 +34,7 @@ enum dfu_layout { DFU_FS_EXT4, DFU_RAM_ADDR, DFU_SKIP, + DFU_SCRIPT, }; enum dfu_op { @@ -497,6 +498,8 @@ static inline int dfu_fill_entity_virt(struct dfu_entity *dfu, char *devstr, } #endif +extern bool dfu_reinit_needed; + #if CONFIG_IS_ENABLED(DFU_WRITE_ALT) /** * dfu_write_by_name() - write data to DFU medium