From patchwork Mon Aug 3 05:43:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 247346 Delivered-To: patch@linaro.org Received: by 2002:a92:cc90:0:0:0:0:0 with SMTP id x16csp931331ilo; Sun, 2 Aug 2020 22:44:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQBmVnmn+WW3JML0f4+w9NhhVBWN/4IVDPI7L8FsMPEJ9F8EAC9PaIcsi4zvY7qQgHVbVx X-Received: by 2002:a05:6402:1a46:: with SMTP id bf6mr14059498edb.284.1596433496180; Sun, 02 Aug 2020 22:44:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596433496; cv=none; d=google.com; s=arc-20160816; b=r7gKxMl6qZBH1VA/vrpOvzL/IbYovfWUWDxm4IK34RBiXv7wuFrL9/eKuyReSrY7rJ Oici0g/OBokXjhenLiUAYmv9euflf4rhsB2rFctYNlWiCyF5fa/fwh8/jVNirAfPm4/l rND2cwX3SOCbutjzq7HqANGN6GZDF3X3u61pdFoa++qmV6AhejnSJ0yILkuTU+31kaFG f3q1gZZJTZVbtE5OMXf5vH3P7apm2irtnSR+eUFTaGjwSUUCOYllpg4wnG8FG03X0Zub 5qlG1TyonUlPGKKROJiJ0MJEWDGofLmn9wiDVMWL8TAr7d0Bd3oB8IV/bVQ9m6AylKUr qVZQ== 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=1kOoXQckxYszkBnJ0EA0SZInIxGc/tOXAT7BGThDU7M=; b=sVvMZEHXRubhcNKPbMdSj80kVjdl0FLaiZSvcNRFOhe2r7Ji0lROOho8zDGTkQpBA1 X+Y3z4/W0c0HTW02lLrPlWhEUHd50N/psOY+8nvhUFtr5ePvOScUfQ4TekBSzJf3biRa uA64O4TnNOy/uYNb/bleLz7fP0MDzOj1OFcQlNE1sR6VxSsPxNooNXKnYnkdPubwEc5B SO/RI+zGd8SVDXi6IvIDCc1a8Wl926Sd5VhBxZ8EUm9cNqhhyK0d5YzVx7Ailpr73zRV IJ9u3Wskp/Z1dwi6ifApQFnMt6sxQ5eJDxkfHYOrd+V/TU4y5dZMe1bmJERPTbtJzGQW 42wQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FjR7Fovl; 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 e21si9883727edv.242.2020.08.02.22.44.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Aug 2020 22:44:56 -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=FjR7Fovl; 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 5BE7D81F2C; Mon, 3 Aug 2020 07:44:38 +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="FjR7Fovl"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B5B1C81D9E; Mon, 3 Aug 2020 07:44:35 +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-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) (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 D05DA81D9E for ; Mon, 3 Aug 2020 07:44:31 +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-pl1-x641.google.com with SMTP id p1so20166066pls.4 for ; Sun, 02 Aug 2020 22:44:31 -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=1kOoXQckxYszkBnJ0EA0SZInIxGc/tOXAT7BGThDU7M=; b=FjR7Fovl3cKvb63Ai2Yzr0CGa7u6oExwDvyxRGXFUtUU2pJZ+CC3gYqMr7DMyRx/4C w8n4VR6Do3350rDsnpdDmmoxUcgluLzVHI0yQKUPHJIfxqAd2cEfTH126L241Rkdxsr0 vq2LsKKR6L1n3AXh59camUyat0Hs7vywrZY5FSYigWxvBcSk1aZd5835ptr237KoDRWp pmpYX3szNpbglHON5nomxt9OaxidTG3z2klkD7JxgakPNdiFW79bNsCGpTcQHaFypsW/ LWCiXFqImXSUoUm502CQEd12XY/mm168kXsdzhvKFZBjq5j8BvJlaY3sW5HnoCcYDLj6 5bUg== 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=1kOoXQckxYszkBnJ0EA0SZInIxGc/tOXAT7BGThDU7M=; b=WcASs6ZRfhrkKEpQ1qUpMRwZJGEwsJCWSdr76MiddASQssBCN0VnUM/r20GA3PNNuJ pVfOvn8fjL3HJxGHwj6WnXeeXaLxBm1NBueRBsq1D43yFDGNzwAcBqsf4vxfwFrAJ7e1 IoCJyv/ZstuipDZa3nzhgeE0bpEbfp4sVPT62DaATPcCgj9x+jbku9nZxnoA8WWXIeMg xDOWBsToLFqDKok9D3pWGi0v85zCoGn2yAEmyevZd8TI9cloW+TwnDDHccBzRqWvb86E 4Qv3MrHan2hFJD4WxM19Zr4zRhoh52NtjeD04OFmG4KrbnMH3AT6c3Q+aqxNBKxXyCDx NPng== X-Gm-Message-State: AOAM531V/9uYOGsAeBmS6fud1vDKsKSbQ8178SphgmazOxlB36bMjx20 30NEHiWbKf55CSL9139N3D108A== X-Received: by 2002:a17:90a:bf89:: with SMTP id d9mr16016827pjs.89.1596433470376; Sun, 02 Aug 2020 22:44:30 -0700 (PDT) Received: from localhost.localdomain (p784a66b9.tkyea130.ap.so-net.ne.jp. [120.74.102.185]) by smtp.gmail.com with ESMTPSA id r25sm16952633pgv.88.2020.08.02.22.44.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Aug 2020 22:44:29 -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 v5 03/17] common: update: add a generic interface for FIT image Date: Mon, 3 Aug 2020 14:43:41 +0900 Message-Id: <20200803054355.17356-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200803054355.17356-1-takahiro.akashi@linaro.org> References: <20200803054355.17356-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 | 14 +++++++++ common/Makefile | 3 +- common/update.c | 71 +++++++++++++++++++++++++++++++++++++++++++++ drivers/dfu/Kconfig | 1 + include/image.h | 12 ++++++++ 5 files changed, 99 insertions(+), 2 deletions(-) -- 2.27.0 diff --git a/common/Kconfig b/common/Kconfig index ca42ba37b726..86568dec2e25 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -1014,6 +1014,20 @@ endmenu menu "Update support" +config UPDATE_COMMON + bool + default n + select DFU_ALT + +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 f82d77cc0be9..2c75b37f19e6 100644 --- a/common/update.c +++ b/common/update.c @@ -23,6 +23,7 @@ #include #include +#ifdef CONFIG_DFU_TFTP /* env variable holding the location of the update file */ #define UPDATE_FILE_ENV "updatefile" @@ -89,6 +90,7 @@ static int update_load(char *filename, ulong msec_max, int cnt_max, ulong addr) return rv; } +#endif /* CONFIG_DFU_TFTP */ static int update_fit_getparams(const void *fit, int noffset, ulong *addr, ulong *fladdr, ulong *size) @@ -106,6 +108,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; @@ -194,3 +197,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 d680b28ecf51..df0585c4fc83 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__ */