From 4f1dc6f1e1d2747ba93adb2e66cefaca589be9d7 Mon Sep 17 00:00:00 2001 From: Sam Protsenko Date: Thu, 16 Jan 2025 17:01:24 -0600 Subject: configs: e850-96: Enable options for updated env The E850-96 default environment is going to be updated soon, requiring next config options to be enabled: - CONFIG_DEFAULT_FDT_FILE: $fdtfile will use this value - CONFIG_PARTITION_TYPE_GUID: $partitions will rely on "type" feature Signed-off-by: Sam Protsenko Signed-off-by: Minkyu Kang --- configs/e850-96_defconfig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/configs/e850-96_defconfig b/configs/e850-96_defconfig index c36196c510c..b1b3510d691 100644 --- a/configs/e850-96_defconfig +++ b/configs/e850-96_defconfig @@ -13,6 +13,7 @@ CONFIG_SYS_LOAD_ADDR=0x80000000 # CONFIG_PSCI_RESET is not set CONFIG_ANDROID_BOOT_IMAGE=y # CONFIG_AUTOBOOT is not set +CONFIG_DEFAULT_FDT_FILE="exynos850-e850-96.dtb" # CONFIG_DISPLAY_CPUINFO is not set CONFIG_HUSH_PARSER=y CONFIG_CMD_ABOOTIMG=y @@ -22,6 +23,7 @@ CONFIG_CMD_MMC=y CONFIG_CMD_PART=y CONFIG_CMD_TIME=y CONFIG_CMD_RNG=y +CONFIG_PARTITION_TYPE_GUID=y CONFIG_NO_NET=y CONFIG_CLK_EXYNOS850=y CONFIG_MMC_DW=y -- cgit v1.2.3 From 5af19ede0d52139b5acb996fd3c660d8fb118aab Mon Sep 17 00:00:00 2001 From: Sam Protsenko Date: Thu, 16 Jan 2025 17:01:25 -0600 Subject: configs: e850-96: Enable U-Boot environment on eMMC Store U-Boot environment in BOOT2 HW area of eMMC (/dev/mmcblk0boot1), as it's currently unused. BOOT1 area will be probably used for storing low-level bootloaders further, so let's not touch it. Both primary and redundant environments work fine: => env default -f -a ## Resetting to default environment => env save Saving Environment to MMC... Writing to redundant MMC(0)... OK Signed-off-by: Sam Protsenko Signed-off-by: Minkyu Kang --- configs/e850-96_defconfig | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/configs/e850-96_defconfig b/configs/e850-96_defconfig index b1b3510d691..d287018ec63 100644 --- a/configs/e850-96_defconfig +++ b/configs/e850-96_defconfig @@ -8,8 +8,11 @@ CONFIG_SYS_MALLOC_F_LEN=0x4000 CONFIG_ARCH_EXYNOS9=y CONFIG_HAS_CUSTOM_SYS_INIT_SP_ADDR=y CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0xf8c00000 +CONFIG_ENV_SIZE=0x10000 +CONFIG_ENV_OFFSET=0x0 CONFIG_DEFAULT_DEVICE_TREE="exynos/exynos850-e850-96" CONFIG_SYS_LOAD_ADDR=0x80000000 +CONFIG_ENV_OFFSET_REDUND=0x10000 # CONFIG_PSCI_RESET is not set CONFIG_ANDROID_BOOT_IMAGE=y # CONFIG_AUTOBOOT is not set @@ -24,8 +27,14 @@ CONFIG_CMD_PART=y CONFIG_CMD_TIME=y CONFIG_CMD_RNG=y CONFIG_PARTITION_TYPE_GUID=y +CONFIG_ENV_OVERWRITE=y +CONFIG_ENV_IS_IN_MMC=y +CONFIG_SYS_REDUNDAND_ENVIRONMENT=y +CONFIG_SYS_RELOC_GD_ENV_ADDR=y +CONFIG_SYS_MMC_ENV_PART=2 CONFIG_NO_NET=y CONFIG_CLK_EXYNOS850=y +CONFIG_SUPPORT_EMMC_BOOT=y CONFIG_MMC_DW=y CONFIG_SOC_SAMSUNG=y CONFIG_EXYNOS_PMU=y -- cgit v1.2.3 From 922c68563a21b0b5dd37774f1ccc4b2c4658e9f0 Mon Sep 17 00:00:00 2001 From: Sam Protsenko Date: Thu, 16 Jan 2025 17:01:26 -0600 Subject: configs: e850-96: Enable more EFI features The basic EFI support is already enabled by EFI_LOADER. Follow SystemReady IR recommendations [1,2] for U-Boot and enable support for more EFI features. That includes: - CONFIG_CMD_BOOTEFI_SELFTEST: support for "bootefi selftest" command - CONFIG_CMD_NVEDIT_EFI: support for "env -e" to explore EFI vars - CONFIG_CMD_EFIDEBUG: support for "efidebug" command Also enable RTC support: - CONFIG_EFI_SET_TIME - CONFIG_CMD_RTC - CONFIG_DM_RTC - CONFIG_RTC_EMULATION [1] https://developer.arm.com/documentation/DUI1101/1-1/Configure-U-Boot-for-SystemReady [2] https://developer.arm.com/documentation/DUI1101/1-1/Test-SystemReady-IR Signed-off-by: Sam Protsenko Reviewed-by: Ilias Apalodimas Signed-off-by: Minkyu Kang --- configs/e850-96_defconfig | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/configs/e850-96_defconfig b/configs/e850-96_defconfig index d287018ec63..1cae252175b 100644 --- a/configs/e850-96_defconfig +++ b/configs/e850-96_defconfig @@ -14,16 +14,22 @@ CONFIG_DEFAULT_DEVICE_TREE="exynos/exynos850-e850-96" CONFIG_SYS_LOAD_ADDR=0x80000000 CONFIG_ENV_OFFSET_REDUND=0x10000 # CONFIG_PSCI_RESET is not set +CONFIG_EFI_SET_TIME=y CONFIG_ANDROID_BOOT_IMAGE=y # CONFIG_AUTOBOOT is not set CONFIG_DEFAULT_FDT_FILE="exynos850-e850-96.dtb" # CONFIG_DISPLAY_CPUINFO is not set CONFIG_HUSH_PARSER=y +CONFIG_CMD_BOOTEFI_SELFTEST=y CONFIG_CMD_ABOOTIMG=y +CONFIG_CMD_NVEDIT_EFI=y CONFIG_CMD_CLK=y CONFIG_CMD_GPT=y CONFIG_CMD_MMC=y CONFIG_CMD_PART=y +CONFIG_CMD_EFIDEBUG=y +# CONFIG_CMD_DATE is not set +CONFIG_CMD_RTC=y CONFIG_CMD_TIME=y CONFIG_CMD_RNG=y CONFIG_PARTITION_TYPE_GUID=y @@ -36,6 +42,8 @@ CONFIG_NO_NET=y CONFIG_CLK_EXYNOS850=y CONFIG_SUPPORT_EMMC_BOOT=y CONFIG_MMC_DW=y +CONFIG_DM_RTC=y +CONFIG_RTC_EMULATION=y CONFIG_SOC_SAMSUNG=y CONFIG_EXYNOS_PMU=y CONFIG_EXYNOS_USI=y -- cgit v1.2.3 From 30404063281e08e9faaa125d2aa09db2beee408d Mon Sep 17 00:00:00 2001 From: Sam Protsenko Date: Thu, 16 Jan 2025 17:01:27 -0600 Subject: configs: e850-96: Enable Standard Boot Enable Standard Boot on E850-96 as documented in [1]. Along with corresponding changes in the default environment and properly prepared eMMC partitions (ESP and rootfs), it makes it possible to boot Debian rootfs automatically. All boot methods were tested: efi_mgr, efi, syslinux and script. The preferred boot method is efi_mgr, which relies on the configured EFI variables (stored in /ubootefi.var file on ESP partition), which boots either GRUB from /EFI/debian/grubaa64.efi, or systemd-boot from /EFI/BOOT/BOOTAA64.EFI. Currently used boot sequence: U-Boot -> bootcmd -> 'bootflow scan -lb' -> efi_mgr -> GRUB -> Debian [1] doc/develop/bootstd/overview.rst Signed-off-by: Sam Protsenko Signed-off-by: Minkyu Kang --- configs/e850-96_defconfig | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/configs/e850-96_defconfig b/configs/e850-96_defconfig index 1cae252175b..5facd418260 100644 --- a/configs/e850-96_defconfig +++ b/configs/e850-96_defconfig @@ -16,17 +16,15 @@ CONFIG_ENV_OFFSET_REDUND=0x10000 # CONFIG_PSCI_RESET is not set CONFIG_EFI_SET_TIME=y CONFIG_ANDROID_BOOT_IMAGE=y -# CONFIG_AUTOBOOT is not set +CONFIG_BOOTSTD_FULL=y CONFIG_DEFAULT_FDT_FILE="exynos850-e850-96.dtb" # CONFIG_DISPLAY_CPUINFO is not set -CONFIG_HUSH_PARSER=y CONFIG_CMD_BOOTEFI_SELFTEST=y CONFIG_CMD_ABOOTIMG=y CONFIG_CMD_NVEDIT_EFI=y CONFIG_CMD_CLK=y CONFIG_CMD_GPT=y CONFIG_CMD_MMC=y -CONFIG_CMD_PART=y CONFIG_CMD_EFIDEBUG=y # CONFIG_CMD_DATE is not set CONFIG_CMD_RTC=y -- cgit v1.2.3 From 4d8ccb938d580638aac48d0e432d6699ed3cc4b8 Mon Sep 17 00:00:00 2001 From: Sam Protsenko Date: Thu, 16 Jan 2025 17:01:28 -0600 Subject: board: samsung: e850-96: Load LDFW from EFI partition In case when EFI System Partition is present it can be used to store firmware binaries, instead of keeping those on separate dedicated partitions. That simplifies the partition table and makes it more standard. Rework the firmware loader code to look for LDFW binary at /EFI/firmware/ldfw.bin on ESP first, and if either the partition or the file doesn't exist -- fallback to reading it from 'ldfw' partition. This way backward compatibility can be kept, and Android partition tables without ESP partition can be handled too. Signed-off-by: Sam Protsenko Signed-off-by: Minkyu Kang --- board/samsung/e850-96/fw.c | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/board/samsung/e850-96/fw.c b/board/samsung/e850-96/fw.c index 82a0b224c67..8f64e759b43 100644 --- a/board/samsung/e850-96/fw.c +++ b/board/samsung/e850-96/fw.c @@ -7,14 +7,16 @@ */ #include +#include #include #include "fw.h" #define EMMC_IFACE "mmc" #define EMMC_DEV_NUM 0 +#define LDFW_RAW_PART "ldfw" +#define LDFW_FAT_PART "esp" +#define LDFW_FAT_PATH "/EFI/firmware/ldfw.bin" -/* LDFW constants */ -#define LDFW_PART_NAME "ldfw" #define LDFW_NWD_ADDR 0x88000000 #define LDFW_MAGIC 0x10adab1e #define SMC_CMD_LOAD_LDFW -0x500 @@ -36,7 +38,33 @@ struct ldfw_header { char fw_name[16]; }; -static int read_fw(const char *part_name, void *buf) +/* Load LDFW binary as a file from FAT partition */ +static int read_fw_from_fat(const char *part_name, const char *path, void *buf) +{ + char dev_part_str[8]; + loff_t len_read; + int err; + + snprintf(dev_part_str, sizeof(dev_part_str), "%d#%s", EMMC_DEV_NUM, + LDFW_FAT_PART); + + err = fs_set_blk_dev(EMMC_IFACE, dev_part_str, FS_TYPE_FAT); + if (err) { + debug("%s: Can't set block device\n", __func__); + return -ENODEV; + } + + err = fs_read(path, (ulong)buf, 0, 0, &len_read); + if (err) { + debug("%s: Can't read LDFW file\n", __func__); + return -EIO; + } + + return 0; +} + +/* Load LDFW binary from raw partition on block device into RAM buffer */ +static int read_fw_from_raw(const char *part_name, void *buf) { struct blk_desc *blk_desc; struct disk_partition part; @@ -73,10 +101,13 @@ int load_ldfw(void) u64 size = 0; int err, i; - /* Load LDFW from the block device partition into RAM buffer */ - err = read_fw(LDFW_PART_NAME, buf); - if (err) - return err; + /* First try to read LDFW from EFI partition, then from the raw one */ + err = read_fw_from_fat(LDFW_FAT_PART, LDFW_FAT_PATH, buf); + if (err) { + err = read_fw_from_raw(LDFW_RAW_PART, buf); + if (err) + return err; + } /* Validate LDFW by magic number in its header */ hdr = buf; -- cgit v1.2.3 From ccfd8de541a8ab329e575648dabb934572d55fe6 Mon Sep 17 00:00:00 2001 From: Sam Protsenko Date: Thu, 16 Jan 2025 17:01:29 -0600 Subject: board: samsung: e850-96: Report LDFW loading failures LDFW firmware loading can fail, e.g. in case if user forgot to upload the binary to the appropriate location (/EFI/firmware/ldfw.bin on ESP partition). Report such errors explicitly, so that the user can notice it early and take necessary actions. But don't return error code from board_init() in this case, as LDFW firmware is not mandatory for board operation and is only required for some features like TRNG. Signed-off-by: Sam Protsenko Signed-off-by: Minkyu Kang --- board/samsung/e850-96/e850-96.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/board/samsung/e850-96/e850-96.c b/board/samsung/e850-96/e850-96.c index c5cef6f19d2..0bef68d2fb2 100644 --- a/board/samsung/e850-96/e850-96.c +++ b/board/samsung/e850-96/e850-96.c @@ -19,6 +19,11 @@ int dram_init_banksize(void) int board_init(void) { - load_ldfw(); + int err; + + err = load_ldfw(); + if (err) + printf("ERROR: LDFW loading failed (%d)\n", err); + return 0; } -- cgit v1.2.3 From 16218681a5407c1973b3009f21b010a1c09b212e Mon Sep 17 00:00:00 2001 From: Sam Protsenko Date: Thu, 16 Jan 2025 17:01:30 -0600 Subject: board: samsung: e850-96: Provide bootstd default env Add default environment variables needed for Standard Boot enablement as described in [1]. Also rework the eMMC partition table for Linux boot so it only has two partitions: 1. EFI System Partition (EFI vars, GRUB efi app, firmware files) 2. rootfs partition (Debian rootfs, /boot, extlinux.conf, boot.scr) Both partitions are made bootable so that 'bootflow' command can detect all loader files (rootfs might contain extlinux.conf and boot.scr). 'ldfw' partition is removed too, as ldfw.bin can be loaded from ESP now (from /EFI/firmware/ldfw.bin). Android partitons will be added later, once Android boot is actually enabled for E850-96. Notes: - $kernel_comp_addr_r uses the same address (0x88000000) as LDFW buffer (in board/samsung/e850-96/fw.c), but that's fine, as LDFW will be copied to another RAM location (Secure World) by SMC command, so it's only used temporarily on startup - addition assignment (+=) operation is used for $partitions to avoid spaces added by newlines, so that $partitions can be used in the shell with no quotes Now it's possible to successfully automatically boot Debian rootfs: => env default -f -a => env save => gpt write mmc 0 $partitions => reset [1] doc/develop/bootstd/overview.rst Signed-off-by: Sam Protsenko Signed-off-by: Minkyu Kang --- board/samsung/e850-96/e850-96.env | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/board/samsung/e850-96/e850-96.env b/board/samsung/e850-96/e850-96.env index f36f90be950..5ac76bcef02 100644 --- a/board/samsung/e850-96/e850-96.env +++ b/board/samsung/e850-96/e850-96.env @@ -1,26 +1,11 @@ -partitions= - uuid_disk=${uuid_gpt_disk}; - name=efs,start=512K,size=20M,uuid=${uuid_gpt_efs}; - name=env,size=16K,uuid=${uuid_gpt_env}; - name=kernel,size=30M,uuid=${uuid_gpt_kernel}; - name=ramdisk,size=26M,uuid=${uuid_gpt_ramdisk}; - name=dtbo,size=1M,uuid=${uuid_gpt_dtbo}; - name=ldfw,size=4016K,uuid=${uuid_gpt_ldfw}; - name=keystorage,size=8K,uuid=${uuid_gpt_keystorage}; - name=tzsw,size=1M,uuid=${uuid_gpt_tzsw}; - name=harx,size=2M,uuid=${uuid_gpt_harx}; - name=harx_rkp,size=2M,uuid=${uuid_gpt_harx_rkp}; - name=logo,size=40M,uuid=${uuid_gpt_logo}; - name=super,size=3600M,uuid=${uuid_gpt_super}; - name=cache,size=300M,uuid=${uuid_gpt_cache}; - name=modem,size=100M,uuid=${uuid_gpt_modem}; - name=boot,size=100M,uuid=${uuid_gpt_boot}; - name=persist,size=30M,uuid=${uuid_gpt_persist}; - name=recovery,size=40M,uuid=${uuid_gpt_recovery}; - name=misc,size=40M,uuid=${uuid_gpt_misc}; - name=mnv,size=20M,uuid=${uuid_gpt_mnv}; - name=frp,size=512K,uuid=${uuid_gpt_frp}; - name=vbmeta,size=64K,uuid=${uuid_gpt_vbmeta}; - name=metadata,size=16M,uuid=${uuid_gpt_metadata}; - name=dtb,size=1M,uuid=${uuid_gpt_dtb}; - name=userdata,size=-,uuid=${uuid_gpt_userdata} +kernel_addr_r=0x80000000 +kernel_comp_addr_r=0x88000000 +kernel_comp_size=0x4000000 +fdt_addr_r=0x8c000000 +scriptaddr=0x8c100000 +pxefile_addr_r=0x8c200000 +ramdisk_addr_r=0x8c300000 +fdtfile=CONFIG_DEFAULT_FDT_FILE + +partitions=name=esp,start=512K,size=128M,bootable,type=system; +partitions+=name=rootfs,size=-,bootable,type=linux -- cgit v1.2.3