From patchwork Wed Jul 22 06:05:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 246950 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp253428ilg; Tue, 21 Jul 2020 23:06:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJocAsz7JEt8HgtdnqIBNNaem6//bkO2xgga/PAefbi/rTcHRxrU6+YD8wofFIfrShmfTO X-Received: by 2002:a17:906:8d5:: with SMTP id o21mr11459949eje.155.1595398008639; Tue, 21 Jul 2020 23:06:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595398008; cv=none; d=google.com; s=arc-20160816; b=ry4v0YQbcFOejaEy9Mz2SaRHbtmhEjtzbG9HxBDYSoBao+hiSr2YlPEtB0gLzqgacZ ogpdSSenoBsgObKvjUSBs1lh0ncq5VJ3foHvjW8pX7tK7szRbLgyiKBU9tCZzFKFucKR AiK8lqBULzNJitpBoC8AcMTcnf9sPSxb+Vlui+9L2oT3Dj/Oc4+FlE1gSAPbUb4JSZi+ G4QeSkqTLrtwob9vOv5s4caP3/7n+4i9PAsF94u69yDqez5nSjTwu9am/2f3FVVYrSux wn1S9hLIF8edddsePy5ntcJXuwS8ZeFvkgsO/FTEie2A9X6+q3pGpCbguNSiEiNf4hrR cMHQ== 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=xAKBYJi0oboeVaISzpy1fgpCufVHTsqmx7AdhwU/ts4=; b=rEBalei5Bn3ssJNDHYDgKid9+mFjptfSOGEqA5o413CSMCQ7QbCZf+gD9g3WZAyLe7 1qKik4FWRY8qxOVV3q/g0K5OLVnJ8Fc3v08vGF3Pwx9tFPrN6XDXfd6KxXxZVNje93YN 7ekH9ccSWeGA+flcGZOlPoq8cHyUdDTe5OXPXwdgV29PlszK60jjeglh+9y8Dl8iJkG0 L25QEnkgzeuQEAnx6VBIKniVjmQs0YCkT8IGDzvc/DXkMGZhRKO6FhwPxiOM9rINKhk1 imYHJYiLhIDPdSJgSPkRq2Lj5w7dol076ttOu7rsmtFd+AZ0r8sp2Wm7yD+TxcYjf/5U /Lsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=D1Lwaq0G; 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 v18si13516272ejr.577.2020.07.21.23.06.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jul 2020 23:06:48 -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=D1Lwaq0G; 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 6473481D71; Wed, 22 Jul 2020 08:06:32 +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="D1Lwaq0G"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8F5AB81B96; Wed, 22 Jul 2020 08:06:27 +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-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) (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 0818781C3E for ; Wed, 22 Jul 2020 08:06:24 +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-pg1-x544.google.com with SMTP id g67so626756pgc.8 for ; Tue, 21 Jul 2020 23:06:23 -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=xAKBYJi0oboeVaISzpy1fgpCufVHTsqmx7AdhwU/ts4=; b=D1Lwaq0Gk/svnKJ/K2gZ1gkZGQv/laxOmQ8ikc7d7azsZfAtaDsML3ZKu0fw+VTI9O T8EiRTnZPHkYSdRJq/UrQbkxBiTnoKmNqJuI5ci+TyiimB6IW8QHvMhgjXLkqJWzAhHJ OWU2Fxj0CO9ukN9/B0Zesp59AAVYK5lRNKfCmqsxhd60BT/hjV9L5SQQDGjKKjU1iMVJ zkBaYhAlZGY7Ti9Z0NmzecpFnZskoRAtHxR9DWctH1fGLZ2LlU3qyinUClgt3oBXdf4Y Y24BHkgir9iXGyLPJ3+3IEwlO+6HZEothKwPiR5l/y0UwXhyFxdav+iszGm23nYmQ3M2 iXKQ== 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=xAKBYJi0oboeVaISzpy1fgpCufVHTsqmx7AdhwU/ts4=; b=MLv90SANxIbXUYLugUJ8CdVDYxnYdcJRD8qmqxU8abR4dDb3L8f5Q/wW9C5p1cAs3f AGHTWI8stzsjELw2hEhY2w1Yki+BkCOWsEjURat+lSnCIdy1L3H3GwFs3rp6+RzLfgeY rTdXyyxz48iGqadgyIoOtGf7Wp3EmD8qSXpvFaOPshgJCMdo04/a4SgRdnLgId30i/IV az0TH9pvsPzBNqy0HnJ18DoeYwPgDDrdr/B5ga+MxnGZg9RCH3Kwku9jbvXI495+rJQK /NX1FzIeYgwxF72VWjW6rQNcdFxjhwEaKrOnIvYt4j4VzKhOTXc5RwW0kei5JLA9WMy7 jW9g== X-Gm-Message-State: AOAM530CaW8KEcnIiIbZ24ofTaXcDDx9EsPRG/UwoCtYrfqNmV3Nyi+/ TZBu2m00jDn/MpiOgseNdlpnJA== X-Received: by 2002:a63:441c:: with SMTP id r28mr25822754pga.372.1595397982547; Tue, 21 Jul 2020 23:06:22 -0700 (PDT) Received: from localhost.localdomain (p6e424d9a.tkyea130.ap.so-net.ne.jp. [110.66.77.154]) by smtp.gmail.com with ESMTPSA id p10sm19578759pgn.6.2020.07.21.23.06.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jul 2020 23:06:21 -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 v4 03/16] common: update: add a generic interface for FIT image Date: Wed, 22 Jul 2020 15:05:26 +0900 Message-Id: <20200722060539.15168-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200722060539.15168-1-takahiro.akashi@linaro.org> References: <20200722060539.15168-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..dce2997f9a6a 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 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__ */