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 D0EF7C4332F for ; Fri, 14 Oct 2022 06:42:24 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B145C84DD1; Fri, 14 Oct 2022 08:42:22 +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="Aoeun4Dr"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B540384EAE; Fri, 14 Oct 2022 08:42:20 +0200 (CEST) Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) (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 0351684D64 for ; Fri, 14 Oct 2022 08:42:18 +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=ilias.apalodimas@linaro.org Received: by mail-ej1-x62b.google.com with SMTP id w18so8402420ejq.11 for ; Thu, 13 Oct 2022 23:42:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=5I6QGMczvrWCgZgElmIj+Q5FlItzXuCX/GaHNNIOzoc=; b=Aoeun4DrQKoxH5xSNSWxhO8Yz+olpyEwnZ3E0FyL6bYIAAtqmLDXE7SvfMxBBpYkAR LrhPzY77Ek8rHAtm4OPeA1320cVOyjlzC46t6TG+q1sIcPb1Sd01mpLFbTqzAwnVaY4B imrQHvg4trNxA6P/sUFTjhvzqZOV7702O8w021QUSEVrrWfrWR5elbGL7o2hUr8kac12 QBwO5oJqYUvBwdrzQygqWhILZzBEouXDIkln58WIzUZTwqQYiyNsW2cikwIwB0TnK7h2 +zB/UwaDG90vIN9VFx7WBf17yTNdivtiEdHz9Mw9T+DQgpxO5KLBnvvByZ/5KKn8hkS3 z1dA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=5I6QGMczvrWCgZgElmIj+Q5FlItzXuCX/GaHNNIOzoc=; b=gtx3iPE57bPYOC95ExARPkvKMq8S5lytJiyAwpmavqVw2WQhH0i/HRcVJkeGTOyUmW rV+LeawZf7sXXidkJ95C5zAp4q4r6oMc9VGtmAdf8y3O87N/oyGGnYIg6EpJtec1iJJR oPjxKzku6E6oHJb2G0LUWpwSU9f5o02vqBhDwMDVpSfpqcE36a4xugrjn8y+8htmroZU huHRvnUnlNkkWl/QCC1qbybBGBO5q3CSnE3OR6AJKIFLwN0/3idhQO667TLuNAewk1Vj DQNlO5Al48zm9wx7FOeZASXHp5igL/QF0ivhloPqEYjWz/AHARegaXxlj+UF8oqkk0iu hAfw== X-Gm-Message-State: ACrzQf0j0WMQvO6ott8v8oT6gipMAV091mjBiFuUsILHWg0yGrQdOLyo Tejh2BtzRfhqlUNE3oq9GEwZcw== X-Google-Smtp-Source: AMsMyM6XnsSafPbmWlP8ZH62Ghfu8y8OBriHJdN7t1DMuY5B4b7gtl8exG0iZUwqt/J56qboG7Fqwg== X-Received: by 2002:a17:907:70a:b0:741:78ab:dce5 with SMTP id xb10-20020a170907070a00b0074178abdce5mr2475209ejb.527.1665729737547; Thu, 13 Oct 2022 23:42:17 -0700 (PDT) Received: from hera (ppp046103015185.access.hol.gr. [46.103.15.185]) by smtp.gmail.com with ESMTPSA id p10-20020a170906228a00b0078bfe57fc7bsm1034423eja.47.2022.10.13.23.42.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 23:42:17 -0700 (PDT) Date: Fri, 14 Oct 2022 09:42:14 +0300 From: Ilias Apalodimas To: Sughosh Ganu Cc: u-boot@lists.denx.de, Heinrich Schuchardt , Takahiro Akashi , Patrick Delaunay , Patrice Chotard , Simon Glass , Bin Meng , Tom Rini , Etienne Carriere , Michal Simek , Jassi Brar Subject: Re: [PATCH v13 10/15] FWU: Add support for the FWU Multi Bank Update feature Message-ID: References: <20221006090629.436518-1-sughosh.ganu@linaro.org> <20221006090629.436518-11-sughosh.ganu@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221006090629.436518-11-sughosh.ganu@linaro.org> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.6 at phobos.denx.de X-Virus-Status: Clean On Thu, Oct 06, 2022 at 02:36:24PM +0530, Sughosh Ganu wrote: > The FWU Multi Bank Update feature supports updation of firmware images s/updation/updating > to one of multiple sets(also called banks) of images. The firmware > images are clubbed together in banks, with the system booting images > from the active bank. Information on the images such as which bank > they belong to is stored as part of the metadata structure, which is > stored on the same storage media as the firmware images on a dedicated > 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 active > bank to subsequently boot from. > > Signed-off-by: Sughosh Ganu > --- > Changes since V12: None > > drivers/Kconfig | 2 + > drivers/Makefile | 1 + > include/fwu.h | 30 +++++ > lib/Kconfig | 6 + > lib/Makefile | 1 + > lib/efi_loader/efi_capsule.c | 207 +++++++++++++++++++++++++++++++++- > lib/efi_loader/efi_firmware.c | 14 +++ > lib/fwu_updates/Kconfig | 33 ++++++ > lib/fwu_updates/Makefile | 7 ++ > lib/fwu_updates/fwu.c | 22 ++++ > 10 files changed, 321 insertions(+), 2 deletions(-) > create mode 100644 lib/fwu_updates/Kconfig > create mode 100644 lib/fwu_updates/Makefile > > diff --git a/drivers/Kconfig b/drivers/Kconfig > index 8b6fead351..75ac149d31 100644 > --- a/drivers/Kconfig > +++ b/drivers/Kconfig > @@ -44,6 +44,8 @@ source "drivers/fuzz/Kconfig" > > source "drivers/fpga/Kconfig" > > +source "drivers/fwu-mdata/Kconfig" > + > source "drivers/gpio/Kconfig" > > source "drivers/hwspinlock/Kconfig" > diff --git a/drivers/Makefile b/drivers/Makefile > index 9d9f69a3c9..253cbfb71d 100644 > --- a/drivers/Makefile > +++ b/drivers/Makefile > @@ -85,6 +85,7 @@ obj-y += cache/ > obj-$(CONFIG_CPU) += cpu/ > obj-y += crypto/ > obj-$(CONFIG_FASTBOOT) += fastboot/ > +obj-$(CONFIG_FWU_MDATA) += fwu-mdata/ > obj-y += misc/ > obj-$(CONFIG_MMC) += mmc/ > obj-$(CONFIG_NVME) += nvme/ > diff --git a/include/fwu.h b/include/fwu.h > index 2effa7da38..b5c59dc161 100644 > --- a/include/fwu.h > +++ b/include/fwu.h > @@ -60,6 +60,7 @@ struct fwu_mdata_ops { > }; > > @@ -388,6 +395,130 @@ efi_status_t efi_capsule_authenticate(const void *capsule, efi_uintn_t capsule_s > } > #endif /* CONFIG_EFI_CAPSULE_AUTHENTICATE */ > > +static __maybe_unused bool fwu_empty_capsule(struct efi_capsule_header *capsule) > +{ > + return !guidcmp(&capsule->capsule_guid, > + &fwu_guid_os_request_fw_revert) || > + !guidcmp(&capsule->capsule_guid, > + &fwu_guid_os_request_fw_accept); > +} > + > +static __maybe_unused efi_status_t fwu_to_efi_error(int err) > +{ > + efi_status_t ret; > + > + switch(err) { > + case 0: > + ret = EFI_SUCCESS; > + break; > + case -ENODEV: ENODEV should return EFI_INVALID_PARAMETER. The device was not found, EFI_DEVICE_ERROR usually means something bad happened to the device > + case -ERANGE: > + case -EIO: > + ret = EFI_DEVICE_ERROR; > + break; > + case -EINVAL: > + ret = EFI_INVALID_PARAMETER; > + break; > + default: > + ret = EFI_OUT_OF_RESOURCES; > + } > + > + return ret; > +} > + > +static __maybe_unused efi_status_t fwu_empty_capsule_process( > + struct efi_capsule_header *capsule) > +{ > + int status; > + u32 active_idx; > + efi_status_t ret; > + efi_guid_t *image_guid; > + > + if (!guidcmp(&capsule->capsule_guid, > + &fwu_guid_os_request_fw_revert)) { > + /* > + * One of the previously updated image has > + * failed the OS acceptance test. OS has > + * requested to revert back to the earlier > + * boot index > + */ > + status = fwu_revert_boot_index(); > + ret = fwu_to_efi_error(status); > + if (ret == EFI_SUCCESS) > + log_info("Reverted the FWU active_index. Recommend rebooting the system\n"); > + else > + log_err("Failed to revert the FWU boot index\n"); > + } else { We should be explicit on the GUID checking here. IOW if someone hands you over and empty capsule with a guid !fwu_guid_os_request_fw_revert you'll accept the capsule > + /* > + * Image accepted by the OS. Set the acceptance > + * status for the image. > + */ > + image_guid = (void *)(char *)capsule + > + capsule->header_size; > + > + status = fwu_get_active_index(&active_idx); > + ret = fwu_to_efi_error(status); > + if (ret != EFI_SUCCESS) { > + log_err("Unable to get the active_index from the FWU metadata\n"); > + return ret; > + } > + > + status = fwu_accept_image(image_guid, active_idx); > + ret = fwu_to_efi_error(status); > + if (ret != EFI_SUCCESS) > + log_err("Unable to set the Accept bit for the image %pUs\n", > + image_guid); > + } > + > + return ret; > +} > + > +static __maybe_unused void fwu_post_update_checks( > + struct efi_capsule_header *capsule, > + bool *fw_accept_os, bool *capsule_update) > +{ > + if (fwu_empty_capsule(capsule)) > + *capsule_update = false; > + else > + if (!*fw_accept_os) This line should fold to the upper one > + *fw_accept_os = > + capsule->flags & FW_ACCEPT_OS ? true : false; > +} > + > +static __maybe_unused efi_status_t fwu_post_update_process(bool fw_accept_os) > +{ > + int status; > + u32 update_index; > + efi_status_t ret; > + > + status = fwu_plat_get_update_index(&update_index); > + if (status < 0) { > + log_err("Failed to get the FWU update_index value\n"); > + return EFI_DEVICE_ERROR; > + } > + > + /* > + * All the capsules have been updated successfully, > + * update the FWU metadata. > + */ > + log_debug("Update Complete. Now updating active_index to %u\n", > + update_index); > + status = fwu_set_active_index(update_index); > + ret = fwu_to_efi_error(status); > + if (ret != EFI_SUCCESS) { > + log_err("Failed to update FWU metadata index values\n"); > + } else { > + log_debug("Successfully updated the active_index\n"); [...] Thanks /Ilias