[PATCH 06/10] board: samsung: e850-96: Extract device info from fw loading code
Sam Protsenko
semen.protsenko at linaro.org
Thu Aug 7 00:27:06 CEST 2025
Make it possible to provide the information about storage device where
LDFW firmware resides to the firmware loading routine. The firmware
loader code shouldn't have that data hard-coded anyway, and it also
allows for implementing more dynamic behavior later, like choosing the
storage device containing LDFW via some environment variables.
No functional change.
Signed-off-by: Sam Protsenko <semen.protsenko at linaro.org>
---
board/samsung/e850-96/e850-96.c | 9 ++++++-
board/samsung/e850-96/fw.c | 45 ++++++++++++++++++++-------------
board/samsung/e850-96/fw.h | 4 ++-
3 files changed, 38 insertions(+), 20 deletions(-)
diff --git a/board/samsung/e850-96/e850-96.c b/board/samsung/e850-96/e850-96.c
index 2cf874fcf7a5..b5f6ba23432e 100644
--- a/board/samsung/e850-96/e850-96.c
+++ b/board/samsung/e850-96/e850-96.c
@@ -24,6 +24,12 @@
#define EXYNOS850_APM_SHMEM_OFFSET 0x3200
#define EXYNOS850_IPC_AP_I3C 10
+/* LDFW firmware definitions */
+#define LDFW_NWD_ADDR 0x88000000
+#define EMMC_IFNAME "mmc"
+#define EMMC_DEV_NUM 0
+#define EMMC_ESP_PART 1
+
struct efi_fw_image fw_images[] = {
{
.image_type_id = E850_96_FWBL1_IMAGE_GUID,
@@ -141,7 +147,8 @@ int board_late_init(void)
* Do this in board_late_init() to make sure MMC is not probed before
* efi_init_early().
*/
- err = load_ldfw();
+ err = load_ldfw(EMMC_IFNAME, EMMC_DEV_NUM, EMMC_ESP_PART,
+ LDFW_NWD_ADDR);
if (err)
printf("ERROR: LDFW loading failed (%d)\n", err);
diff --git a/board/samsung/e850-96/fw.c b/board/samsung/e850-96/fw.c
index 8f64e759b431..64235c01a254 100644
--- a/board/samsung/e850-96/fw.c
+++ b/board/samsung/e850-96/fw.c
@@ -11,13 +11,9 @@
#include <linux/arm-smccc.h>
#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"
-#define LDFW_NWD_ADDR 0x88000000
#define LDFW_MAGIC 0x10adab1e
#define SMC_CMD_LOAD_LDFW -0x500
#define SDM_HW_RESET_STATUS 0x1230
@@ -39,19 +35,23 @@ struct ldfw_header {
};
/* Load LDFW binary as a file from FAT partition */
-static int read_fw_from_fat(const char *part_name, const char *path, void *buf)
+static int read_fw_from_fat(const char *ifname, int dev, int part,
+ const char *path, void *buf)
{
- char dev_part_str[8];
+ struct blk_desc *blk_desc;
loff_t len_read;
int err;
- snprintf(dev_part_str, sizeof(dev_part_str), "%d#%s", EMMC_DEV_NUM,
- LDFW_FAT_PART);
+ blk_desc = blk_get_dev(ifname, dev);
+ if (!blk_desc) {
+ debug("%s: Can't get block device\n", __func__);
+ return -ENODEV;
+ }
- err = fs_set_blk_dev(EMMC_IFACE, dev_part_str, FS_TYPE_FAT);
+ err = fs_set_blk_dev_with_part(blk_desc, part);
if (err) {
- debug("%s: Can't set block device\n", __func__);
- return -ENODEV;
+ debug("%s: Can't set partition\n", __func__);
+ return -ENOENT;
}
err = fs_read(path, (ulong)buf, 0, 0, &len_read);
@@ -64,16 +64,17 @@ static int read_fw_from_fat(const char *part_name, const char *path, void *buf)
}
/* Load LDFW binary from raw partition on block device into RAM buffer */
-static int read_fw_from_raw(const char *part_name, void *buf)
+static int read_fw_from_raw(const char *ifname, int dev, const char *part_name,
+ void *buf)
{
struct blk_desc *blk_desc;
struct disk_partition part;
unsigned long cnt;
int part_num;
- blk_desc = blk_get_dev(EMMC_IFACE, EMMC_DEV_NUM);
+ blk_desc = blk_get_dev(ifname, dev);
if (!blk_desc) {
- debug("%s: Can't get eMMC device\n", __func__);
+ debug("%s: Can't get block device\n", __func__);
return -ENODEV;
}
@@ -92,9 +93,17 @@ static int read_fw_from_raw(const char *part_name, void *buf)
return 0;
}
-int load_ldfw(void)
+/**
+ * load_ldfw - Load the loadable firmware (LDFW)
+ * @ifname: Interface name of the block device to load the firmware from
+ * @dev: Device number
+ * @part: Partition number
+ * @addr: Temporary memory (Normal World) to use for loading the firmware
+ *
+ * Return: 0 on success or a negative value on error.
+ */
+int load_ldfw(const char *ifname, int dev, int part, phys_addr_t addr)
{
- const phys_addr_t addr = (phys_addr_t)LDFW_NWD_ADDR;
struct ldfw_header *hdr;
struct arm_smccc_res res;
void *buf = (void *)addr;
@@ -102,9 +111,9 @@ int load_ldfw(void)
int err, i;
/* 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);
+ err = read_fw_from_fat(ifname, dev, part, LDFW_FAT_PATH, buf);
if (err) {
- err = read_fw_from_raw(LDFW_RAW_PART, buf);
+ err = read_fw_from_raw(ifname, dev, LDFW_RAW_PART, buf);
if (err)
return err;
}
diff --git a/board/samsung/e850-96/fw.h b/board/samsung/e850-96/fw.h
index 472664e4ed21..73d9615d4a9c 100644
--- a/board/samsung/e850-96/fw.h
+++ b/board/samsung/e850-96/fw.h
@@ -7,6 +7,8 @@
#ifndef __E850_96_FW_H
#define __E850_96_FW_H
-int load_ldfw(void);
+#include <asm/types.h>
+
+int load_ldfw(const char *ifname, int dev, int part, phys_addr_t addr);
#endif /* __E850_96_FW_H */
--
2.39.5
More information about the U-Boot
mailing list