From patchwork Wed Jun 17 02:55:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1310883 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=WL3rSzDY; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49mqTn6M0Mz9sTH for ; Wed, 17 Jun 2020 12:56:45 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9E41481FCE; Wed, 17 Jun 2020 04:56:08 +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="WL3rSzDY"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4E10D81FB7; Wed, 17 Jun 2020 04:55: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-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 8A33B81FAE for ; Wed, 17 Jun 2020 04:55:50 +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-pf1-x443.google.com with SMTP id x22so424959pfn.3 for ; Tue, 16 Jun 2020 19:55:50 -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=KeZNEDwawafC2swPfuWBb3fRjrfsHyb4K4MiVrVXet4=; b=WL3rSzDY/SyJ+3ASuoLwICvOlIOP8aB5nyOANRV8Euwul35hB5vPPnL5kzVgDMMOTB HSJaBl7CoayWEeqJuFjqIpE/+FwpJZ/i+rZ1OV4S03gqLlDkNaVaplXbXy/KVs2sAx/f hfkYLXqIlwJ7KR1np6dlZXxNEV1qFWedeNjPZZfCn2Z0Td2FkLC2mGe2KImlIhzLZymJ Ze2Fe/EZYmals1CRTeh6amku7HSyD4X1rlkPJg7gxPNA5vjLAEx8Lr1dDgMp3AD9CWeV qkSKmXRIB+zJb71gJojxzo5Som0oBbeKOaFlDUZzjhsd/pGz3NGluxIS3XmkAA5254Rs ZRzw== 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=KeZNEDwawafC2swPfuWBb3fRjrfsHyb4K4MiVrVXet4=; b=iEZbvMxnC3W1xQTuDvbBdkHl/uztQ5wSocnomeb3qDb9HNuY9BnCfVeZKoutPhBDKR Uek/z/Lr06MyjmyRmceJ6XRP9oazLayD+DiA4F3019gvVFV4PrCEQB6BOi5W1UOJHebS wM3bsmTfUTGJDA8B5Izu8Mr5Zy++jeL9TfpHh0WB5S4WigULDcSKtlIMvknyKcSdsTmx P+7gkcvZO1yIDqR/KCzcTod3a5bs/AyXkcTbJ7XpDYpAPvXazdO5vq3NkyklBoMBTTUC g8NCC6FxVF0luCrCzODycERAcse68EmyL89SQuqYuC/n8h1a1im2/BJ73fvCW/OI5wD6 GNZA== X-Gm-Message-State: AOAM530BIgJ5sPEXuEef2baH9MmShxugCVte75Owz8y77S/VpF86sSjs Flrisy4stNlI/2ds4XSaMRdzpA== X-Google-Smtp-Source: ABdhPJxqzsvt+dQZfzmksnIYr8hET/lb5GQ89wZe9leFK9ZQlwP2OE/DHd6YdtLFx6ZGcObo6Hmq1w== X-Received: by 2002:a63:c004:: with SMTP id h4mr4482999pgg.385.1592362548375; Tue, 16 Jun 2020 19:55:48 -0700 (PDT) Received: from localhost.localdomain (p6e421564.tkyea130.ap.so-net.ne.jp. [110.66.21.100]) by smtp.gmail.com with ESMTPSA id lt14sm3724918pjb.52.2020.06.16.19.55.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jun 2020 19:55:47 -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 v2 04/17] common: update: add a generic interface for FIT image Date: Wed, 17 Jun 2020 11:55:02 +0900 Message-Id: <20200617025515.23585-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200617025515.23585-1-takahiro.akashi@linaro.org> References: <20200617025515.23585-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.2 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 | 16 +++++++++++ common/Makefile | 2 +- common/update.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++-- include/image.h | 12 ++++++++ 4 files changed, 102 insertions(+), 3 deletions(-) diff --git a/common/Kconfig b/common/Kconfig index 2d86dd7e63c6..a51d2a7b9d2a 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -985,9 +985,16 @@ 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 + depends on DFU + select UPDATE_COMMON help This option allows performing update of NOR with data in fitImage sent via TFTP boot. @@ -1002,6 +1009,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..c238db8108e7 100644 --- a/common/Makefile +++ b/common/Makefile @@ -53,7 +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_UPDATE_COMMON) += update.o obj-$(CONFIG_DFU_TFTP) += 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 3547dc68bf7c..a8151383fae7 100644 --- a/common/update.c +++ b/common/update.c @@ -24,6 +24,7 @@ #include #include +#ifdef CONFIG_UPDATE_TFTP /* env variable holding the location of the update file */ #define UPDATE_FILE_ENV "updatefile" @@ -211,6 +212,7 @@ static int update_flash(ulong addr_source, ulong addr_first, ulong size) return 1; #endif } +#endif /* CONFIG_UPDATE_TFTP */ static int update_fit_getparams(const void *fit, int noffset, ulong *addr, ulong *fladdr, ulong *size) @@ -228,6 +230,7 @@ static int update_fit_getparams(const void *fit, int noffset, ulong *addr, return 0; } +#ifdef CONFIG_UPDATE_TFTP int update_tftp(ulong addr, char *interface, char *devstring) { char *filename, *env_addr, *fit_image_name; @@ -322,8 +325,9 @@ got_update_file: } } else if (fit_image_check_type(fit, noffset, IH_TYPE_FIRMWARE)) { - ret = dfu_tftp_write(fit_image_name, update_addr, - update_size, interface, devstring); + ret = dfu_write_by_name(fit_image_name, update_addr, + update_size, interface, + devstring); if (ret) return ret; } @@ -333,3 +337,70 @@ next_node: return ret; } +#endif + +#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, update_addr, + update_size, NULL, NULL); + if (ret) + return ret; + } +next_node: + noffset = fdt_next_node(fit, noffset, &ndepth); + } + + return ret; +} +#endif diff --git a/include/image.h b/include/image.h index ad81dad44429..1f2c53339d51 100644 --- a/include/image.h +++ b/include/image.h @@ -1573,4 +1573,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 indentified 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__ */