From patchwork Thu Oct 29 04:47:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 319342 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp141673ilc; Wed, 28 Oct 2020 21:50:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzI5FA0Yai/mFXfGHoJD/ONOw4dme5QZPlFBqRTHRqoiLMc4TEdHTETej9dzfY3gjHt2YPj X-Received: by 2002:aa7:d550:: with SMTP id u16mr2123874edr.147.1603947002907; Wed, 28 Oct 2020 21:50:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603947002; cv=none; d=google.com; s=arc-20160816; b=pQD78A5i/U/c1jGi98tPAu+taZCZcc9FtBNEABqTh/TLLQV8ITI6sCKUNo3rlIOwM7 n+c/HE6wBIQJH/bADIsaYhGs3LuV26RpJthB1Z7vhL2ocdP0GFouIlW3uucvtQRbuLUg 6M5iOJIOsCaGpCFu9v3qTDkCERPPq1xZ42ttzp+PaY3XQWTyUuwPwmE4xg1cjNLc1Oir Ti8cuTQDo41sR3+zOWLQWihTsCGUVwDdd4xGYM0ozf+WABq5TVWOVWctxQw0M0OJ3WJu iZHgbZe2vliaTE37uW3Kz3P7eXaMWtPKWbmCXZ/9n5wAyTTOziVyAxVZg5ofurLKs/4u PF1w== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=tAOoJtASeHpxw8IJa311Dp3BleIZicwBKoEsuk6R8oU=; b=b1QQVHBLRpZeF+wElnm97p/Y3lJ783i4VLb5oHY7nnGRXoBbWDnm3c9JEgnOQkCXEm qDyynuIsst8xLo3HiizG2dVuYNEFDFx5PXqrDycuSrLUyA3T8s0oQq6szbKWDU5MuFhS 6q2PWQhwAFWzYB84UEE6JV6qOrDah+m+GgrO2T+nybCwxPEDa4D0maAuspQ+r5GYIp4o TgxrzT51uQcPMIEObWxPzXNIdHKKKlwc6lfgE0bafk94+J6LFy8lIf5cHpYbGQAa3Oe0 FU4d4/Oy/nKsy3VUU89nf23r63+PuPCWlbQjefrgUTqWAoeaMTEuhmzoqW9kUyMNx44i VeLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XCi5FNXY; 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=linaro.org 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 r21si1298388ejo.534.2020.10.28.21.50.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 21:50:02 -0700 (PDT) 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=@linaro.org header.s=google header.b=XCi5FNXY; 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=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 766748247D; Thu, 29 Oct 2020 05:49:52 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="XCi5FNXY"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5C81D824DE; Thu, 29 Oct 2020 05:49:48 +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=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6190F82369 for ; Thu, 29 Oct 2020 05:49:45 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pf1-x443.google.com with SMTP id b3so1350534pfo.2 for ; Wed, 28 Oct 2020 21:49:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tAOoJtASeHpxw8IJa311Dp3BleIZicwBKoEsuk6R8oU=; b=XCi5FNXYrh2UEs1uDN2WD5YeKqaRHrOakXLhyIfV7Jo2r6nAJFfld77GmVyHCKXoxh A1fFbvUkQdeWHtJx/5DgJjieQzqJG45Btc1H6G+0m6ayo8L14wbyxbXX7kaB962PdYY5 OrU97Ayi7r0H5H/OetwcRMaqvfm1JXdpdNB/OYj+8/+8st+A3wQQwqgNdfFbI0kBIpe6 wmSZAcPhE5F+4WD94beqmMWQFiXn32DIJtz+usId9jz6s9GRdO2J1K8QFAAcw+c87wWI Vi7j8zm81p+lu7uHisk1534sfGEmUMcfEHUjGFY4YYoomOaEi/6ZmiQxqyO3ZIPd0Y6F xQPQ== 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:mime-version:content-transfer-encoding; bh=tAOoJtASeHpxw8IJa311Dp3BleIZicwBKoEsuk6R8oU=; b=myz9TCqaugf9lPmzbM2TQlXIt1IrReI4p+1Eppsv3iIO1kScJmWj4seMnKA78Y7cwM X47QcwG1YdhQsQXGtvEBTidgRtB0PQcwhd2/0BKBqBHPc16taT9EpxX8sMvZxi8xbfAn 8W8MWNwLyWmuieYEqWhKX4T4NfXfOkeKcpwc6RwgvsV5gF5AgQlbiyZsoeUThhhE3h4B xZh6ij8MIg9FKGT9Pm5oHIICb+WbzdxmDz08PDJBpMRmO2Q7aHAE7GNCkeiHbXC2HLMN +MblUpumYp7XV4hAzmzuf7VFTktMIt7Cz5PrHwM/9ytZZtwc5scBw/WJBSbMFzx+OtSM m75A== X-Gm-Message-State: AOAM530sqJCvEut8wyV00VuDdHvsPPQbAT64Y0z1lGaEv6D4tIw28drE cZ3Ir2M3WOtM4wLlHCxwvQoUwQ== X-Received: by 2002:a62:343:0:b029:15c:e33c:faff with SMTP id 64-20020a6203430000b029015ce33cfaffmr2325039pfd.7.1603946983977; Wed, 28 Oct 2020 21:49:43 -0700 (PDT) Received: from localhost.localdomain (p784a66b9.tkyea130.ap.so-net.ne.jp. [120.74.102.185]) by smtp.gmail.com with ESMTPSA id t14sm830689pjy.46.2020.10.28.21.49.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 21:49:43 -0700 (PDT) From: AKASHI Takahiro To: lukma@denx.de, trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Cc: sughosh.ganu@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH v7 03/17] common: update: add a generic interface for FIT image Date: Thu, 29 Oct 2020 13:47:43 +0900 Message-Id: <20201029044757.183262-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201029044757.183262-1-takahiro.akashi@linaro.org> References: <20201029044757.183262-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 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 The main purpose of this patch is to separate a generic interface for updating firmware using DFU drivers from "auto-update" via tftp. This function will also be used in implementing UEFI capsule update in a later commit. Signed-off-by: AKASHI Takahiro --- common/Kconfig | 15 ++++++++++ common/Makefile | 3 +- common/update.c | 71 +++++++++++++++++++++++++++++++++++++++++++++ drivers/dfu/Kconfig | 1 + include/image.h | 12 ++++++++ 5 files changed, 100 insertions(+), 2 deletions(-) -- 2.28.0 Reviewed-by: Tom Rini diff --git a/common/Kconfig b/common/Kconfig index 318d372a481b..2bce8c9ba1b9 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -599,9 +599,15 @@ endmenu menu "Update support" +config UPDATE_COMMON + bool + default n + select DFU_WRITE_ALT + config UPDATE_TFTP bool "Auto-update using fitImage via TFTP" depends on FIT + select UPDATE_COMMON help This option allows performing update of NOR with data in fitImage sent via TFTP boot. @@ -616,6 +622,15 @@ config UPDATE_TFTP_MSEC_MAX default 100 depends on UPDATE_TFTP +config UPDATE_FIT + bool "Firmware update using fitImage" + depends on FIT + depends on DFU + select UPDATE_COMMON + help + This option allows performing update of DFU-capable storage with + data in fitImage. + config ANDROID_AB bool "Android A/B updates" default n diff --git a/common/Makefile b/common/Makefile index 2e7a090588d9..bcf352d01652 100644 --- a/common/Makefile +++ b/common/Makefile @@ -53,8 +53,7 @@ obj-$(CONFIG_LCD_ROTATION) += lcd_console_rotation.o obj-$(CONFIG_LCD_DT_SIMPLEFB) += lcd_simplefb.o obj-$(CONFIG_LYNXKDI) += lynxkdi.o obj-$(CONFIG_MENU) += menu.o -obj-$(CONFIG_UPDATE_TFTP) += update.o -obj-$(CONFIG_DFU_TFTP) += update.o +obj-$(CONFIG_UPDATE_COMMON) += update.o obj-$(CONFIG_USB_KEYBOARD) += usb_kbd.o obj-$(CONFIG_CMDLINE) += cli_readline.o cli_simple.o diff --git a/common/update.c b/common/update.c index 8dd6ee8b7ddb..808be0880dfd 100644 --- a/common/update.c +++ b/common/update.c @@ -29,6 +29,7 @@ #include #include +#ifdef CONFIG_DFU_TFTP /* env variable holding the location of the update file */ #define UPDATE_FILE_ENV "updatefile" @@ -98,6 +99,7 @@ static int update_load(char *filename, ulong msec_max, int cnt_max, ulong addr) return rv; } +#endif /* CONFIG_DFU_TFTP */ #ifdef CONFIG_MTD_NOR_FLASH static int update_flash_protect(int prot, ulong addr_first, ulong addr_last) @@ -231,6 +233,7 @@ static int update_fit_getparams(const void *fit, int noffset, ulong *addr, return 0; } +#ifdef CONFIG_DFU_TFTP int update_tftp(ulong addr, char *interface, char *devstring) { char *filename, *env_addr, *fit_image_name; @@ -337,3 +340,71 @@ next_node: return ret; } +#endif /* CONFIG_DFU_UPDATE */ + +#ifdef CONFIG_UPDATE_FIT +/** + * fit_update - update storage with FIT image + * @fit: Pointer to FIT image + * + * Update firmware on storage using FIT image as input. + * The storage area to be update will be identified by the name + * in FIT and matching it to "dfu_alt_info" variable. + * + * Return: 0 - on success, non-zero - otherwise + */ +int fit_update(const void *fit) +{ + char *fit_image_name; + ulong update_addr, update_fladdr, update_size; + int images_noffset, ndepth, noffset; + int ret = 0; + + if (!fit) + return -EINVAL; + + if (!fit_check_format((void *)fit)) { + printf("Bad FIT format of the update file, aborting auto-update\n"); + return -EINVAL; + } + + /* process updates */ + images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH); + + ndepth = 0; + noffset = fdt_next_node(fit, images_noffset, &ndepth); + while (noffset >= 0 && ndepth > 0) { + if (ndepth != 1) + goto next_node; + + fit_image_name = (char *)fit_get_name(fit, noffset, NULL); + printf("Processing update '%s' :", fit_image_name); + + if (!fit_image_verify(fit, noffset)) { + printf("Error: invalid update hash, aborting\n"); + ret = 1; + goto next_node; + } + + printf("\n"); + if (update_fit_getparams(fit, noffset, &update_addr, + &update_fladdr, &update_size)) { + printf("Error: can't get update parameters, aborting\n"); + ret = 1; + goto next_node; + } + + if (fit_image_check_type(fit, noffset, IH_TYPE_FIRMWARE)) { + ret = dfu_write_by_name(fit_image_name, + (void *)update_addr, + update_size, NULL, NULL); + if (ret) + return ret; + } +next_node: + noffset = fdt_next_node(fit, noffset, &ndepth); + } + + return ret; +} +#endif /* CONFIG_UPDATE_FIT */ diff --git a/drivers/dfu/Kconfig b/drivers/dfu/Kconfig index 10196f390fcd..b7427fc4f0d6 100644 --- a/drivers/dfu/Kconfig +++ b/drivers/dfu/Kconfig @@ -22,6 +22,7 @@ config DFU_TFTP bool "DFU via TFTP" select DFU_WRITE_ALT select DFU_OVER_TFTP + select UPDATE_COMMON help This option allows performing update of DFU-managed medium with data sent via TFTP boot. diff --git a/include/image.h b/include/image.h index 4094ee588a57..00bc03bebece 100644 --- a/include/image.h +++ b/include/image.h @@ -1602,4 +1602,16 @@ struct fit_loadable_tbl { .handler = _handler, \ } +/** + * fit_update - update storage with FIT image + * @fit: Pointer to FIT image + * + * Update firmware on storage using FIT image as input. + * The storage area to be update will be identified by the name + * in FIT and matching it to "dfu_alt_info" variable. + * + * Return: 0 on success, non-zero otherwise + */ +int fit_update(const void *fit); + #endif /* __IMAGE_H__ */