board: phytec: k3: Add EFI capsule update support

Implement EFI capsule update functionality for PHYTEC K3-based SoMs.
These SoMs feature various flash device options, including eMMC,
OSPI NOR, and uSD card at the board level.

This update provides the necessary logic to enable EFI capsule updates
across all three flash devices, ensuring flexible and robust firmware
upgrade capabilities.

The GUID is dynamically generated for the board, to get it:

  efidebug capsule esrt
  ========================================
  ESRT: fw_resource_count=3
  ESRT: fw_resource_count_max=3
  ESRT: fw_resource_version=1
  [entry 0]==============================
  ESRT: fw_class=C7D64D6D-10B2-54BC-A3BF-06A9DC3653D9
  ESRT: fw_type=unknown
  ESRT: fw_version=0
  ESRT: lowest_supported_fw_version=0
  ESRT: capsule_flags=0
  ESRT: last_attempt_version=0
  ESRT: last_attempt_status=success
  [entry 1]==============================
  ESRT: fw_class=09841C3F-F177-5D57-B1F6-754D92879205
  ESRT: fw_type=unknown
  ESRT: fw_version=0
  ESRT: lowest_supported_fw_version=0
  ESRT: capsule_flags=0
  ESRT: last_attempt_version=0
  ESRT: last_attempt_status=success
  [entry 2]==============================
  ESRT: fw_class=D11A9016-515E-503A-8872-3FF65384D0C4
  ESRT: fw_type=unknown
  ESRT: fw_version=0
  ESRT: lowest_supported_fw_version=0
  ESRT: capsule_flags=0
  ESRT: last_attempt_version=0
  ESRT: last_attempt_status=success
  ========================================

On the board (from uSD card containing capsule binaries at boot):

  load mmc 1:1 $loadaddr tiboot3-capsule.bin
  efidebug capsule update $loadaddr

  load mmc 1:1 $loadaddr tispl-capsule.bin
  efidebug capsule update $loadaddr

  load mmc 1:1 $loadaddr uboot-capsule.bin
  efidebug capsule update $loadaddr

The binaries will be flashed to the flash device you are booted from.

Signed-off-by: Wadim Egorov <w.egorov@phytec.de>
This commit is contained in:
Wadim Egorov 2024-11-27 13:17:35 +01:00 committed by Tom Rini
parent 2cac36430e
commit f9fc0b7a2e
3 changed files with 88 additions and 0 deletions

View file

@ -4,15 +4,92 @@
* Author: Wadim Egorov <w.egorov@phytec.de>
*/
#include <efi_loader.h>
#include <env_internal.h>
#include <fdt_support.h>
#include <dm/ofnode.h>
#include <mtd.h>
#include <spl.h>
#include <malloc.h>
#include <asm/arch/hardware.h>
#include "../am6_som_detection.h"
#if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT)
struct efi_fw_image fw_images[] = {
{
.fw_name = PHYCORE_AM6XX_FW_NAME_TIBOOT3,
.image_index = 1,
},
{
.fw_name = PHYCORE_AM6XX_FW_NAME_SPL,
.image_index = 2,
},
{
.fw_name = PHYCORE_AM6XX_FW_NAME_UBOOT,
.image_index = 3,
}
};
struct efi_capsule_update_info update_info = {
.dfu_string = NULL,
.num_images = ARRAY_SIZE(fw_images),
.images = fw_images,
};
/**
* configure_capsule_updates() - Set up the DFU string for capsule updates
*
* Configures all three bootloader binaries for updates on the current
* booted flash device, which may be eMMC, OSPI NOR, or a uSD card. If
* booting from USB or Serial, capsule updates will be performed on the
* eMMC device.
*
* Note: Currently, eMMC hardware partitions are not differentiated; Updates
* are always applied to the first boot partition.
*/
void configure_capsule_updates(void)
{
static char dfu_string[128] = { 0 };
const char *dfu_raw = "tiboot3.bin raw 0x0 0x400 mmcpart 1;"
"tispl.bin raw 0x400 0x1000 mmcpart 1;"
"u-boot.img.raw raw 0x1400 0x2000 mmcpart 1";
const char *dfu_fat = "tiboot3.bin fat 1 1;"
"tispl.bin fat 1 1;"
"u-boot.img fat 1 1";
const char *dfu_spi = "tiboot3.bin part 1;"
"tispl.bin part 2;"
"u-boot.img part 3";
u32 boot_device = get_boot_device();
switch (boot_device) {
case BOOT_DEVICE_MMC1:
snprintf(dfu_string, 128, "mmc 0=%s", dfu_raw);
break;
case BOOT_DEVICE_MMC2:
snprintf(dfu_string, 128, "mmc 1=%s", dfu_fat);
break;
case BOOT_DEVICE_SPI:
mtd_probe_devices();
snprintf(dfu_string, 128, "mtd nor0=%s", dfu_spi);
break;
default:
snprintf(dfu_string, 128, "mmc 0=%s", dfu_raw);
break;
};
update_info.dfu_string = dfu_string;
}
#endif
#if IS_ENABLED(CONFIG_SET_DFU_ALT_INFO)
void set_dfu_alt_info(char *interface, char *devstr)
{
if (IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT))
env_set("dfu_alt_info", update_info.dfu_string);
}
#endif
#if IS_ENABLED(CONFIG_ENV_IS_IN_FAT) || IS_ENABLED(CONFIG_ENV_IS_IN_MMC)
int mmc_get_env_dev(void)
{
@ -94,6 +171,9 @@ int board_late_init(void)
}
}
if (IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT))
configure_capsule_updates();
return 0;
}
#endif

View file

@ -12,4 +12,8 @@
/* DDR Configuration */
#define CFG_SYS_SDRAM_BASE 0x80000000
#define PHYCORE_AM6XX_FW_NAME_TIBOOT3 u"PHYCORE_AM62X_TIBOOT3"
#define PHYCORE_AM6XX_FW_NAME_SPL u"PHYCORE_AM62X_SPL"
#define PHYCORE_AM6XX_FW_NAME_UBOOT u"PHYCORE_AM62X_UBOOT"
#endif /* __PHYCORE_AM62X_H */

View file

@ -12,4 +12,8 @@
/* DDR Configuration */
#define CFG_SYS_SDRAM_BASE 0x80000000
#define PHYCORE_AM6XX_FW_NAME_TIBOOT3 u"PHYCORE_AM64X_TIBOOT3"
#define PHYCORE_AM6XX_FW_NAME_SPL u"PHYCORE_AM64X_SPL"
#define PHYCORE_AM6XX_FW_NAME_UBOOT u"PHYCORE_AM64X_UBOOT"
#endif /* __PHYCORE_AM64X_H */