From patchwork Mon Sep 7 05:34:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 249191 Delivered-To: patch@linaro.org Received: by 2002:a92:5b9c:0:0:0:0:0 with SMTP id c28csp3414556ilg; Sun, 6 Sep 2020 22:36:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvpyI1t6uApIwHQzx+8ZWkuhyOmcT+kxIGvFOtLgs4fNmmiDCPzwMTbixQz2kqcKWX+Run X-Received: by 2002:a17:906:c7d9:: with SMTP id dc25mr18935905ejb.452.1599457012390; Sun, 06 Sep 2020 22:36:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599457012; cv=none; d=google.com; s=arc-20160816; b=ryfBTq9mDXqLGGZ9IdeVeT6jNS8GcqP5in/6JZFqWB+K5UYy/fSYM6nw/QEoVvc6FU R3l7nR+0qMIorQ2irf5JGhD8Dm8nb1mNmPSa2JzyDHVvvstIuP8V7zqsR0qknmLcVVOH uzNhHAyfyrRr2/+q8BO6Urxwe28kRmfS5qgmapD6GLwvHf9HL9hy6zfU0/UtQnTx7Rag /5KawHUxPX4kvHOWWAoXJX/br6StNqv6MXIc2eO07WlQuI0zfm5W/lqRmyiUtbvsgGxo UM/b4WSOvmozBa1ZD2tvbuswDI8BIUkECGDJjITA+SIeMvBNQ7+BX5a80hLDZ0GKC2Ya GNTg== 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=cx6hY3daU+eiUbIq+eoZJ2Z9CmqEP9Hy6+vKyLqsvsM=; b=iZ+CC3JZumixXaBJ+GADZEapbf1GzI0wtKMHdyy5ZV7Ov1cnMQTvgbVbL7tCJd2AwS wjguFhWhEKkq029zmK8uoZbUHkzIMEQggHjk/ceESThlmFffb13TkrX9ngBtDExFpdab fh2DL7OLF1KmfvwkjV+8S8uY/pSEfwWPWFrzckpLYyXQnGAXWtD/ONhQ9VZr7n00GhGj a/EA2A46y1zmOBxMjFIrLXoOkBBTSXjg42ta4cqMe4/u0+A9A0xwJnv0psP01fFax2Q6 V5A4+6UGYEniVr2k1WQ7LaK8wMFquMjk9FMGZO/j/oc+Z+DvVkyCUwFh8aOJE9vJsMNh hHHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=C9xVToSd; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id c1si9030430eds.366.2020.09.06.22.36.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2020 22:36:52 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=C9xVToSd; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 4737C824DC; Mon, 7 Sep 2020 07:36:16 +0200 (CEST) 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="C9xVToSd"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 202D9824AE; Mon, 7 Sep 2020 07:35:56 +0200 (CEST) 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-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) (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 478F7824AE for ; Mon, 7 Sep 2020 07:35:53 +0200 (CEST) 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-pj1-x1044.google.com with SMTP id a9so2930826pjg.1 for ; Sun, 06 Sep 2020 22:35:53 -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=cx6hY3daU+eiUbIq+eoZJ2Z9CmqEP9Hy6+vKyLqsvsM=; b=C9xVToSd1Ltyxn6uxbGEGK6DI818HjYpD4hxJ3CHcvmBNRyiTFYDWsrOHEfq8gxXec klwrNo40RNoiEbdjnPC/7wsbwimAwxwx9/ook3gnWc/MEQw3+fa987xAYyizLRocIAd2 FKMitj5pXXacN2X4lXb9vSZm/xbWYS+TyctKgRKRnPW4/8nLvF15sULAPOEmOuqTqfxv 1M5uGUyPnm0+N2h9iVsDP3O7vjUyhXWqg06MIRcHsPYND24yCtsWbjoe8cKRz744PX3J eVSA5TKSZZddDmgpm5UySeTtq7SFCDl2KBraj70iYSI5aSmcK78GnSVVyRKqs03jnaPz i65w== 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=cx6hY3daU+eiUbIq+eoZJ2Z9CmqEP9Hy6+vKyLqsvsM=; b=f2249K8RPFOdNthHCeaQGSg6yvkhJtGx70t/VOvcLaocSQBmGUPz5GA3q0sXpKka7e euZJFvxNaXwUgIPFtMEbNCqCzeDmRGTSICMTMRwUTgdrZhg4JTy9JwbHY8mhlzxeJ5rO /LAFHnydSuNb+7XxkGs5ScqgZgD51tpZW/rMya1/SZUC9PvBrJll6b9eS6MtfEL3IOR6 Ia6BpQvVgT1EA3OrAghBa1d5eDIIGQuG5X8YUaSOCaOk5NeQKZ7rKp7miNvLl4wptx7H 5vsubOd4e1HhoX4cw24vhHI//dba87Gmj6sYv5flRSQ/9nrHaRgdLIZ54khYAOsL3B64 WuPg== X-Gm-Message-State: AOAM533WjqogRNgA447fR5DWO50S0cT1v9WF6ejyymZ1tUGNDzNGplD3 hH0B47I3Jqzh0zRdycYKe7ddkA== X-Received: by 2002:a17:90b:803:: with SMTP id bk3mr19102322pjb.57.1599456947222; Sun, 06 Sep 2020 22:35:47 -0700 (PDT) Received: from localhost.localdomain (p784a66b9.tkyea130.ap.so-net.ne.jp. [120.74.102.185]) by smtp.gmail.com with ESMTPSA id w6sm10783939pgr.82.2020.09.06.22.35.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2020 22:35:46 -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 v6 03/17] common: update: add a generic interface for FIT image Date: Mon, 7 Sep 2020 14:34:12 +0900 Message-Id: <20200907053426.1675646-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200907053426.1675646-1-takahiro.akashi@linaro.org> References: <20200907053426.1675646-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 diff --git a/common/Kconfig b/common/Kconfig index c58f08ba91bf..36998e382bda 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -1050,9 +1050,15 @@ endmenu menu "Update support" +config UPDATE_COMMON + bool + default n + select DFU_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. @@ -1067,6 +1073,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 78f901ff348a..ce0c42c7df9c 100644 --- a/drivers/dfu/Kconfig +++ b/drivers/dfu/Kconfig @@ -22,6 +22,7 @@ config DFU_TFTP bool "DFU via TFTP" select DFU_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 9a5a87dbf870..35b8b7c3d84f 100644 --- a/include/image.h +++ b/include/image.h @@ -1592,4 +1592,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__ */