Merge patch series "env: scsi: support SCSI env without partition UUID"

David Lechner <dlechner@baylibre.com> says:

This is a series adding support for reading U-Boot env directly from
SCSI devices that do not have a partition table, similar to how we can
already do this for MMC devices.

The motivation behind this is that MediaTek's BSP is already using the
same disk images for both MMC and UFS devices, so we need to be able to
read the env from SCSI devices without requiring a partition UUID.

The series starts with cleaning up a few oddities we noticed in the
existing code. Then some refactoring so that the env code manages
calling scsi_scan() so that we don't have to duplicate that for the
new code path. Then finally, the last few patches add and document the
new functionality.

Link: https://lore.kernel.org/r/20260326-env-scsi-hw-part-support-v1-0-55c9dd07a2cb@baylibre.com
This commit is contained in:
Tom Rini
2026-04-08 11:07:19 -06:00
5 changed files with 60 additions and 13 deletions
+1 -1
View File
@@ -11,6 +11,6 @@ CONFIG_REMAKE_ELF=y
CONFIG_FASTBOOT_BUF_ADDR=0xdb300000
CONFIG_DEFAULT_DEVICE_TREE="qcom/qcs9100-ride-r3"
CONFIG_ENV_IS_IN_SCSI=y
CONFIG_SCSI_ENV_PART_UUID="71cb9cd0-acf1-b6cb-ad91-be9572fe11a9"
CONFIG_ENV_SCSI_PART_UUID="71cb9cd0-acf1-b6cb-ad91-be9572fe11a9"
# CONFIG_ENV_IS_DEFAULT is not set
# CONFIG_ENV_IS_NOWHERE is not set
+1 -7
View File
@@ -29,15 +29,9 @@ int scsi_get_blk_by_uuid(const char *uuid,
struct blk_desc **blk_desc_ptr,
struct disk_partition *part_info_ptr)
{
static int is_scsi_scanned;
struct blk_desc *blk;
int i, ret;
if (!is_scsi_scanned) {
scsi_scan(false /* no verbose */);
is_scsi_scanned = 1;
}
for (i = 0; i < blk_find_max_devnum(UCLASS_SCSI) + 1; i++) {
ret = blk_get_desc(UCLASS_SCSI, i, &blk);
if (ret)
@@ -50,7 +44,7 @@ int scsi_get_blk_by_uuid(const char *uuid,
}
}
return -1;
return -ENODEV;
}
int scsi_bus_reset(struct udevice *dev)
Vendored
+29 -1
View File
@@ -294,6 +294,23 @@ config ENV_IS_IN_SCSI
Define this if you have an SCSI device which you want to use for the
environment.
- CONFIG_ENV_SIZE:
The size of the partition where the environment is stored in bytes. Must
be a multiple of the partition block size.
- CONFIG_ENV_SCSI_HW_PARTITION:
Specifies which SCSI partition the environment is stored in. If not
set, defaults to partition 0, the user area. Common values might be
1 (first SCSI boot partition), 2 (second SCSI boot partition). Ignored
if CONFIG_ENV_SCSI_PART_UUID is set to non-empty string.
- CONFIG_ENV_SCSI_PART_UUID:
UUID of the SCSI partition where the environment is stored.
config ENV_RANGE
hex "Length of the region in which the environment can be written"
depends on ENV_IS_IN_NAND
@@ -763,7 +780,18 @@ config ENV_MMC_USE_DT
The 2 defines CONFIG_ENV_OFFSET, CONFIG_ENV_OFFSET_REDUND
are not used as fallback.
config SCSI_ENV_PART_UUID
config ENV_SCSI_HW_PARTITION
string "SCSI hardware partition number"
depends on ENV_IS_IN_SCSI
default 0
help
SCSI hardware partition device number on the platform where the
environment is stored. Note that this is not related to any software
defined partition table but instead if we are in the user area, which is
partition 0 or the first boot partition, which is 1 or some other defined
partition.
config ENV_SCSI_PART_UUID
string "SCSI partition UUID for saving environment"
depends on ENV_IS_IN_SCSI
help
Vendored
+24 -4
View File
@@ -33,10 +33,22 @@ static struct env_scsi_info env_part;
static inline struct env_scsi_info *env_scsi_get_part(void)
{
static bool is_scsi_scanned;
struct env_scsi_info *ep = &env_part;
if (scsi_get_blk_by_uuid(CONFIG_SCSI_ENV_PART_UUID, &ep->blk, &ep->part))
return NULL;
if (!is_scsi_scanned) {
scsi_scan(false /* no verbose */);
is_scsi_scanned = true;
}
if (CONFIG_ENV_SCSI_PART_UUID[0] == '\0') {
if (blk_get_device_part_str("scsi", CONFIG_ENV_SCSI_HW_PARTITION,
&ep->blk, &ep->part, true))
return NULL;
} else {
if (scsi_get_blk_by_uuid(CONFIG_ENV_SCSI_PART_UUID, &ep->blk, &ep->part))
return NULL;
}
ep->count = CONFIG_ENV_SIZE / ep->part.blksz;
@@ -83,12 +95,20 @@ static int env_scsi_load(void)
int ret;
if (!ep) {
env_set_default(CONFIG_SCSI_ENV_PART_UUID " partition not found", 0);
if (CONFIG_ENV_SCSI_PART_UUID[0] == '\0')
env_set_default("SCSI partition " CONFIG_ENV_SCSI_HW_PARTITION " not found", 0);
else
env_set_default(CONFIG_ENV_SCSI_PART_UUID " partition not found", 0);
return -ENOENT;
}
if (blk_dread(ep->blk, ep->part.start, ep->count, &envbuf) != ep->count) {
env_set_default(CONFIG_SCSI_ENV_PART_UUID " partition read failed", 0);
if (CONFIG_ENV_SCSI_PART_UUID[0] == '\0')
env_set_default("SCSI partition " CONFIG_ENV_SCSI_HW_PARTITION " read failed", 0);
else
env_set_default(CONFIG_ENV_SCSI_PART_UUID " partition read failed", 0);
return -EIO;
}
+5
View File
@@ -340,6 +340,7 @@ int scsi_bus_reset(struct udevice *dev);
* scsi_scan() - Scan all SCSI controllers for available devices
*
* @vebose: true to show information about each device found
* Return: 0 if OK, -ve on error
*/
int scsi_scan(bool verbose);
@@ -348,15 +349,19 @@ int scsi_scan(bool verbose);
*
* @dev: SCSI bus
* @verbose: true to show information about each device found
* Return: 0 if OK, -ve on error
*/
int scsi_scan_dev(struct udevice *dev, bool verbose);
/**
* scsi_get_blk_by_uuid() - Provides SCSI partition information.
*
* scsi_scan() must have been called before calling this function.
*
* @uuid: UUID of the partition for fetching its info
* @blk_desc_ptr: Provides the blk descriptor
* @part_info_ptr: Provides partition info
* Return: 0 if OK, -ve on error
*/
int scsi_get_blk_by_uuid(const char *uuid, struct blk_desc **blk_desc_ptr,
struct disk_partition *part_info_ptr);