From patchwork Thu Oct 29 00:25:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 319306 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp15012ilc; Wed, 28 Oct 2020 17:26:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+2ZvmjiAORXmjIL6T7/hES1F5rRQWSaNfHdAZyq6TT/K9livKw96x8hLMHb1OQWn8kV0x X-Received: by 2002:a50:fe05:: with SMTP id f5mr1569173edt.366.1603931184432; Wed, 28 Oct 2020 17:26:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603931184; cv=none; d=google.com; s=arc-20160816; b=zSza0T5BmVDE6ebCmzftAE/WL4z8I8UnDbAR8/0aSqFbIUvqf2X4rEj8cZojXlwuPJ lahF+E+CuQIGZqc43GkkAbJIfzKUAookCZYfx7DrkktgGkU15Lx2sFOD47hwsoxo9z/Y WtlzQYvLTz/cKtAMSb4hX8lUwm1nv5SVZ/Ws2e0sqWp1GdzJDJf8CV5LbktOCcXozcq8 tmTBKw2vSUotUEpB7BeztQSEe0iS+BQ8lROjEesqIY5qBadO3R08BLhSe8gLsRidaLyY M/nZIk5HJyFkWSUNWZj8q4x9fKDSjj2uj0aJAYR78Q4m9/5PK4hLOaFJclqbvGoCHJRl qmdw== 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=FcJgQrljui/HJx683kIxTRBuXZBU0d8QT3uyfp4p+FI=; b=moVotXSB9r/AdEjRJfhbs0Z1lZrP7mv4/fgQ6JiwBtUrLVsCX4ueifc/bdzgjOjgei 6MjmmgxIo7jHonE4xFiu/Rk7Y21ZEQhf5gnSHmeiN5GkmCLjOdjMPD2m+dvGCGHzydqs AsCOKBhXpwUHatvmCwDL3qHmP+hh37wHz3Hpw6bAjl7O2wLmzeRPLOl2ic6J33xkBaGy w2+gWznauV0Km6g3jq0YPR1jNYk2akFfIWNMFTLnRtVXoyq2jjlcIrpppaNoV1Nwr8TP pSNrP9EJ+FHcEEkWddGz6d+gTXYCz5nUtycYeFUWBxxBr+y6RXPoXvlWxNrHY/T2DJFg xWyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WMWyIFkq; 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 nt19si660175ejb.490.2020.10.28.17.26.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:26:24 -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=WMWyIFkq; 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 DC63B824E1; Thu, 29 Oct 2020 01:26:08 +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="WMWyIFkq"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 394E3824C5; Thu, 29 Oct 2020 01:26:06 +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-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) (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 966EA8248E for ; Thu, 29 Oct 2020 01:26:02 +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-x444.google.com with SMTP id 13so868823pfy.4 for ; Wed, 28 Oct 2020 17:26:02 -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=FcJgQrljui/HJx683kIxTRBuXZBU0d8QT3uyfp4p+FI=; b=WMWyIFkqTkPo+8+Y1DoFn19TE2v1h2JEAAX/pYWVHJy1OxCUTlKM7vr3Xon2DdK4TW lKpUr4JTpJW7KYSFO8KuMCI77zh4SvaPTu+NuZUcP5CN58NHIB6VTETH4PGO/v87bNJV QtxU8vqI0tRaWVZgniFHMG5pmRVHfSmaVsya/dl8lMfbBwdnqjmGGnfeo+CMOXdLxJWh BQ3e/jHqhfE7wLFwyDaWKvRC9HHfF/ahTCLh194QthAmRv40ftVOk46TnuOC4O3rlIeF 35bIPQNowkFmntEeGWyc+TEEf/LoHTm4+j3NLpX0ppYxfq9WVYIwdR+aIJ3oinkOOnjT WmvA== 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=FcJgQrljui/HJx683kIxTRBuXZBU0d8QT3uyfp4p+FI=; b=DdoQUC1as90ZxjCjiAemdVDQ4LIilUgU5ao6wpEAIAKcbWxEjoToX8k9wyyW8edZaI Arjmrvl5UpuvgNwhxbRHEKOLVyFcD9guvOxTUF43yeWRlVusLJbXHMnAZdKMU+NPf+Hd htNbLQjsHsBQFXdFPiPS+qWtQstjYYZiWTHSLRqJ7Mk7BYJ4XAdvLTLgqtOKQ9KK5oPH gReUH4VWeRpc+i9kqcytkmvc2r8KwffarBN9EQw8vNPomi1yefBcJScErVKhonJcmgBS /JEHMIT3ABujotvoYsfZ1sGpLiEQxsFS24vkxnqoXo167xZfJ9l2Ji1us+QsrTWpbLbT fxqg== X-Gm-Message-State: AOAM532xk97WPn1ClQ+ljMdZs17Qm8HKG7AZStuu08IrdAeWTWlhPjxn +El3DcxH0l4lxVcrIzkWyP2hWw== X-Received: by 2002:aa7:9a86:0:b029:163:bfc2:2d7e with SMTP id w6-20020aa79a860000b0290163bfc22d7emr1421490pfi.61.1603931161069; Wed, 28 Oct 2020 17:26:01 -0700 (PDT) Received: from localhost.localdomain (p784a66b9.tkyea130.ap.so-net.ne.jp. [120.74.102.185]) by smtp.gmail.com with ESMTPSA id s22sm731502pfu.119.2020.10.28.17.25.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:26:00 -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: [RESEND PATCH v6 03/17] common: update: add a generic interface for FIT image Date: Thu, 29 Oct 2020 09:25:14 +0900 Message-Id: <20201029002528.34408-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201029002528.34408-1-takahiro.akashi@linaro.org> References: <20201029002528.34408-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 318d372a481b..787d203d0aea 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -599,9 +599,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. @@ -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 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 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__ */