board: samsung: e850-96: Split LDFW loading and init
authorSam Protsenko <semen.protsenko@linaro.org>
Tue, 18 Nov 2025 23:21:16 +0000 (17:21 -0600)
committerMinkyu Kang <mk7.kang@samsung.com>
Wed, 26 Nov 2025 08:55:57 +0000 (17:55 +0900)
The LDFW firmware loading is done in two steps:

  1. Read the firmware binary from some block device
  2. Provide it to EL3 monitor software via an SMC call, so it can copy
     it to a Secure World memory and start using it

Let's split the load_ldfw() function by two functions correspondingly,
to reflect that process better:

  - load_ldfw_from_blk()
  - init_ldfw()

It can be useful in case when the LDFW binary should be obtained from
some different media, e.g. downloaded over USB during USB boot.

No functional change.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>
board/samsung/e850-96/e850-96.c
board/samsung/e850-96/fw.c
board/samsung/e850-96/fw.h

index 34e0191..3cf98a0 100644 (file)
@@ -151,9 +151,14 @@ void load_firmware(void)
        }
 
        printf("Loading LDFW firmware (from %s %ld)...\n", ifname, dev);
-       err = load_ldfw(ifname, dev, part, LDFW_NWD_ADDR);
-       if (err)
+       err = load_ldfw_from_blk(ifname, dev, part, LDFW_NWD_ADDR);
+       if (err) {
                printf("ERROR: LDFW loading failed (%d)\n", err);
+               return;
+       }
+       err = init_ldfw(LDFW_NWD_ADDR);
+       if (err)
+               printf("ERROR: LDFW init failed (%d)\n", err);
 }
 
 int dram_init(void)
index 64235c0..2d52433 100644 (file)
@@ -94,7 +94,7 @@ static int read_fw_from_raw(const char *ifname, int dev, const char *part_name,
 }
 
 /**
- * load_ldfw - Load the loadable firmware (LDFW)
+ * load_ldfw_from_blk - Load the loadable firmware (LDFW) from block device
  * @ifname: Interface name of the block device to load the firmware from
  * @dev: Device number
  * @part: Partition number
@@ -102,24 +102,37 @@ static int read_fw_from_raw(const char *ifname, int dev, const char *part_name,
  *
  * Return: 0 on success or a negative value on error.
  */
-int load_ldfw(const char *ifname, int dev, int part, phys_addr_t addr)
+int load_ldfw_from_blk(const char *ifname, int dev, int part, phys_addr_t addr)
 {
-       struct ldfw_header *hdr;
-       struct arm_smccc_res res;
        void *buf = (void *)addr;
-       u64 size = 0;
-       int err, i;
+       int err;
 
        /* First try to read LDFW from EFI partition, then from the raw one */
        err = read_fw_from_fat(ifname, dev, part, LDFW_FAT_PATH, buf);
-       if (err) {
-               err = read_fw_from_raw(ifname, dev, LDFW_RAW_PART, buf);
-               if (err)
-                       return err;
-       }
+       if (err)
+               return read_fw_from_raw(ifname, dev, LDFW_RAW_PART, buf);
+
+       return 0;
+}
+
+/**
+ * init_ldfw - Provide the LDFW (loaded to RAM) to EL3 monitor to make use of it
+ * @addr: Memory address where LDFW resides
+ *
+ * EL3 monitor will copy the LDFW from the provided Normal World memory @addr to
+ * Secure World location, and start using it.
+ *
+ * Return: 0 on success or a negative value on error.
+ */
+int init_ldfw(phys_addr_t addr)
+{
+       struct ldfw_header *hdr;
+       struct arm_smccc_res res;
+       u64 size = 0;
+       int err, i;
 
        /* Validate LDFW by magic number in its header */
-       hdr = buf;
+       hdr = (struct ldfw_header *)addr;
        if (hdr->magic != LDFW_MAGIC) {
                debug("%s: Wrong LDFW magic; is LDFW flashed?\n", __func__);
                return -EINVAL;
index 73d9615..b061abc 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <asm/types.h>
 
-int load_ldfw(const char *ifname, int dev, int part, phys_addr_t addr);
+int load_ldfw_from_blk(const char *ifname, int dev, int part, phys_addr_t addr);
+int init_ldfw(phys_addr_t addr);
 
 #endif /* __E850_96_FW_H */