From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6B1ABC433EF for ; Mon, 20 Dec 2021 23:57:24 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D530C83788; Tue, 21 Dec 2021 00:57:21 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=konsulko.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=konsulko.com header.i=@konsulko.com header.b="DqeTzekc"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E799A83790; Tue, 21 Dec 2021 00:57:19 +0100 (CET) Received: from mail-qk1-x72c.google.com (mail-qk1-x72c.google.com [IPv6:2607:f8b0:4864:20::72c]) (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 923E68304F for ; Tue, 21 Dec 2021 00:57:14 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=konsulko.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=trini@konsulko.com Received: by mail-qk1-x72c.google.com with SMTP id p4so10987706qkm.7 for ; Mon, 20 Dec 2021 15:57:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=5b8DmfOrgDzLtTrDhv3mQ79Tpmc3ed31Ceg3iCtazVY=; b=DqeTzekcS2joQrDpAJOENFqCEKeL/g9qXv5/QI10PsKlNu8JFPWnzYFO9/qjGPhAeD non2B/ojRYXfLg5NvQnXTHv7nq6QOgkD5tSsov+enOEkDISFdbfrLcCkPhIAoIK7G9ap LMTCZSAxGi/+bg/MYR4bYyOq+2uEzYQYgKG7I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=5b8DmfOrgDzLtTrDhv3mQ79Tpmc3ed31Ceg3iCtazVY=; b=QrsLjGTiYU+dAhQYQU/n/0ut0urJ5ZR4LjII0uQYrnb23lWcxL+b3ENf1Cx/VNMoX3 o39/hj2RuUKhV9/1G23vamD8qAHMuMRt0iXcUw5yZiu2gjHO7sXVEYPjhbLMSzDffg51 ADy6QshSjQjXXCUJ2TEr/X74S39/NQTSP6iiqXn1jGdU2M/D4n3Bq8UHBZXL9tRiGHNs 1WNRuVBuKbJsJQ3wPS3ORE53FnjpT0IWGNBtVDG/DE4NI5c8ieq7i7e+MoyYXK3nQnBF PhPhL0yUxIogF5iP97AYcVusIPwyJaR4xD7sYOLyjZuQjRIEB/zTKZVHL6yuPUbYuNC8 DOVQ== X-Gm-Message-State: AOAM533Tej0xOnvcl1tWJ0TauiT9YNFdFa+gN1EqbWTsAlxAOm7n9AU9 NiXYgtjluLd1Y0HRpouS9WwwBQ== X-Google-Smtp-Source: ABdhPJwuIIs+ic/PeZKgwAZEjnVv2GnZ6H/nQKQKL3T3qCkUD+EP5umGFjdl17e1M4O0o5MB+FoYfQ== X-Received: by 2002:a05:620a:2486:: with SMTP id i6mr458139qkn.522.1640044633132; Mon, 20 Dec 2021 15:57:13 -0800 (PST) Received: from bill-the-cat (2603-6081-7b01-cbda-c90a-b114-2d52-2406.res6.spectrum.com. [2603:6081:7b01:cbda:c90a:b114:2d52:2406]) by smtp.gmail.com with ESMTPSA id j9sm12619103qkp.111.2021.12.20.15.57.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Dec 2021 15:57:12 -0800 (PST) Date: Mon, 20 Dec 2021 18:57:10 -0500 From: Tom Rini To: Masami Hiramatsu Cc: Sughosh Ganu , AKASHI Takahiro , u-boot@lists.denx.de, Patrick Delaunay , Patrice Chotard , Heinrich Schuchardt , Alexander Graf , Simon Glass , Bin Meng , Ilias Apalodimas , Jose Marinho , Grant Likely , Jason Liu , Etienne Carriere Subject: Re: [RFC PATCH v2 7/8] FWU: Add support for FWU Multi Bank Update feature Message-ID: <20211220235710.GI2773246@bill-the-cat> References: <20211219070605.14894-1-sughosh.ganu@linaro.org> <20211219070605.14894-8-sughosh.ganu@linaro.org> <20211220061448.GC31993@laputa> <20211220163619.GD2773246@bill-the-cat> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="WxezjuMNsgvRf6mf" Content-Disposition: inline In-Reply-To: X-Clacks-Overhead: GNU Terry Pratchett X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.38 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.103.2 at phobos.denx.de X-Virus-Status: Clean --WxezjuMNsgvRf6mf Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Dec 21, 2021 at 08:30:02AM +0900, Masami Hiramatsu wrote: > Hi Tom, >=20 > 2021=E5=B9=B412=E6=9C=8821=E6=97=A5(=E7=81=AB) 1:36 Tom Rini : > > > > On Mon, Dec 20, 2021 at 10:13:35PM +0900, Masami Hiramatsu wrote: > > > Hi Sughosh, > > > > > > 2021=E5=B9=B412=E6=9C=8820=E6=97=A5(=E6=9C=88) 18:48 Sughosh Ganu : > > > > > > > > > > > > On Mon, 20 Dec 2021 at 11:44, AKASHI Takahiro wrote: > > > >> > > > >> On Sun, Dec 19, 2021 at 12:36:04PM +0530, Sughosh Ganu wrote: > > > >> > The FWU Multi Bank Update feature supports updation of firmware = images > > > >> > to one of multiple sets(also called banks) of images. The firmwa= re > > > >> > images are clubbed together in banks, with the system booting im= ages > > > >> > from the active bank. Information on the images such as which ba= nk > > > >> > they belong to is stored as part of the metadata structure, whic= h is > > > >> > stored on the same storage media as the firmware images on a ded= icated > > > >> > partition. > > > >> > > > > >> > At the time of update, the metadata is read to identify the bank= to > > > >> > which the images need to be flashed(update bank). On a successful > > > >> > update, the metadata is modified to set the updated bank as acti= ve > > > >> > bank to subsequently boot from. > > > >> > > > > >> > Signed-off-by: Sughosh Ganu > > > >> > --- > > > >> > Changes since V1: > > > >> > * Call function fwu_update_checks_pass to check if the > > > >> > update can be initiated > > > >> > * Do not allow firmware update from efi_init_obj_list as the > > > >> > fwu boot-time checks need to be run > > > >> > > > > >> > include/fwu.h | 18 +++- > > > >> > lib/Kconfig | 32 ++++++ > > > >> > lib/Makefile | 1 + > > > >> > lib/efi_loader/efi_capsule.c | 198 ++++++++++++++++++++++++++++= ++++++- > > > >> > lib/efi_loader/efi_setup.c | 3 +- > > > >> > lib/fwu_updates/Makefile | 11 ++ > > > >> > lib/fwu_updates/fwu.c | 27 +++++ > > > >> > 7 files changed, 284 insertions(+), 6 deletions(-) > > > >> > create mode 100644 lib/fwu_updates/Makefile > > > >> > > > > >> > diff --git a/include/fwu.h b/include/fwu.h > > > >> > index 2d2e674d6a..bf50fe9277 100644 > > > >> > --- a/include/fwu.h > > > >> > +++ b/include/fwu.h > > > >> > @@ -10,14 +10,28 @@ > > > >> > > > > >> > #include > > > >> > > > > >> > -#define FWU_MDATA_VERSION 0x1 > > > >> > +#define FWU_MDATA_GUID \ > > > >> > + EFI_GUID(0x8a7a84a0, 0x8387, 0x40f6, 0xab, 0x41, \ > > > >> > + 0xa8, 0xb9, 0xa5, 0xa6, 0x0d, 0x23) > > > >> > + > > > >> > +#define FWU_OS_REQUEST_FW_REVERT_GUID \ > > > >> > + EFI_GUID(0xacd58b4b, 0xc0e8, 0x475f, 0x99, 0xb5, \ > > > >> > + 0x6b, 0x3f, 0x7e, 0x07, 0xaa, 0xf0) > > > >> > + > > > >> > +#define FWU_OS_REQUEST_FW_ACCEPT_GUID \ > > > >> > + EFI_GUID(0x0c996046, 0xbcc0, 0x4d04, 0x85, 0xec, \ > > > >> > + 0xe1, 0xfc, 0xed, 0xf1, 0xc6, 0xf8) > > > >> > > > > >> > #define FWU_MDATA_GUID \ > > > >> > EFI_GUID(0x8a7a84a0, 0x8387, 0x40f6, 0xab, 0x41, \ > > > >> > 0xa8, 0xb9, 0xa5, 0xa6, 0x0d, 0x23) > > > >> > > > > >> > -int fwu_boottime_checks(void); > > > >> > +#define FWU_MDATA_VERSION 0x1 > > > >> > +#define FWU_IMAGE_ACCEPTED 0x1 > > > >> > + > > > >> > u8 fwu_update_checks_pass(void); > > > >> > +int fwu_boottime_checks(void); > > > >> > +int fwu_trial_state_ctr_start(void); > > > >> > > > > >> > int fwu_get_active_index(u32 *active_idx); > > > >> > int fwu_update_active_index(u32 active_idx); > > > >> > diff --git a/lib/Kconfig b/lib/Kconfig > > > >> > index 807a4c6ade..7cb306317c 100644 > > > >> > --- a/lib/Kconfig > > > >> > +++ b/lib/Kconfig > > > >> > @@ -835,3 +835,35 @@ config PHANDLE_CHECK_SEQ > > > >> > When there are multiple device tree nodes with same name, > > > >> > enable this config option to distinguish them using > > > >> > phandles in fdtdec_get_alias_seq() function. > > > >> > + > > > >> > +config FWU_MULTI_BANK_UPDATE > > > >> > + bool "Enable FWU Multi Bank Update Feature" > > > >> > + depends on EFI_HAVE_CAPSULE_SUPPORT > > > >> > + select PARTITION_TYPE_GUID > > > >> > + select EFI_SETUP_EARLY > > > >> > + help > > > >> > + Feature for updating firmware images on platforms having > > > >> > + multiple banks(copies) of the firmware images. One of the > > > >> > + bank is selected for updating all the firmware components > > > >> > + > > > >> > +config FWU_NUM_BANKS > > > >> > + int "Number of Banks defined by the platform" > > > >> > + depends on FWU_MULTI_BANK_UPDATE > > > >> > + help > > > >> > + Define the number of banks of firmware images on a platf= orm > > > >> > + > > > >> > +config FWU_NUM_IMAGES_PER_BANK > > > >> > + int "Number of firmware images per bank" > > > >> > + depends on FWU_MULTI_BANK_UPDATE > > > >> > + help > > > >> > + Define the number of firmware images per bank. This value > > > >> > + should be the same for all the banks. > > > >> > + > > > >> > +config FWU_TRIAL_STATE_CNT > > > >> > + int "Number of times system boots in Trial State" > > > >> > + depends on FWU_MULTI_BANK_UPDATE > > > >> > + default 3 > > > >> > + help > > > >> > + With FWU Multi Bank Update feature enabled, number of ti= mes > > > >> > + the platform is allowed to boot in Trial State after an > > > >> > + update. > > > >> > diff --git a/lib/Makefile b/lib/Makefile > > > >> > index 5ddbc77ed6..bc5c1e22fc 100644 > > > >> > --- a/lib/Makefile > > > >> > +++ b/lib/Makefile > > > >> > @@ -9,6 +9,7 @@ obj-$(CONFIG_EFI) +=3D efi/ > > > >> > obj-$(CONFIG_EFI_LOADER) +=3D efi_driver/ > > > >> > obj-$(CONFIG_EFI_LOADER) +=3D efi_loader/ > > > >> > obj-$(CONFIG_CMD_BOOTEFI_SELFTEST) +=3D efi_selftest/ > > > >> > +obj-$(CONFIG_FWU_MULTI_BANK_UPDATE) +=3D fwu_updates/ > > > >> > obj-$(CONFIG_LZMA) +=3D lzma/ > > > >> > obj-$(CONFIG_BZIP2) +=3D bzip2/ > > > >> > obj-$(CONFIG_TIZEN) +=3D tizen/ > > > >> > diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_c= apsule.c > > > >> > index 8301eed631..6dfe56bb0f 100644 > > > >> > --- a/lib/efi_loader/efi_capsule.c > > > >> > +++ b/lib/efi_loader/efi_capsule.c > > > >> > @@ -14,6 +14,7 @@ > > > >> > #include > > > >> > #include > > > >> > #include > > > >> > +#include > > > >> > #include > > > >> > #include > > > >> > #include > > > >> > @@ -30,6 +31,13 @@ static const efi_guid_t efi_guid_firmware_man= agement_capsule_id =3D > > > >> > EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID; > > > >> > const efi_guid_t efi_guid_firmware_management_protocol =3D > > > >> > EFI_FIRMWARE_MANAGEMENT_PROTOCOL_GUID; > > > >> > +const efi_guid_t fwu_guid_os_request_fw_revert =3D > > > >> > + FWU_OS_REQUEST_FW_REVERT_GUID; > > > >> > +const efi_guid_t fwu_guid_os_request_fw_accept =3D > > > >> > + FWU_OS_REQUEST_FW_ACCEPT_GUID; > > > >> > + > > > >> > +__maybe_unused static u32 update_index; > > > >> > +__maybe_unused static bool capsule_update; > > > >> > > > > >> > #ifdef CONFIG_EFI_CAPSULE_ON_DISK > > > >> > /* for file system access */ > > > >> > @@ -403,10 +411,13 @@ static efi_status_t efi_capsule_update_fir= mware( > > > >> > void *image_binary, *vendor_code; > > > >> > efi_handle_t *handles; > > > >> > efi_uintn_t no_handles; > > > >> > - int item; > > > >> > + int item, alt_no; > > > >> > struct efi_firmware_management_protocol *fmp; > > > >> > u16 *abort_reason; > > > >> > + efi_guid_t image_type_id; > > > >> > efi_status_t ret =3D EFI_SUCCESS; > > > >> > + int status; > > > >> > + u8 image_index; > > > >> > > > > >> > /* sanity check */ > > > >> > if (capsule_data->header_size < sizeof(*capsule) || > > > >> > @@ -481,8 +492,36 @@ static efi_status_t efi_capsule_update_firm= ware( > > > >> > goto out; > > > >> > } > > > >> > > > > >> > + if (IS_ENABLED(CONFIG_FWU_MULTI_BANK_UPDATE)) { > > > >> > + /* > > > >> > + * Based on the value of update_image_type= _id, > > > >> > + * derive the alt number value. This will = be > > > >> > + * passed as update_image_index to the > > > >> > + * set_image function. > > > >> > + */ > > > >> > + image_type_id =3D image->update_image_type= _id; > > > >> > + status =3D fwu_get_image_alt_num(image_typ= e_id, > > > >> > + update_inde= x, > > > >> > + &alt_no); > > > >> > + if (status < 0) { > > > >> > + log_err("Unable to get the alt no = for the image type %pUl\n", > > > >> > + &image_type_id); > > > >> > + if (status =3D=3D -ENODEV || statu= s =3D=3D -EIO) > > > >> > + ret =3D EFI_DEVICE_ERROR; > > > >> > + else if (status =3D=3D -ENOMEM) > > > >> > + ret =3D EFI_OUT_OF_RESOURC= ES; > > > >> > + else if (status =3D=3D -ERANGE || = status =3D=3D -EINVAL) > > > >> > + ret =3D EFI_INVALID_PARAME= TER; > > > >> > + goto out; > > > >> > + } > > > >> > + log_debug("alt_no %u for Image Type Id %pU= l\n", > > > >> > + alt_no, &image_type_id); > > > >> > + image_index =3D alt_no + 1; > > > >> > + } else { > > > >> > + image_index =3D image->update_image_index; > > > >> > + } > > > >> > abort_reason =3D NULL; > > > >> > - ret =3D EFI_CALL(fmp->set_image(fmp, image->update= _image_index, > > > >> > + ret =3D EFI_CALL(fmp->set_image(fmp, image_index, > > > >> > image_binary, > > > >> > image_binary_size, > > > >> > vendor_code, NULL, > > > >> > @@ -493,6 +532,24 @@ static efi_status_t efi_capsule_update_firm= ware( > > > >> > efi_free_pool(abort_reason); > > > >> > goto out; > > > >> > } > > > >> > + > > > >> > + if (IS_ENABLED(CONFIG_FWU_MULTI_BANK_UPDATE)) { > > > >> > + status =3D fwu_clear_accept_image(&image_t= ype_id, > > > >> > + update_ind= ex); > > > >> > + if (status < 0) { > > > >> > + log_err("Unable to clear the accep= t bit for the image %pUl\n", > > > >> > + &image_type_id); > > > >> > + if (status =3D=3D -ENODEV || statu= s =3D=3D -EIO) > > > >> > + ret =3D EFI_DEVICE_ERROR; > > > >> > + else if (status =3D=3D -ENOMEM) > > > >> > + ret =3D EFI_OUT_OF_RESOURC= ES; > > > >> > + else if (status =3D=3D -ERANGE || = status =3D=3D -EINVAL) > > > >> > + ret =3D EFI_INVALID_PARAME= TER; > > > >> > + goto out; > > > >> > + } > > > >> > + log_debug("Cleared out accepted bit for Im= age %pUl\n", &image_type_id); > > > >> > + } > > > >> > + > > > >> > } > > > >> > > > > >> > out: > > > >> > @@ -527,6 +584,9 @@ efi_status_t EFIAPI efi_update_capsule( > > > >> > u64 scatter_gather_list) > > > >> > { > > > >> > struct efi_capsule_header *capsule; > > > >> > + efi_guid_t *image_guid; > > > >> > + u32 active_idx; > > > >> > + int status; > > > >> > unsigned int i; > > > >> > efi_status_t ret; > > > >> > > > > >> > @@ -538,6 +598,16 @@ efi_status_t EFIAPI efi_update_capsule( > > > >> > goto out; > > > >> > } > > > >> > > > > >> > + if (IS_ENABLED(CONFIG_FWU_MULTI_BANK_UPDATE)) { > > > >> > + /* Obtain the update_index from the platform */ > > > >> > + status =3D fwu_plat_get_update_index(&update_index= ); > > > >> > + if (status < 0) { > > > >> > + log_err("Failed to get the FWU update_inde= x value\n"); > > > >> > + ret =3D EFI_DEVICE_ERROR; > > > >> > + goto out; > > > >> > + } > > > >> > + } > > > >> > + > > > >> > ret =3D EFI_SUCCESS; > > > >> > for (i =3D 0, capsule =3D *capsule_header_array; i < capsu= le_count; > > > >> > i++, capsule =3D *(++capsule_header_array)) { > > > >> > @@ -552,7 +622,64 @@ efi_status_t EFIAPI efi_update_capsule( > > > >> > i, &capsule->capsule_guid); > > > >> > if (!guidcmp(&capsule->capsule_guid, > > > >> > &efi_guid_firmware_management_capsule= _id)) { > > > >> > + if (IS_ENABLED(CONFIG_FWU_MULTI_BANK_UPDAT= E)) { > > > >> > + if (!fwu_update_checks_pass()) { > > > >> > + log_err("FWU checks failed= =2E Cannot start update\n"); > > > >> > + ret =3D EFI_INVALID_PARAME= TER; > > > >> > + goto out; > > > >> > + } > > > >> > + } > > > >> > + > > > >> > ret =3D efi_capsule_update_firmware(capsu= le); > > > >> > + capsule_update =3D true; > > > >> > + } else if (IS_ENABLED(CONFIG_FWU_MULTI_BANK_UPDATE= )) { > > > >> > + capsule_update =3D false; > > > >> > + if (!guidcmp(&capsule->capsule_guid, > > > >> > + &fwu_guid_os_request_fw_rever= t)) { > > > >> > + /* > > > >> > + * One of the previously updated i= mage has > > > >> > + * failed the OS acceptance test. = OS has > > > >> > + * requested to revert back to the= earlier > > > >> > + * boot index > > > >> > + */ > > > >> > + status =3D fwu_revert_boot_index(); > > > >> > + if (status < 0) { > > > >> > + log_err("Failed to revert = the FWU boot index\n"); > > > >> > + if (status =3D=3D -ENODEV = || > > > >> > + status =3D=3D -ERANGE = || > > > >> > + status =3D=3D -EIO) > > > >> > + ret =3D EFI_DEVICE= _ERROR; > > > >> > + else if (status =3D=3D -EI= NVAL) > > > >> > + ret =3D EFI_INVALI= D_PARAMETER; > > > >> > + else if (status =3D=3D -EN= OMEM) > > > >> > + ret =3D EFI_OUT_OF= _RESOURCES; > > > >> > + } else { > > > >> > + ret =3D EFI_SUCCESS; > > > >> > + log_err("Reverted the FWU = active_index to %u. Recommend rebooting the system\n", > > > >> > + active_idx); > > > >> > + } > > > >> > + } else if (!guidcmp(&capsule->capsule_guid, > > > >> > + &fwu_guid_os_request_f= w_accept)) { > > > >> > + /* > > > >> > + * Image accepted by the OS. Set t= he acceptance > > > >> > + * status for the image. > > > >> > + */ > > > >> > + image_guid =3D (void *)(char *)cap= sule + > > > >> > + capsule->header_size; > > > >> > + status =3D fwu_accept_image(image_= guid); > > > >> > + if (status < 0) { > > > >> > + if (status =3D=3D -ENODEV = || > > > >> > + status =3D=3D -ERANGE = || > > > >> > + status =3D=3D -EIO) > > > >> > + ret =3D EFI_DEVICE= _ERROR; > > > >> > + else if (status =3D=3D -EI= NVAL) > > > >> > + ret =3D EFI_INVALI= D_PARAMETER; > > > >> > + else if (status =3D=3D -EN= OMEM) > > > >> > + ret =3D EFI_OUT_OF= _RESOURCES; > > > >> > + } else { > > > >> > + ret =3D EFI_SUCCESS; > > > >> > + } > > > >> > + } > > > >> > } else { > > > >> > log_err("Unsupported capsule type: %pUl\n", > > > >> > &capsule->capsule_guid); > > > >> > @@ -563,6 +690,36 @@ efi_status_t EFIAPI efi_update_capsule( > > > >> > goto out; > > > >> > } > > > >> > > > > >> > + /* > > > >> > + * Update the FWU metadata once all the capsules have > > > >> > + * been updated. This is done only for the Runtime > > > >> > + * capsule update service. > > > >> > + * The update_index value now gets written to the > > > >> > + * active_index and the update_index value also > > > >> > + * gets updated. > > > >> > + * For the capsule-on-disk feature, the updation > > > >> > + * of the FWU metadata happens in efi_launch_capsules > > > >> > + */ > > > >> > + if (IS_ENABLED(CONFIG_FWU_MULTI_BANK_UPDATE) && > > > >> > + !IS_ENABLED(CONFIG_EFI_CAPSULE_ON_DISK)) { > > > >> > + status =3D fwu_update_active_index(update_index); > > > >> > + if (status < 0) { > > > >> > + log_err("Failed to update FWU metadata ind= ex values\n"); > > > >> > + if (status =3D=3D -EINVAL || status =3D=3D= -ERANGE) > > > >> > + ret =3D EFI_INVALID_PARAMETER; > > > >> > + else if (status =3D=3D -ENODEV || status = =3D=3D -EIO) > > > >> > + ret =3D EFI_DEVICE_ERROR; > > > >> > + else if (status =3D=3D -ENOMEM) > > > >> > + ret =3D EFI_OUT_OF_RESOURCES; > > > >> > + } else { > > > >> > + status =3D fwu_trial_state_ctr_start(); > > > >> > + if (status < 0) > > > >> > + ret =3D EFI_DEVICE_ERROR; > > > >> > + else > > > >> > + ret =3D EFI_SUCCESS; > > > >> > + } > > > >> > + } > > > >> > + > > > >> > if (IS_ENABLED(CONFIG_EFI_ESRT)) { > > > >> > /* Rebuild the ESRT to reflect any updated FW imag= es. */ > > > >> > ret =3D efi_esrt_populate(); > > > >> > @@ -1090,8 +1247,10 @@ efi_status_t efi_launch_capsules(void) > > > >> > { > > > >> > struct efi_capsule_header *capsule =3D NULL; > > > >> > u16 **files; > > > >> > + int status; > > > >> > unsigned int nfiles, index, i; > > > >> > efi_status_t ret; > > > >> > + bool update_status =3D true; > > > >> > > > > >> > if (check_run_capsules() !=3D EFI_SUCCESS) > > > >> > return EFI_SUCCESS; > > > >> > @@ -1119,9 +1278,11 @@ efi_status_t efi_launch_capsules(void) > > > >> > ret =3D efi_capsule_read_file(files[i], &capsule); > > > >> > if (ret =3D=3D EFI_SUCCESS) { > > > >> > ret =3D EFI_CALL(efi_update_capsule(&capsu= le, 1, 0)); > > > >> > - if (ret !=3D EFI_SUCCESS) > > > >> > + if (ret !=3D EFI_SUCCESS) { > > > >> > log_err("Applying capsule %ls fail= ed\n", > > > >> > files[i]); > > > >> > + update_status =3D false; > > > >> > + } > > > >> > > > > >> > /* create CapsuleXXXX */ > > > >> > set_capsule_result(index, capsule, ret); > > > >> > @@ -1129,6 +1290,7 @@ efi_status_t efi_launch_capsules(void) > > > >> > free(capsule); > > > >> > } else { > > > >> > log_err("Reading capsule %ls failed\n", fi= les[i]); > > > >> > + update_status =3D false; > > > >> > } > > > >> > /* delete a capsule either in case of success or f= ailure */ > > > >> > ret =3D efi_capsule_delete_file(files[i]); > > > >> > @@ -1136,7 +1298,37 @@ efi_status_t efi_launch_capsules(void) > > > >> > log_err("Deleting capsule %ls failed\n", > > > >> > files[i]); > > > >> > } > > > >> > + > > > >> > efi_capsule_scan_done(); > > > >> > + if (IS_ENABLED(CONFIG_FWU_MULTI_BANK_UPDATE)) { > > > >> > + if (update_status =3D=3D true && capsule_update = =3D=3D true) { > > > >> > + /* > > > >> > + * All the capsules have been updated succ= essfully, > > > >> > + * update the FWU metadata. > > > >> > + */ > > > >> > + log_debug("Update Complete. Now updating a= ctive_index to %u\n", > > > >> > + update_index); > > > >> > + status =3D fwu_update_active_index(update_= index); > > > >> > + if (status < 0) { > > > >> > + log_err("Failed to update FWU meta= data index values\n"); > > > >> > + if (status =3D=3D -EINVAL || statu= s =3D=3D -ERANGE) > > > >> > + ret =3D EFI_INVALID_PARAME= TER; > > > >> > + else if (status =3D=3D -ENODEV || = status =3D=3D -EIO) > > > >> > + ret =3D EFI_DEVICE_ERROR; > > > >> > + else if (status =3D=3D -ENOMEM) > > > >> > + ret =3D EFI_OUT_OF_RESOURC= ES; > > > >> > + } else { > > > >> > + log_debug("Successfully updated th= e active_index\n"); > > > >> > + status =3D fwu_trial_state_ctr_sta= rt(); > > > >> > + if (status < 0) > > > >> > + ret =3D EFI_DEVICE_ERROR; > > > >> > + else > > > >> > + ret =3D EFI_SUCCESS; > > > >> > + } > > > >> > + } else if (capsule_update =3D=3D true && update_st= atus =3D=3D false) { > > > >> > + log_err("All capsules were not updated. No= t updating FWU metadata\n"); > > > >> > + } > > > >> > + } > > > >> > > > > >> > for (i =3D 0; i < nfiles; i++) > > > >> > free(files[i]); > > > >> > diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_set= up.c > > > >> > index 1aba71cd96..6601176a2d 100644 > > > >> > --- a/lib/efi_loader/efi_setup.c > > > >> > +++ b/lib/efi_loader/efi_setup.c > > > >> > @@ -298,7 +298,8 @@ efi_status_t efi_init_obj_list(void) > > > >> > goto out; > > > >> > > > > >> > /* Execute capsules after reboot */ > > > >> > - if (IS_ENABLED(CONFIG_EFI_CAPSULE_ON_DISK) && > > > >> > + if (!IS_ENABLED(CONFIG_FWU_MULTI_BANK_UPDATE) && > > > >> > + IS_ENABLED(CONFIG_EFI_CAPSULE_ON_DISK) && > > > >> > !IS_ENABLED(CONFIG_EFI_CAPSULE_ON_DISK_EARLY)) > > > >> > ret =3D efi_launch_capsules(); > > > >> > out: > > > >> > diff --git a/lib/fwu_updates/Makefile b/lib/fwu_updates/Makefile > > > >> > new file mode 100644 > > > >> > index 0000000000..73099a30cb > > > >> > --- /dev/null > > > >> > +++ b/lib/fwu_updates/Makefile > > > >> > @@ -0,0 +1,11 @@ > > > >> > +# SPDX-License-Identifier: GPL-2.0+ > > > >> > +# > > > >> > +# Copyright (c) 2021, Linaro Limited > > > >> > +# > > > >> > + > > > >> > +obj-$(CONFIG_FWU_MULTI_BANK_UPDATE) +=3D fwu_mdata.o > > > >> > +obj-$(CONFIG_FWU_MULTI_BANK_UPDATE) +=3D fwu.o > > > >> > + > > > >> > +ifdef CONFIG_EFI_PARTITION > > > >> > +obj-$(CONFIG_FWU_MULTI_BANK_UPDATE) +=3D fwu_mdata_gpt_blk.o > > > >> > +endif > > > >> > > > >> If I understand correctly, any platform may have its own > > > >> fwu_mdata_ops. So we should not unconditionally compile in > > > >> fwu_mdata_gpt_blk.o even if CONFIG_EFI_PARTITION is enabled. > > > > > > > > > > > > I can put in an additional guard of CONFIG_BLK for building the fil= e. Not sure if there would be a requirement to have a platform specific set= of operations for a GPT partitioned block device. Will wait for Masami to = explain. > > > > > > > > > OK, I'm trying to implement the AB update on the developerbox > > > platform, which doesn't have GPT, nor BLK since the firmware will be > > > stored on the SPI NOR flash. So I will introduce a new fwu_mdata_sf.c. > > > For this purpose, I introduced CONFIG_FWU_MULTI_BANK_UPDATE_SF, which > > > depends on CONFIG_FWU_MULTI_BANK_UPDATE and CONFIG_DM_SPI_FLASH. Thus, > > > I also recommend you to introduce CONFIG_FWU_MULTI_BANK_UPDATE_GPT_BLK > > > and it should depends on CONFIG_BLK and selects CONFIG_EFI_PARTITION. > > > > > > BTW, there are some code pieces which can shared with the > > > fwu_mdata_gpt_blk.c, for example, comparing primary and seconday > > > metadata and calculate the crc32. > > > > Here's my concern / question. At what level is this abstraction being > > used? I want to be sure that other SoCs, such as say a Rockchip > > platform (I have a SystemReady IR certified one on the way) can re-use > > this code as well but I'm sure it will need things written to different > > offsets within the SPI/eMMC. Thanks! >=20 > For the metadata, I introduced CONFIG_FWU_SF_PRIMARY_METADATA_OFFSET > and CONFIG_FWU_SF_PRIMARY_METADATA_OFFSET for configuring offset of > the metadata on SPI Flash for my prototype code. > I think it might be better to introduce accessors for the metadata, > e.g. fwu_load_pri_mdata()/fwu_save_sec_mdata() etc. so that the > platform can choose the media which stores metadata independent from > the firmware storage. >=20 > For the firmware offset, it is defined in the dfu_alt_info, so you can > use (or even mix) any storage media like SPI nor or MTD or eMMC. OK, good so you're keeping it in mind. Is there any chance we can get a second platform supported as part of the series itself, to confirm it's sufficient? I always worry a bit about things that are supposed to be abstract enough to support anything but only implemented once. Thanks! --=20 Tom --WxezjuMNsgvRf6mf Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQGzBAABCgAdFiEEGjx/cOCPqxcHgJu/FHw5/5Y0tywFAmHBGFIACgkQFHw5/5Y0 tyxDFAv/XzkzkEAUT6Qv8RtYUsuM0mGZdTTu2/ItK+uZZVJa6Dfr3OqIQP2OSNmf NriaIcjkJTWFp6bhJ1aJhjLBRCFYxn105gpu4TptzRxakZbge/ocRlX8oARxUggv Rb2wmEPV4rG4PDVzSNZygyggGMaeQC0tDFOwU+tqnBjqmjQtD8neV3fdFh1J1ZqS ORIWfFz3G/fgR+fY4EZHg08TH5PJ2Sgf9i96OYBftvXKD5es002rUVV9YFDQ7I7u ofU4TBWaHvHu8vqVdNzoqgMQgApKP4NcA12wMH/K0gN7QmNAUn43UwtntU3j00AP jk8YYUmcpPuC3HdQlBO2NOnEVazIPxfDKh2CQTDnvSeUSP1AISJUijM6At8vw6LF JJdJVq/bBg08l9OGJjCm3hGJVhTzxzLu2f18miylquiEOQO8G/6sWkT5oOVl7nWB bWaDKAdc0jp7+36LBH0JiU9yIjBX8/ye+OyxXyla0+8DfqgxvWAnFsSk8+75VmkA 9KBJowXs =ysSG -----END PGP SIGNATURE----- --WxezjuMNsgvRf6mf--