From patchwork Fri Nov 13 04:14:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 324261 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:5ce:0:0:0:0 with SMTP id l14csp898835ils; Thu, 12 Nov 2020 20:16:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJy69d/BeHBDIElisCBjg58I9pT2LfNLvz703uTKUhc/CIXgCG5jZgqicHT2VITMNRxUGOYK X-Received: by 2002:aa7:cb4c:: with SMTP id w12mr577596edt.309.1605240999063; Thu, 12 Nov 2020 20:16:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605240999; cv=none; d=google.com; s=arc-20160816; b=yAVmfecD2icDn3WbOHl5WTrJcqbCXd1L4yLgamgGc5ETPEzGduEnegEjKQ1AZv2bss qBAePYIf5Lo0c4Or/Oeek/xY4ayI6SA5iPQC2nEpxxYtRBP+p/9IamevfQ/Jl0n3opO1 snj2xdOlRMVpuGuZa5XIuzut/3zW8rlT9Ut6bjNEoCLOzsThlf4qPovzlPIJcdFiPcIR 54zzfro0oOrBT8Qy9tfU17uoAO7yYk57AJGO86WjxVl8dCpaV1NCxkhsxyzNZeO1/s+8 IiunU3oUBr/P8Jr1B2ANxFfpB6F5D7TFjjGY5p4SKDJIMFCvspoHHgaEGbYtzuNFcs0K Zt2A== 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=5d/oM76upI+TLqBELIr9B5n4bSWcvU4VOq8S8EHFqIk=; b=T4aqlOkCH7OBqIF+p6U75AJSQK6d4BNKNslNg/Q1qmS52LToLkc8zKZtA+oU8aaVbh X+LbCZuZkLiPMDwCGNaPPGo42tydPlYlk/Y7u0jq1zKe7fUx6hLMvUcKysibSPDgHx7C HC8H7/GTcTjXz1rQ8NKf4LsFg1HbS0SgVc6TUhm1ezZN+8acA6iIwlxUP9jLbFNrw6Mq AKf/dUHjdL6OiWCZSYMXTpnoHJpU1qOObeDvCdF2eSN1bSz8arr74Ug/DyxoYrth7gsZ U45hI5loPtnU737b+ZkTs8BnQJc3mIupoGEOYPHLlnIcFX3mp4119Cr17UdB4XWWsM60 nKfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TSVhdZhx; 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 a6si5117657ejj.398.2020.11.12.20.16.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2020 20:16:39 -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=@linaro.org header.s=google header.b=TSVhdZhx; 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 BB65782573; Fri, 13 Nov 2020 05:16:05 +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="TSVhdZhx"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E1CA982564; Fri, 13 Nov 2020 05:15:53 +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-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) (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 4D3B68000F for ; Fri, 13 Nov 2020 05:15:43 +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-pl1-x644.google.com with SMTP id k7so3944351plk.3 for ; Thu, 12 Nov 2020 20:15:43 -0800 (PST) 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=5d/oM76upI+TLqBELIr9B5n4bSWcvU4VOq8S8EHFqIk=; b=TSVhdZhxNIOfkjhYw7igRUxkO8jGcxT6UShMTHLQXP1MQZP9rck/5RdASr4JezUFXf LYy1HWF/9MavWCdHUAzcJfG/K8A4bIa+5cuZaUyKA3DQfY0n6Yl3iacN9Pgr/jLT/y2Z Qm0LslFNX89wVPV+IjeL+5+wk+BQUxrXTwCpMNI72eItiK9eRNV8O8MeulKwpTfgXf/M cD7RAfhneui8aS/1Qik49CEHNteCa3eDY2liK1HQR+UDDcCCzGlqJtimnVp6wr/7+1fN Dv+id+z37T6NYsr1sfNCCWVxFExKeYoFQfKeC+PD9yoG2ucPZYd+TloKmao7U+CRtk8n LIrQ== 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=5d/oM76upI+TLqBELIr9B5n4bSWcvU4VOq8S8EHFqIk=; b=QI4G7AgLcjiw8tzCWQLtKDrayesM2c0Hg0jod/fOuvkqXdp+GuCGA3+nmSq7eVZAwa Ch0Yx1vkm3w9PnmXktd0syrYCMp+fSgFQfdEMaYlUaJRI5seUuE2ygtA4XuE8XLbzs9C wCzWtUlUWbk4NJ0T66M27fPL+JAsMXJDi1kaHV/b55SUx2VCAU8UByzbHix1SZ9Un3j+ L/3IRsUG+SIoYwjxhB+S9KTTLVB8surOSQ27xswgASP0e9M0m5jWmV5dDTu8N7FTdRCy CrhdARgZqjtuYBCmS26M4i5vYOE040K/LmeWjLBibNJGxtUERZaHWC56P0Akb2+8w03G EDqw== X-Gm-Message-State: AOAM531XeXb4SXO9k8vCAraQRXy6BGyaNsXbaBYHchri+80jnzMeU9GZ I9dp1nSLJkkwkY+fd5RGVyseEA== X-Received: by 2002:a17:902:e9c4:b029:d6:d5d6:c288 with SMTP id 4-20020a170902e9c4b02900d6d5d6c288mr597020plk.22.1605240938454; Thu, 12 Nov 2020 20:15:38 -0800 (PST) Received: from localhost.localdomain (p784a5642.tkyea130.ap.so-net.ne.jp. [120.74.86.66]) by smtp.gmail.com with ESMTPSA id s10sm4588340pjn.35.2020.11.12.20.15.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2020 20:15:37 -0800 (PST) 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 v8 03/18] common: update: add a generic interface for FIT image Date: Fri, 13 Nov 2020 13:14:56 +0900 Message-Id: <20201113041511.48207-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201113041511.48207-1-takahiro.akashi@linaro.org> References: <20201113041511.48207-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 | 2 +- include/image.h | 12 ++++++++ 5 files changed, 100 insertions(+), 3 deletions(-) -- 2.28.0 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..a5879cb52c41 100644 --- a/common/update.c +++ b/common/update.c @@ -29,6 +29,7 @@ #include #include +#if defined(CONFIG_DFU_TFTP) || defined(CONFIG_UPDATE_TFTP) /* env variable holding the location of the update file */ #define UPDATE_FILE_ENV "updatefile" @@ -214,6 +215,7 @@ static int update_flash(ulong addr_source, ulong addr_first, ulong size) #endif return 0; } +#endif /* CONFIG_DFU_TFTP || CONFIG_UPDATE_TFTP */ static int update_fit_getparams(const void *fit, int noffset, ulong *addr, ulong *fladdr, ulong *size) @@ -231,6 +233,7 @@ static int update_fit_getparams(const void *fit, int noffset, ulong *addr, return 0; } +#if defined(CONFIG_DFU_TFTP) || defined(CONFIG_UPDATE_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 || CONFIG_UPDATE_TFTP */ + +#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..121dc54f5463 100644 --- a/drivers/dfu/Kconfig +++ b/drivers/dfu/Kconfig @@ -20,7 +20,7 @@ config DFU_WRITE_ALT config DFU_TFTP bool "DFU via TFTP" - select DFU_WRITE_ALT + select UPDATE_COMMON select DFU_OVER_TFTP help This option allows performing update of DFU-managed medium with data 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__ */