Skip to contentSkip to conversation

board: samsung: e850-96: Support USB boot

PATCH Superseded Sam Protsenko 1 participant 7 messages Oct 27, 2025

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover board: samsung: e850-96: Support USB boot

When U-Boot is executed during USB boot [1,2] on E850-96 board, two issues happen:

1. eMMC fails to initialize
2. Attempt to use USB PHY driver leads to abort

It was identified that issue #1 happens due to enalbed Flash Memory Protector bits in MMC block registers during USB boot, and it's handled in patch series [3].

Issue #2 on the other hand happens because ROM code expects the bootloader (U-Boot) to download remaining binaries (LDFW and TZSW) over USB using SMC calls. Before that, the access to USB blocks (USB PHY and DWC3) is disabled, probably because corresponding TrustZone domains are configured for access from Secure World only.

This patch series implements downloading LDFW and TZSW firmware over USB during USB boot, which makes it possible to use U-Boot for flashing images to eMMC using fastboot and DFU protocols. That in turn simplifies the U-Boot development, as one can use `dltool' [1] to run U-Boot binary during USB boot, and update U-Boot on eMMC this way (e.g. using DFU). It's not possible when using LittleKernel bootloader, as it expects non-standard Samsung GPT partition, but in case of U-Boot we use the regular one.

Once this patch series and patch series [3] are applied it'll be possible to use U-Boot during USB boot. The two series are independent of each other, and can be applied in any particular order.

[1] https://gitlab.com/LinaroLtd/e850-96/tools/dltool
[2] https://docs.u-boot.org/en/latest/board/samsung/e850-96.html
[3] https://lore.kernel.org/u-boot/[email protected]/

Sam Protsenko (5):
board: samsung: e850-96: Keep public functions together
board: samsung: e850-96: Add routines for checking boot dev
board: samsung: e850-96: Split LDFW loading and init
board: samsung: e850-96: Add routine for loading images over USB
board: samsung: e850-96: Load firmwares over USB on USB boot

 board/samsung/e850-96/Makefile  |  2 +-
 board/samsung/e850-96/bootdev.c | 99 +++++++++++++++++++++++++++++++++
 board/samsung/e850-96/bootdev.h | 23 ++++++++
 board/samsung/e850-96/e850-96.c | 65 +++++++++++++++++-----
 board/samsung/e850-96/fw.c      | 75 ++++++++++++++++++-------
 board/samsung/e850-96/fw.h      | 10 +++-
 6 files changed, 239 insertions(+), 35 deletions(-)
 create mode 100644 board/samsung/e850-96/bootdev.c
 create mode 100644 board/samsung/e850-96/bootdev.h

base-commit: fd976ff3a233ae7c6a9f5bec790b02bbbf57bb24

Signature · 1 line
2.39.5
#1 lore raw

PATCH 1/5 board: samsung: e850-96: Keep public functions together

Move DRAM init functions close to other public functions, to make things visually distinct and improve the readability.

No functional change.

---
 board/samsung/e850-96/e850-96.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
board/samsung/e850-96/e850-96.c +10 -10
index 3df241edde2a..34e01914032c 100644
@@ -77,16 +77,6 @@ static struct acpm acpm = {
 	.ipc_ch		= EXYNOS850_IPC_AP_I3C,
 };
 
-int dram_init(void)
-{
-	return fdtdec_setup_mem_size_base();
-}
-
-int dram_init_banksize(void)
-{
-	return fdtdec_setup_memory_banksize();
-}
-
 /* Read the unique SoC ID from OTP registers */
 static u64 get_chip_id(void)
 {
@@ -166,6 +156,16 @@ void load_firmware(void)
 		printf("ERROR: LDFW loading failed (%d)\n", err);
 }
 
+int dram_init(void)
+{
+	return fdtdec_setup_mem_size_base();
+}
+
+int dram_init_banksize(void)
+{
+	return fdtdec_setup_memory_banksize();
+}
+
 int board_late_init(void)
 {
 	setup_serial();
Signature · 1 line
2.39.5
#2 lore raw

PATCH 2/5 board: samsung: e850-96: Add routines for checking boot dev

In reply to Sam Protsenko

Implement functionality to check the current boot device (a device where the SoC ROM code is loading the bootloaders from). The boot device order can be changed using the SW1 DIP switch on the E850-96 board (which controls XOM SoC lines), as stated in [1].

The boot device information is requested from EL3 software using the corresponding SMC call, which in turn reads it from iRAM memory, which was written by the ROM code. New routines decode that data and allow the user to check the current boot device, boot order, etc. That API can be used further to implement different code flows depending on the current boot device, e.g.:

- on eMMC boot: obtain the firmware binaries from eMMC
- on USB boot: download the firmware over USB instead

No functional change; this patch only adds new functionality but it's not used yet.

[1] doc/board/samsung/e850-96.rst

---
 board/samsung/e850-96/Makefile  |  2 +-
 board/samsung/e850-96/bootdev.c | 99 +++++++++++++++++++++++++++++++++
 board/samsung/e850-96/bootdev.h | 23 ++++++++
 3 files changed, 123 insertions(+), 1 deletion(-)
 create mode 100644 board/samsung/e850-96/bootdev.c
 create mode 100644 board/samsung/e850-96/bootdev.h
board/samsung/e850-96/Makefile +1 -1
index 76b8d47994e8..e9c62d3181fd 100644
@@ -3,4 +3,4 @@
 # Copyright (C) 2024, Linaro Limited
 # Sam Protsenko <[email protected]>
 
-obj-y := e850-96.o fw.o acpm.o pmic.o
+obj-y := e850-96.o fw.o acpm.o pmic.o bootdev.o
board/samsung/e850-96/bootdev.c new file +99 -0

99 lines not on this page · raw message

board/samsung/e850-96/bootdev.h new file +23 -0
new file mode 100644
index 000000000000..5f454bf00901
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (c) 2025 Linaro Ltd.
+ * Sam Protsenko <[email protected]>
+ */
+
+#ifndef __E850_96_BOOTDEV_H
+#define __E850_96_BOOTDEV_H
+
+#include <stdbool.h>
+
+enum bootdev {
+	BOOTDEV_ERROR,
+	BOOTDEV_SD,
+	BOOTDEV_EMMC,
+	BOOTDEV_USB,
+	BOOTDEV_UFS,
+};
+
+enum bootdev bootdev_get_current(void);
+bool bootdev_is_usb(void);
+
+#endif /* __E850_96_BOOTDEV_H */
Signature · 1 line
2.39.5
#3 lore raw

PATCH 3/5 board: samsung: e850-96: Split LDFW loading and init

In reply to Sam Protsenko

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.

---
 board/samsung/e850-96/e850-96.c |  9 ++++++--
 board/samsung/e850-96/fw.c      | 37 ++++++++++++++++++++++-----------
 board/samsung/e850-96/fw.h      |  3 ++-
 3 files changed, 34 insertions(+), 15 deletions(-)
board/samsung/e850-96/e850-96.c +7 -2
index 34e01914032c..3cf98a01b703 100644
@@ -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)
board/samsung/e850-96/fw.c +25 -12
index 64235c01a254..2d52433e38ad 100644
@@ -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;
board/samsung/e850-96/fw.h +2 -1
index 73d9615d4a9c..b061abc4df69 100644
@@ -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 */
Signature · 1 line
2.39.5
#4 lore raw

PATCH 4/5 board: samsung: e850-96: Add routine for loading images over USB

In reply to Sam Protsenko

During USB boot U-Boot is supposed to download some firmware over USB. It's done by EL3 software, so it has to be requested via corresponding SMC call. Implement a routine for doing that.

No functional change.

---
 board/samsung/e850-96/fw.c | 38 +++++++++++++++++++++++++++++++-------
 board/samsung/e850-96/fw.h |  7 +++++++
 2 files changed, 38 insertions(+), 7 deletions(-)
board/samsung/e850-96/fw.c +31 -7
index 2d52433e38ad..e8777060563f 100644
@@ -11,14 +11,19 @@
 #include <linux/arm-smccc.h>
 #include "fw.h"
 
-#define LDFW_RAW_PART		"ldfw"
-#define LDFW_FAT_PATH		"/EFI/firmware/ldfw.bin"
+#define LDFW_RAW_PART			"ldfw"
+#define LDFW_FAT_PATH			"/EFI/firmware/ldfw.bin"
+#define LDFW_MAGIC			0x10adab1e
 
-#define LDFW_MAGIC		0x10adab1e
-#define SMC_CMD_LOAD_LDFW	-0x500
-#define SDM_HW_RESET_STATUS	0x1230
-#define SDM_SW_RESET_STATUS	0x1231
-#define SB_ERROR_PREFIX		0xfdaa0000
+/* SMC command for providing LDFW to EL3 monitor */
+#define SMC_CMD_LOAD_LDFW		-0x500
+/* SMC command for loading some binary over USB */
+#define SMC_CMD_LOAD_IMAGE_BY_USB	-0x512
+
+/* Error codes for SMC_CMD_LOAD_LDFW */
+#define SDM_HW_RESET_STATUS		0x1230
+#define SDM_SW_RESET_STATUS		0x1231
+#define SB_ERROR_PREFIX			0xfdaa0000
 
 struct ldfw_header {
 	u32 magic;
@@ -93,6 +98,25 @@ static int read_fw_from_raw(const char *ifname, int dev, const char *part_name,
 	return 0;
 }
 
+/**
+ * load_image_usb - Load some binary over USB during USB boot
+ * @type: Image type
+ * @addr: Memory address where the image should be downloaded to
+ * @size: Image size
+ *
+ * Return: 0 on success or a negative value on error.
+ */
+int load_image_usb(enum usb_dn_image type, phys_addr_t addr, phys_size_t size)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_smc(SMC_CMD_LOAD_IMAGE_BY_USB, (u64)type, addr, size,
+		      0, 0, 0, 0, &res);
+
+	if (res.a0)
+		return -EIO;
+}
+
 /**
  * load_ldfw_from_blk - Load the loadable firmware (LDFW) from block device
  * @ifname: Interface name of the block device to load the firmware from
board/samsung/e850-96/fw.h +7 -0
index b061abc4df69..68f943e8bbce 100644
@@ -9,6 +9,13 @@
 
 #include <asm/types.h>
 
+/* Image types for downloading over USB */
+enum usb_dn_image {
+	USB_DN_IMAGE_LDFW	= 1,	/* Loadable Firmware */
+	USB_DN_IMAGE_SP		= 2,	/* Secure Payload (tzsw.img) */
+};
+
+int load_image_usb(enum usb_dn_image type, phys_addr_t addr, phys_size_t size);
 int load_ldfw_from_blk(const char *ifname, int dev, int part, phys_addr_t addr);
 int init_ldfw(phys_addr_t addr);
 
Signature · 1 line
2.39.5
#5 lore raw

PATCH 5/5 board: samsung: e850-96: Load firmwares over USB on USB boot

In reply to Sam Protsenko

During USB boot it's expected that the bootloader (U-Boot) should download LDFW and TZSW firmware binaries over USB, using corresponding SMC call. Once it's done, the Boot ROM code can release the USB block, so that it can be used in U-Boot (e.g. for flashing images to eMMC using DFU or fastboot). Otherwise USB wouldn't be accessible in U-Boot, and any attempt to access USB PHY or DWC3 registers will lead to abort.

---
 board/samsung/e850-96/e850-96.c | 36 +++++++++++++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)
board/samsung/e850-96/e850-96.c +34 -2
index 3cf98a01b703..3aa4992a36d5 100644
@@ -11,6 +11,7 @@
 #include <net.h>
 #include <usb.h>
 #include <asm/io.h>
+#include "bootdev.h"
 #include "fw.h"
 #include "pmic.h"
 
@@ -31,6 +32,10 @@
 #define EMMC_DEV_NUM			0
 #define EMMC_ESP_PART			1
 
+/* Firmware size */
+#define LDFW_MAX_SIZE			SZ_4M
+#define SP_MAX_SIZE			SZ_1M
+
 struct efi_fw_image fw_images[] = {
 	{
 		.image_type_id = E850_96_FWBL1_IMAGE_GUID,
@@ -127,11 +132,34 @@ static void setup_ethaddr(void)
 		eth_env_set_enetaddr("ethaddr", mac_addr);
 }
 
+static void load_firmware_usb(void)
+{
+	int err;
+
+	printf("Loading LDFW firmware (over USB)...\n");
+	err = load_image_usb(USB_DN_IMAGE_LDFW, LDFW_NWD_ADDR, LDFW_MAX_SIZE);
+	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);
+		/* Do not return, still need to download SP */
+	}
+
+	printf("Loading SP firmware (over USB)...\n");
+	err = load_image_usb(USB_DN_IMAGE_SP, LDFW_NWD_ADDR, SP_MAX_SIZE);
+	if (err)
+		printf("ERROR: SP loading failed (%d)\n", err);
+}
+
 /*
  * Call this in board_late_init() to avoid probing block devices before
  * efi_init_early().
  */
-void load_firmware(void)
+static void load_firmware_blk(void)
 {
 	const char *ifname;
 	ulong dev, part;
@@ -175,7 +203,11 @@ int board_late_init(void)
 {
 	setup_serial();
 	setup_ethaddr();
-	load_firmware();
+
+	if (bootdev_is_usb())
+		load_firmware_usb();
+	else
+		load_firmware_blk();
 
 	return 0;
 }
Signature · 1 line
2.39.5
#6 lore raw
In reply to Sam Protsenko
Quoted 52 lines · Sam Protsenko

When U-Boot is executed during USB boot [1,2] on E850-96 board, two issues happen:

1. eMMC fails to initialize
2. Attempt to use USB PHY driver leads to abort

It was identified that issue #1 happens due to enalbed Flash Memory Protector bits in MMC block registers during USB boot, and it's handled in patch series [3].

Issue #2 on the other hand happens because ROM code expects the bootloader (U-Boot) to download remaining binaries (LDFW and TZSW) over USB using SMC calls. Before that, the access to USB blocks (USB PHY and DWC3) is disabled, probably because corresponding TrustZone domains are configured for access from Secure World only.

This patch series implements downloading LDFW and TZSW firmware over USB during USB boot, which makes it possible to use U-Boot for flashing images to eMMC using fastboot and DFU protocols. That in turn simplifies the U-Boot development, as one can use `dltool' [1] to run U-Boot binary during USB boot, and update U-Boot on eMMC this way (e.g. using DFU). It's not possible when using LittleKernel bootloader, as it expects non-standard Samsung GPT partition, but in case of U-Boot we use the regular one.

Once this patch series and patch series [3] are applied it'll be possible to use U-Boot during USB boot. The two series are independent of each other, and can be applied in any particular order.

[1] https://gitlab.com/LinaroLtd/e850-96/tools/dltool
[2] https://docs.u-boot.org/en/latest/board/samsung/e850-96.html
[3] https://lore.kernel.org/u-boot/[email protected]/

Sam Protsenko (5):
board: samsung: e850-96: Keep public functions together
board: samsung: e850-96: Add routines for checking boot dev
board: samsung: e850-96: Split LDFW loading and init
board: samsung: e850-96: Add routine for loading images over USB
board: samsung: e850-96: Load firmwares over USB on USB boot

 board/samsung/e850-96/Makefile  |  2 +-
 board/samsung/e850-96/bootdev.c | 99 +++++++++++++++++++++++++++++++++
 board/samsung/e850-96/bootdev.h | 23 ++++++++
 board/samsung/e850-96/e850-96.c | 65 +++++++++++++++++-----
 board/samsung/e850-96/fw.c      | 75 ++++++++++++++++++-------
 board/samsung/e850-96/fw.h      | 10 +++-
 6 files changed, 239 insertions(+), 35 deletions(-)
 create mode 100644 board/samsung/e850-96/bootdev.c
 create mode 100644 board/samsung/e850-96/bootdev.h
Quoted 2 lines

base-commit: fd976ff3a233ae7c6a9f5bec790b02bbbf57bb24 --

Oops, a minor mistake was found in this series. I'll send v2 shortly.

Quoted 2 lines

2.39.5