From ad4831d7a51d53bdb5ed0493fdc7bb510ce3f9a5 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Thu, 26 Mar 2026 17:59:23 -0500 Subject: env: scsi: rename ENV_SCSI_PART_UUID Rename SCSI_ENV_PART_UUID to ENV_SCSI_PART_UUID. All other environment- related config names are of the form ENV_, so this is more consistent. Signed-off-by: David Lechner Reviewed-by: Sumit Garg --- configs/qcom_qcs9100_defconfig | 2 +- env/Kconfig | 2 +- env/scsi.c | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/configs/qcom_qcs9100_defconfig b/configs/qcom_qcs9100_defconfig index 371448b8b1b..082106157bb 100644 --- a/configs/qcom_qcs9100_defconfig +++ b/configs/qcom_qcs9100_defconfig @@ -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 diff --git a/env/Kconfig b/env/Kconfig index 2feff0b382e..5824f762870 100644 --- a/env/Kconfig +++ b/env/Kconfig @@ -762,7 +762,7 @@ 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_PART_UUID string "SCSI partition UUID for saving environment" depends on ENV_IS_IN_SCSI help diff --git a/env/scsi.c b/env/scsi.c index 207717e17b1..f376f731870 100644 --- a/env/scsi.c +++ b/env/scsi.c @@ -35,7 +35,7 @@ static inline struct env_scsi_info *env_scsi_get_part(void) { struct env_scsi_info *ep = &env_part; - if (scsi_get_blk_by_uuid(CONFIG_SCSI_ENV_PART_UUID, &ep->blk, &ep->part)) + 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 +83,12 @@ static int env_scsi_load(void) int ret; if (!ep) { - env_set_default(CONFIG_SCSI_ENV_PART_UUID " partition not found", 0); + 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); + env_set_default(CONFIG_ENV_SCSI_PART_UUID " partition read failed", 0); return -EIO; } -- cgit v1.2.3 From e5d8ad260bb7de1729a6454e8b95a83e629dff7a Mon Sep 17 00:00:00 2001 From: David Lechner Date: Thu, 26 Mar 2026 17:59:24 -0500 Subject: scsi: return ENODEV in scsi_get_blk_by_uuid() Change scsi_get_blk_by_uuid() to return -ENODEV instead of -1 on error. Other scsi_* functions return an error code rather than -1. 1 is EPERM, which doesn't make sense here. So we use ENODEV instead. The only caller only checks for !success, so changing the value has no effect on the caller. Signed-off-by: David Lechner --- drivers/scsi/scsi-uclass.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/scsi-uclass.c b/drivers/scsi/scsi-uclass.c index 3eb6069649f..e7870d7f831 100644 --- a/drivers/scsi/scsi-uclass.c +++ b/drivers/scsi/scsi-uclass.c @@ -50,7 +50,7 @@ int scsi_get_blk_by_uuid(const char *uuid, } } - return -1; + return -ENODEV; } int scsi_bus_reset(struct udevice *dev) -- cgit v1.2.3 From 7b824e75056a45d7c40eea9014edffa1b5289750 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Thu, 26 Mar 2026 17:59:25 -0500 Subject: scsi: document return values of public functions Add Return: documentation for some public functions in scsi.h that were missing it. Signed-off-by: David Lechner --- include/scsi.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/scsi.h b/include/scsi.h index 8d6c5116419..c244120c283 100644 --- a/include/scsi.h +++ b/include/scsi.h @@ -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,6 +349,7 @@ 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); @@ -357,6 +359,7 @@ int scsi_scan_dev(struct udevice *dev, bool verbose); * @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); -- cgit v1.2.3 From b382cd0973521a5197a097d4e190f47aadb79757 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Thu, 26 Mar 2026 17:59:26 -0500 Subject: scsi: move scsi_scan() call out of scsi_get_blk_by_uuid() Move scsi_scan() call out of scsi_get_blk_by_uuid(). The only caller, env_scsi_get_part(), should be managing this call since it may also want to use different ways to get the partition information in the future. Signed-off-by: David Lechner --- drivers/scsi/scsi-uclass.c | 6 ------ env/scsi.c | 6 ++++++ include/scsi.h | 2 ++ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/scsi-uclass.c b/drivers/scsi/scsi-uclass.c index e7870d7f831..39b4c7476d4 100644 --- a/drivers/scsi/scsi-uclass.c +++ b/drivers/scsi/scsi-uclass.c @@ -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) diff --git a/env/scsi.c b/env/scsi.c index f376f731870..1787dcca92a 100644 --- a/env/scsi.c +++ b/env/scsi.c @@ -33,8 +33,14 @@ 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 (!is_scsi_scanned) { + scsi_scan(false /* no verbose */); + is_scsi_scanned = true; + } + if (scsi_get_blk_by_uuid(CONFIG_ENV_SCSI_PART_UUID, &ep->blk, &ep->part)) return NULL; diff --git a/include/scsi.h b/include/scsi.h index c244120c283..2520a8b8fe6 100644 --- a/include/scsi.h +++ b/include/scsi.h @@ -356,6 +356,8 @@ 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 -- cgit v1.2.3 From 83223d4f86980f09fdf341b64f69e03313cac14b Mon Sep 17 00:00:00 2001 From: David Lechner Date: Thu, 26 Mar 2026 17:59:27 -0500 Subject: env: scsi: add CONFIG_ENV_SCSI_HW_PARTITION Add CONFIG_ENV_SCSI_HW_PARTITION and supporting code to allow loading the environment directly from a SCSI device without a partition table. Some platforms store the environment directly on the SCSI device without a way to look it up by partition UUID. Signed-off-by: David Lechner --- env/Kconfig | 11 +++++++++++ env/scsi.c | 22 ++++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/env/Kconfig b/env/Kconfig index 5824f762870..ffaf16c581c 100644 --- a/env/Kconfig +++ b/env/Kconfig @@ -762,6 +762,17 @@ config ENV_MMC_USE_DT The 2 defines CONFIG_ENV_OFFSET, CONFIG_ENV_OFFSET_REDUND are not used as fallback. +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 diff --git a/env/scsi.c b/env/scsi.c index 1787dcca92a..f4986353da5 100644 --- a/env/scsi.c +++ b/env/scsi.c @@ -41,8 +41,14 @@ static inline struct env_scsi_info *env_scsi_get_part(void) is_scsi_scanned = true; } - if (scsi_get_blk_by_uuid(CONFIG_ENV_SCSI_PART_UUID, &ep->blk, &ep->part)) - return NULL; + 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; @@ -89,12 +95,20 @@ static int env_scsi_load(void) int ret; if (!ep) { - env_set_default(CONFIG_ENV_SCSI_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_ENV_SCSI_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; } -- cgit v1.2.3 From d72c2b63da5c004bb41855577d4fd783598b004a Mon Sep 17 00:00:00 2001 From: David Lechner Date: Thu, 26 Mar 2026 17:59:28 -0500 Subject: env: scsi: document requirements for ENV_IS_IN_SCSI Expand the Kconfig help for ENV_IS_IN_SCSI to explain the other required config options when this option is enabled. Signed-off-by: David Lechner --- env/Kconfig | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/env/Kconfig b/env/Kconfig index ffaf16c581c..9eb941b74a4 100644 --- a/env/Kconfig +++ b/env/Kconfig @@ -293,6 +293,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 -- cgit v1.2.3