
On 6/9/22 14:30, Sughosh Ganu wrote:
From: Masami Hiramatsu masami.hiramatsu@linaro.org
Generate dfu_alt_info from the partition uuid information in the devicetree, and record the mapping of partition uuid and the index of dfu_alt_num.
This could be a reference implementation of the automatic DFU generation for FWU multi-bank update for non GPT firmware platforms.
Signed-off-by: Masami Hiramatsu masami.hiramatsu@linaro.org Signed-off-by: Sughosh Ganu sughosh.ganu@linaro.org
.../synquacer-sc2a11-developerbox-u-boot.dtsi | 3 + board/socionext/developerbox/Kconfig | 1 + board/socionext/developerbox/fwu_plat.c | 79 ++++---- include/configs/synquacer.h | 6 +- include/fwu.h | 6 + lib/fwu_updates/Makefile | 1 + lib/fwu_updates/fwu_mtd.c | 173 ++++++++++++++++++ 7 files changed, 221 insertions(+), 48 deletions(-) create mode 100644 lib/fwu_updates/fwu_mtd.c
diff --git a/arch/arm/dts/synquacer-sc2a11-developerbox-u-boot.dtsi b/arch/arm/dts/synquacer-sc2a11-developerbox-u-boot.dtsi index ab4e3d1c2b..c7ec8a0321 100644 --- a/arch/arm/dts/synquacer-sc2a11-developerbox-u-boot.dtsi +++ b/arch/arm/dts/synquacer-sc2a11-developerbox-u-boot.dtsi @@ -36,6 +36,7 @@ compatible = "fixed-partitions"; #address-cells = <1>; #size-cells = <1>;
uuid = "17e86d77-41f9-4fd7-87ec-a55df9842de5"; partition@0 { label = "BootStrap-BL1";
@@ -88,10 +89,12 @@ partition@600000 { label = "FIP-Bank0"; reg = <0x600000 0x400000>;
uuid = "5a66a702-99fd-4fef-a392-c26e261a2828"; }; partition@a00000 { label = "FIP-Bank1"; reg = <0xa00000 0x400000>;
};uuid = "a8f868a1-6e5c-4757-878d-ce63375ef2c0"; }; };
diff --git a/board/socionext/developerbox/Kconfig b/board/socionext/developerbox/Kconfig index 7df6750baf..ad2a284f13 100644 --- a/board/socionext/developerbox/Kconfig +++ b/board/socionext/developerbox/Kconfig @@ -38,6 +38,7 @@ config FWU_MULTI_BANK_UPDATE select DM_SPI_FLASH select DM_FWU_MDATA select BOARD_LATE_INIT
select SET_DFU_ALT_INFO
config FWU_NUM_BANKS default 2
diff --git a/board/socionext/developerbox/fwu_plat.c b/board/socionext/developerbox/fwu_plat.c index fd6d0e3659..ff06eade7d 100644 --- a/board/socionext/developerbox/fwu_plat.c +++ b/board/socionext/developerbox/fwu_plat.c @@ -10,8 +10,10 @@ #include <fwu_mdata.h> #include <malloc.h> #include <memalign.h> +#include <mtd.h> #include <spi.h> #include <spi_flash.h> +#include <uuid.h>
#include <linux/errno.h> #include <linux/types.h> @@ -94,6 +96,36 @@ static int sf_save_data(u32 offs, u32 size, void *data) return ret; }
+#define DFU_ALT_BUF_LEN 256 +#define DFU_ALT_NUM_MAX (CONFIG_FWU_NUM_IMAGES_PER_BANK * CONFIG_FWU_NUM_BANKS)
+/* Generate dfu_alt_info from partitions */ +void set_dfu_alt_info(char *interface, char *devstr) +{
- int ret;
- struct mtd_info *mtd;
- static char *buf = NULL;
- if (!buf) {
buf = malloc_cache_aligned(DFU_ALT_BUF_LEN);
memset(buf, 0, DFU_ALT_BUF_LEN);
mtd_probe_devices();
mtd = get_mtd_device_nm("nor1");
if (IS_ERR_OR_NULL(mtd))
return;
ret = fwu_gen_alt_info_from_mtd(buf, DFU_ALT_BUF_LEN, mtd);
if (ret < 0) {
log_err("Error: Failed to generate dfu_alt_info. (%d)\n", ret);
return;
}
log_debug("Make dfu_alt_info: '%s'\n", buf);
- }
- env_set("dfu_alt_info", buf);
+}
- #define PLAT_METADATA_OFFSET 0x510000 #define PLAT_METADATA_SIZE (sizeof(struct devbox_metadata))
@@ -105,49 +137,7 @@ struct __packed devbox_metadata { int fwu_plat_get_alt_num(struct udevice __always_unused *dev, efi_guid_t *image_id, int *alt_num) {
- struct fwu_image_bank_info *bank;
- struct fwu_mdata *mdata;
- int i, ret;
- ret = fwu_get_mdata(&mdata);
- if (ret < 0)
return ret;
- /*
* DeveloperBox FWU expects Bank:Image = 1:1, and the dfu_alt_info
* only has the entries for banks. Thus the alt_no should be equal
* to the bank index number.
*/
- ret = -ENOENT;
- for (i = 0; i < CONFIG_FWU_NUM_BANKS; i++) {
bank = &mdata->img_entry[0].img_bank_info[i];
if (guidcmp(image_id, &bank->image_uuid) == 0) {
*alt_num = i;
ret = 0;
break;
}
- }
- free(mdata);
- return ret;
-}
-/* This assumes that user doesn't change system default dfu_alt_info */ -efi_status_t fill_image_type_guid_array(const efi_guid_t __always_unused
*default_guid,
efi_guid_t **part_guid_arr)
-{
- int i;
- *part_guid_arr = malloc(sizeof(efi_guid_t) * DEFAULT_DFU_ALT_NUM);
- if (!*part_guid_arr)
return EFI_OUT_OF_RESOURCES;
- for (i = 0; i < DEFAULT_DFU_ALT_NUM; i++)
guidcpy((*part_guid_arr + i), &devbox_fip_image_type_guid);
- return EFI_SUCCESS;
return fwu_get_mtd_alt_num(image_id, alt_num, "nor1", 0); }
int fwu_plat_get_update_index(u32 *update_idx)
@@ -188,6 +178,9 @@ int board_late_init(void) { int ret;
- /* Make mmc available for EFI */
- run_command("mmc dev 0", 0);
What is this for?
And I can't see any single note about in commit message.
Thanks, Michal