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 5A181C433F5 for ; Mon, 29 Nov 2021 06:38:31 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1621981725; Mon, 29 Nov 2021 07:38:29 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (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=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="aGAFjoX+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A627382A66; Mon, 29 Nov 2021 07:38:27 +0100 (CET) Received: from mail-il1-x136.google.com (mail-il1-x136.google.com [IPv6:2607:f8b0:4864:20::136]) (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 A071881725 for ; Mon, 29 Nov 2021 07:38:21 +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=sughosh.ganu@linaro.org Received: by mail-il1-x136.google.com with SMTP id t8so16285466ilu.8 for ; Sun, 28 Nov 2021 22:38:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=lzTE6gs681wV9YpOkuySJAFpUiq8UcqBoyf+LC9C4XU=; b=aGAFjoX+TsKBVQ8steY5qIBhrSmRgKvdVyMae3hKTj2qje1Y8xwojAodi3J5C6tXkj iMEA//7zHWJSNp6huDCbawTtophOdIpj94E/eM7Tt2HAu2zzjZOhtht6bTjYSA4s6siH qVdXHcR+yS9lVFgU1qhNT5xAwmgZ2f7uHJZvsaRUxZhjyCz2Oo9bcssXSbUfbygRm2SA o2QXl3VhpugCkHdg0OSAMke6aStckRnrHKJKlJcS0NCYIsyMpvzoSAdbkZ9XIAt5Z4uj ROGvxV5VuqLjZhu16X9qvJHYItSvqwxv0xGzJof4tfREHGhz0fl2bJBXz1Ns/Q9RPe7g 5Jmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=lzTE6gs681wV9YpOkuySJAFpUiq8UcqBoyf+LC9C4XU=; b=x1u5MCkPSt1e4E6RV74Ye9JM1wcnDVFA80D2951CDhuzG2xTofPrWSRiSVjCmrIEA3 9YLSna3XYMc8lEROp6Bt5E+knZO/peoM48KnQWeN9Mh2FxeHhQTHuBt9Ao2dvRtIijm1 ViV5h4Xead4SaEyqmajIxzZ0nBCqhy3DQTod0ZkPpEA4A40YOZCie0T8JWBdaz2VAKGA WTO6wGkqcJqOE8KszN34xQUjgDcBeuNsyQgEbYd2K8zbvfOF9u1YZL4YA/jxTEoespqb by7//BXRYds4/3g+jG7Pmyv/1zlV2mE98TemoinOBxbxyd7ViqSBervw9IP84NIFfIPJ rRPA== X-Gm-Message-State: AOAM532f+q6GEzmMlQLLJR0sUkEoepGvNAKf8GwCc5a3uW7WTVcbX5Nd sy/pdq8fEgKWD+BCwFly3awGf+S5vphOVO0boixdcQ== X-Google-Smtp-Source: ABdhPJwMsLuH8PRLbazERLW88sRnKClF0HYc3GOBkD3113LfF8SrS43Dms31HlMFGJIEg8SpEpJbUf+gX3TbnPtpD6Y= X-Received: by 2002:a05:6e02:20e5:: with SMTP id q5mr53754404ilv.63.1638167899961; Sun, 28 Nov 2021 22:38:19 -0800 (PST) MIME-Version: 1.0 References: <20211125071302.3644-1-sughosh.ganu@linaro.org> <20211125071302.3644-4-sughosh.ganu@linaro.org> In-Reply-To: From: Sughosh Ganu Date: Mon, 29 Nov 2021 12:08:08 +0530 Message-ID: Subject: Re: [RESEND RFC PATCH 03/10] FWU: Add metadata structure and functions for accessing metadata To: Ilias Apalodimas Cc: u-boot@lists.denx.de, Patrick Delaunay , Patrice Chotard , Heinrich Schuchardt , Alexander Graf , Simon Glass , Bin Meng , Peng Fan , AKASHI Takahiro , Jose Marinho , Grant Likely , Jason Liu Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.37 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.37 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 hi Ilias, Thanks for the review. On Fri, 26 Nov 2021 at 17:05, Ilias Apalodimas wrote: > Hi Sughosh, > > On Thu, Nov 25, 2021 at 12:42:55PM +0530, Sughosh Ganu wrote: > > In the FWU Multi Bank Update feature, the information about the > > updatable images is stored as part of the metadata, which is stored on > > a dedicated partition. Add the metadata structure, and functions to > > access the metadata. These are generic API's, and implementations can > > be added based on parameters like how the metadata partition is > > accessed and what type of storage device houses the metadata. > > > > Signed-off-by: Sughosh Ganu > > --- > > include/fwu_metadata.h | 125 +++++++++++++++ > > lib/fwu_updates/fwu_metadata.c | 275 +++++++++++++++++++++++++++++++++ > > 2 files changed, 400 insertions(+) > > create mode 100644 include/fwu_metadata.h > > create mode 100644 lib/fwu_updates/fwu_metadata.c > > > > diff --git a/include/fwu_metadata.h b/include/fwu_metadata.h > > new file mode 100644 > > index 0000000000..e692ef7506 > > --- /dev/null > > +++ b/include/fwu_metadata.h > > @@ -0,0 +1,125 @@ > > +/* SPDX-License-Identifier: GPL-2.0+ */ > > +/* > > + * Copyright (c) 2021, Linaro Limited > > Please add a link here to the arm spec that describes the metadata etc > Will add. > > > + */ > > + > > +#if !defined _FWU_METADATA_H_ > > +#define _FWU_METADATA_H_ > > + > > +#include > > +#include > > +#include > > + > > +#include > > + > > +/** > > + * struct fwu_image_bank_info - firmware image information > > + * @image_uuid: Guid value of the image in this bank > > + * @accepted: Acceptance status of the image > > + * @reserved: Reserved > > + * > > + * The structure contains image specific fields which are > > + * used to identify the image and to specify the image's > > + * acceptance status > > + */ > > +struct fwu_image_bank_info { > > + efi_guid_t image_uuid; > > + u32 accepted; > > + u32 reserved; > > +}; > > fwu_image_bank_info -> fwu_img_bank_info > Okay. > > > + > > +/** > > + * struct fwu_image_entry - information for a particular type of image > > + * @image_type_uuid: Guid value for identifying the image type > > + * @location_uuid: Guid of the storage volume where the image is located > > /s/Guid/GUID > Will change. > > > + * @img_bank_info: Array containing properties of images > > + * > > + * This structure contains information on various types of updatable > > + * firmware images. Each image type then contains an array of image > > + * information per bank. > > + */ > > +struct fwu_image_entry { > > + efi_guid_t image_type_uuid; > > + efi_guid_t location_uuid; > > + struct fwu_image_bank_info img_bank_info[CONFIG_FWU_NUM_BANKS]; > > +}; > > + > > It seems like you've followed the naming proposed in the spec, which makes > reading spec -- code easier. However I feel we should add a few more > comments on the naming to make reading easier or change the naming and > mention the original name in comments. > > A 'bank' is supposed to contain: > bank[0]: Uboot(0), TF-A(0) etc > bank[1]: Uboot(1), TF-A(1) etc > However there's no structure that defines an entire bank. Instead the bank > information is constructed by reading the metadata and fixing it up on > the fly. > > fwu_image_bank_info -- Information for a specific image (e.g OP-TEE, > U-Boot, TF-A, whatever) but not within a *bank*. That's amongst a > collection of images of the same type. > > IOW img_bank_info looks like: > img_bank_info[0] -> U-Boot(0), U-Boot(1) etc > img_bank_info[1] -> TF-A(0), TF-A(1) etc > > @Jose can we tweak the spec naming a bit to be more intuitive? > I am terrible at naming stuff but what about: > fwu_image_bank_info -> fwu_img_repo_info, fwu_img_vault_info, > fwu_img_storage_info, > fwu_img_array_info, > > > > +/** > > + * struct fwu_metadata - Metadata structure for multi-bank updates > > + * @crc32: crc32 value for the metadata > > + * @version: Metadata version > > + * @active_index: Index of the bank currently used for booting images > > + * @previous_active_inde: Index of the bank used before the current bank > > + * being used for booting > > + * @img_entry: Array of information on various firmware images that can > > + * be updated > > + * > > + * This structure is used to store all the needed information for > performing > > + * multi bank updates on the platform. This contains info on the bank > being > > + * used to boot along with the information needed for identification of > > + * individual images > > + */ > > +struct fwu_metadata { > > + u32 crc32; > > + u32 version; > > + u32 active_index; > > + u32 previous_active_index; > > + > > + struct fwu_image_entry img_entry[CONFIG_FWU_NUM_IMAGES_PER_BANK]; > > +}; > > + > > +/** > > + * @get_active_index: get the current active_index value > > + * @update_active_index: update the active_index value > > + * @fill_partition_guid_array: fill the array with guid values of the > > + * partitions found on the storage media > > + * @get_image_alt_num: get the alt number to be used for the image > > + * @metadata_check: check the validity of the metadata partitions > > + * @revert_boot_index: set the active_index to previous_active_index > > + * @set_accept_image: set the accepted bit for the image > > + * @clear_accept_image: clear the accepted bit for the image > > + * @get_metadata() - Get a metadata copy > > + */ > > +struct fwu_metadata_ops { > > + int (*get_active_index)(u32 *active_idx); > > + > > + int (*update_active_index)(u32 active_idx); > > + > > + int (*fill_partition_guid_array)(efi_guid_t **part_guid_arr, > > + u32 *nparts); > > + > > + int (*get_image_alt_num)(efi_guid_t image_type_id, u32 update_bank, > > + int *alt_num); > > + > > + int (*metadata_check)(void); > > + > > + int (*revert_boot_index)(u32 *active_idx); > > + > > + int (*set_accept_image)(efi_guid_t *img_type_id); > > + > > + int (*clear_accept_image)(efi_guid_t *img_type_id, u32 bank); > > + > > + int (*get_metadata)(struct fwu_metadata **metadata); > > +}; > > + > > +#define FWU_METADATA_GUID \ > > + EFI_GUID(0x8a7a84a0, 0x8387, 0x40f6, 0xab, 0x41, \ > > + 0xa8, 0xb9, 0xa5, 0xa6, 0x0d, 0x23) > > + > > +#define FWU_METADATA_VERSION 0x1 > > + > > +extern struct fwu_metadata_ops fwu_gpt_blk_ops; > > + > > +struct fwu_metadata_ops *get_plat_fwu_metadata_ops(void); > > +int fwu_get_active_index(u32 *active_idx); > > +int fwu_update_active_index(u32 active_idx); > > +int fwu_fill_partition_guid_array(efi_guid_t **part_guid_arr, u32 > *nparts); > > +int fwu_get_image_alt_num(efi_guid_t image_type_id, u32 update_bank, > > + int *alt_num); > > +int fwu_metadata_check(void); > > +int fwu_revert_boot_index(u32 *active_idx); > > +int fwu_accept_image(efi_guid_t *img_type_id); > > +int fwu_clear_accept_image(efi_guid_t *img_type_id, u32 bank); > > +int fwu_get_metadata(struct fwu_metadata **metadata); > > + > > +#endif /* _FWU_METADATA_H_ */ > > diff --git a/lib/fwu_updates/fwu_metadata.c > b/lib/fwu_updates/fwu_metadata.c > > new file mode 100644 > > index 0000000000..ebc3eaa04a > > --- /dev/null > > +++ b/lib/fwu_updates/fwu_metadata.c > > @@ -0,0 +1,275 @@ > > +// SPDX-License-Identifier: GPL-2.0+ > > +/* > > + * Copyright (c) 2021, Linaro Limited > > + */ > > + > > +#include > > + > > +#include > > +#include > > + > > +static inline struct fwu_metadata_ops *get_fwu_metadata_ops(void) > > +{ > > + return get_plat_fwu_metadata_ops(); > > +} > > + > > +/** > > + * fwu_get_active_index() - Get active_index from the metadata > > + * @active_idx: active_index value to be read > > + * > > + * Read the active_index field from the metadata and place it in > > + * the variable pointed to be the function argument. > > + * > > + * Return: 0 if OK, -ve on error > > -ve ? > Sorry, I did not get this review comment. The active index is returned back through the function parameter. The return value indicates whether the function is returning the active_index value successfully(0), or if there was an error(-ve) in getting the active_index. > > + * > > + */ > > +int fwu_get_active_index(u32 *active_idx) > > +{ > > + struct fwu_metadata_ops *ops; > > + > > + ops = get_fwu_metadata_ops(); > > On all callsites of get_fwu_metadata_ops() do we need to be that verbose on > the ops missing? If not we can just squeeze in the if > (!ops->XXXXXX) check in get_fwu_metadata_ops() and simply return an error > there. > Okay. Will change. > > > + if (!ops) { > > + log_err("Unable to get fwu ops\n"); > > + return -EPROTONOSUPPORT; > > + } > > + > > + > > + * Return: 0 if OK, -ve on error > > + * > > + */ > > +int fwu_update_active_index(u32 active_idx) > > +{ > > + struct fwu_metadata_ops *ops; > > + > > + ops = get_fwu_metadata_ops(); > > + if (!ops) { > > + log_err("Unable to get fwu ops\n"); > > + return -EPROTONOSUPPORT; > > + } > > + > > + if (!ops->update_active_index) { > > + log_err("update_active_index() method not defined for the > platform\n"); > > + return -ENOSYS; > > + } > > + > > + return ops->update_active_index(active_idx); > > +} > > + > > +/** > > + * fwu_fill_partition_guid_array() - Fill the part_guid_arr array with > the guid's of > > + * the partitions > > + * @part_guid_arr: array of partition guid's > > + * @nparts: Number of gpt partitions on the device > > + * > > + * Get the information on the partition guid's, filling the array with > the guid > > + * values and also the number of partitions. > > + * > > + * Return: 0 if OK, -ve on error > > + * > > + */ > > +int fwu_fill_partition_guid_array(efi_guid_t **part_guid_arr, u32 > *nparts) > > +{ > > + struct fwu_metadata_ops *ops; > > + > > + ops = get_fwu_metadata_ops(); > > + if (!ops) { > > + log_err("Unable to get fwu ops\n"); > > + return -EPROTONOSUPPORT; > > + } > > + > > + if (!ops->fill_partition_guid_array) { > > + log_err("fill_partition_guid_array() method not defined > for the platform\n"); > > + return -ENOSYS; > > + } > > + > > + return ops->fill_partition_guid_array(part_guid_arr, nparts); > > +} > > + > > +/** > > + * fwu_get_image_alt_num() - Get the dfu alt number to be used for > capsule update > > + * @image_type_id: image guid as passed in the capsule > > + * @update_bank: Bank to which the update is to be made > > + * @alt_num: The alt_num for the image > > + * > > + * Based on the guid value passed in the capsule, along with the bank > to which the > > + * image needs to be updated, get the dfu alt number which will be used > for the > > + * capsule update > > + * > > + * Return: 0 if OK, -ve on error > > + * > > + */ > > +int fwu_get_image_alt_num(efi_guid_t image_type_id, u32 update_bank, > > + int *alt_num) > > +{ > > + struct fwu_metadata_ops *ops; > > + > > + ops = get_fwu_metadata_ops(); > > + if (!ops) { > > + log_err("Unable to get fwu ops\n"); > > + return -EPROTONOSUPPORT; > > + } > > + > > + if (!ops->get_image_alt_num) { > > + log_err("get_image_alt_num() method not defined for the > platform\n"); > > + return -ENOSYS; > > + } > > + > > + return ops->get_image_alt_num(image_type_id, update_bank, alt_num); > > +} > > + > > +/** > > + * fwu_metadata_check() - Check if the metadata is valid > > + * > > + * Validate both copies of metadata. If one of the copies > > + * has gone bad, restore it from the other bad copy. > > + * > > + * Return: 0 if OK, -ve on error > > + * > > + */ > > +int fwu_metadata_check(void) > > +{ > > + struct fwu_metadata_ops *ops; > > + > > + ops = get_fwu_metadata_ops(); > > + if (!ops) { > > + log_err("Unable to get fwu ops\n"); > > + return -EPROTONOSUPPORT; > > + } > > + > > + if (!ops->metadata_check) { > > + log_err("metadata_check() method not defined for the > platform\n"); > > + return -ENOSYS; > > + } > > + > > + return ops->metadata_check(); > > +} > > + > > +/** > > + * fwu_revert_boot_index() - Revert the active index in the metadata > > + * @active_idx: Value of the updated active_index > > + * > > + * Revert the active_index value in the metadata, by swapping the values > > + * of active_index and previous_active_index in both copies of the > > + * metadata. > > + * > > + * Return: 0 if OK, -ve on error > > + * > > + */ > > +int fwu_revert_boot_index(u32 *active_idx) > > +{ > > + struct fwu_metadata_ops *ops; > > + > > + ops = get_fwu_metadata_ops(); > > + if (!ops) { > > + log_err("Unable to get fwu ops\n"); > > + return -EPROTONOSUPPORT; > > + } > > + > > + if (!ops->revert_boot_index) { > > + log_err("revert_boot_index() method not defined for the > platform\n"); > > + return -ENOSYS; > > + } > > + > > + return ops->revert_boot_index(active_idx); > > +} > > + > > +/** > > + * fwu_accept_image() - Set the Acceptance bit for the image > > + * @img_type_id: Guid of the image type for which the accepted bit is > to be > > + * cleared > > + * > > + * Set the accepted bit for the image specified by the img_guid > parameter. This > > + * indicates acceptance of image for subsequent boots by some governing > component > > + * like OS(or firmware). > > + * > > + * Return: 0 if OK, -ve on error > > + * > > + */ > > +int fwu_accept_image(efi_guid_t *img_type_id) > > +{ > > + struct fwu_metadata_ops *ops; > > + > > + ops = get_fwu_metadata_ops(); > > + if (!ops) { > > + log_err("Unable to get fwu ops\n"); > > + return -EPROTONOSUPPORT; > > + } > > + > > + if (!ops->set_accept_image) { > > + log_err("set_accept_image() method not defined for the > platform\n"); > > + return -ENOSYS; > > + } > > + > > + return ops->set_accept_image(img_type_id); > > +} > > + > > +/** > > + * fwu_clear_accept_image() - Clear the Acceptance bit for the image > > + * @img_type_id: Guid of the image type for which the accepted bit is > to be > > + * cleared > > + * > > + * Clear the accepted bit for the image type specified by the > img_type_id parameter. > > + * This function is called after the image has been updated. The > accepted bit is > > + * cleared to be set subsequently after passing the image acceptance > criteria, by > > + * either the OS(or firmware) > > + * > > + * Return: 0 if OK, -ve on error > > + * > > + */ > > +int fwu_clear_accept_image(efi_guid_t *img_type_id, u32 bank) > > +{ > > + struct fwu_metadata_ops *ops; > > + > > + ops = get_fwu_metadata_ops(); > > + if (!ops) { > > + log_err("Unable to get fwu ops\n"); > > + return -EPROTONOSUPPORT; > > + } > > + > > + if (!ops->clear_accept_image) { > > + log_err("clear_accept_image() method not defined for the > platform\n"); > > + return -ENOSYS; > > + } > > + > > + return ops->clear_accept_image(img_type_id, bank); > > +} > > + > > +/** > > + * fwu_get_metadata() - Get a metadata copy > > + * @metadata: Copy of the metadata > > + * > > + * Get a valid copy of the metadata. > > + * > > + * Return: 0 if OK, -ve on error > > + * > > + */ > > +int fwu_get_metadata(struct fwu_metadata **metadata) > > +{ > > + struct fwu_metadata_ops *ops; > > + > > + ops = get_fwu_metadata_ops(); > > + if (!ops) { > > + log_err("Unable to get fwu ops\n"); > > + return -EPROTONOSUPPORT; > > + } > > + > > + if (!ops->get_metadata) { > > + log_err("get_metadata() method not defined for the > platform\n"); > > + return -ENOSYS; > > + } > > + > > + return ops->get_metadata(metadata); > > +} > > -- > > 2.17.1 > > > > > Cheers > /Ilias >