Add the script name as a prefix to fw_addr and fw_size variables
to make sure they are always unique and won't easily conflict with
user variables.

Signed-off-by: Marek Vasut <[email protected]>
---
Cc: "Lucien.Jheng" <[email protected]>
Cc: Alif Zakuan Yuslaimi <[email protected]>
Cc: Chunfeng Yun <[email protected]>
Cc: GSS_MTK_Uboot_upstream <[email protected]>
Cc: Joe Hershberger <[email protected]>
Cc: Ramon Fried <[email protected]>
Cc: Ryder Lee <[email protected]>
Cc: Sky Huang <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: Weijie Gao <[email protected]>
Cc: [email protected]
---
 lib/fw_loader.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/lib/fw_loader.c b/lib/fw_loader.c
index 207f5fadd1e..f776e09523a 100644
--- a/lib/fw_loader.c
+++ b/lib/fw_loader.c
@@ -13,6 +13,8 @@ int request_firmware_into_buf_via_script(void *buf, size_t 
max_size,
                                         const char *script_name,
                                         size_t *retsize)
 {
+       char env_addr[CONFIG_SYS_CBSIZE] = { 0 };
+       char env_size[CONFIG_SYS_CBSIZE] = { 0 };
        char *args[2] = { "run", (char *)script_name };
        int ret, repeatable;
        ulong addr, size;
@@ -28,13 +30,17 @@ int request_firmware_into_buf_via_script(void *buf, size_t 
max_size,
                return -EINVAL;
        }
 
+       /* Prefix the FW loader variables with the script prefix */
+       snprintf(env_addr, sizeof(env_addr), "%s_addr", script_name);
+       snprintf(env_size, sizeof(env_size), "%s_size", script_name);
+
        /* Find out where the firmware got loaded and how long it is */
-       addr = env_get_hex("fw_addr", 0);
-       size = env_get_hex("fw_size", 0);
+       addr = env_get_hex(env_addr, 0);
+       size = env_get_hex(env_size, 0);
 
        /* Clear the variables set by the firmware loading script */
-       env_set("fw_addr", NULL);
-       env_set("fw_size", NULL);
+       env_set(env_addr, NULL);
+       env_set(env_size, NULL);
 
        if (!addr || !size) {
                log_err("Firmware address (0x%lx) or size (0x%lx) are 
invalid.\n",
-- 
2.51.0

Reply via email to