libubootenv icon indicating copy to clipboard operation
libubootenv copied to clipboard

fw_printenv does not work with `/dev/disk/by-path/platform-11270000.ufshci-scsi-0:0:0:1`

Open AristoChen opened this issue 1 year ago • 0 comments

Hi,

I have /dev/disk/by-path/platform-11270000.ufshci-scsi-0:0:0:1 on my device and I found that fw_printenv will separate the path by checking : then only check if /dev/disk/by-path/platform-11270000.ufshci-scsi-0 exists.

so I am wondering if it makes sense to check the original path first, if it does not exitst, then fallback to the original mechanism that check the splitted path?

I have draft a diff and it works fine on my device

diff --git a/src/uboot_env.c b/src/uboot_env.c
index b924c49..a5dc598 100644
--- a/src/uboot_env.c
+++ b/src/uboot_env.c
@@ -342,21 +342,26 @@ static int normalize_device_path(char *path, struct uboot_flash_env *dev)
        char *sep = NULL, *normalized = NULL;
        size_t normalized_len = 0, volume_len = 0, output_len = 0;
 
-       /*
-        * if volume name is present, split into device path and volume
-        * since only the device path needs normalized
-        */
-       sep = strchr(path, DEVNAME_SEPARATOR);
-       if (sep)
-       {
-               volume_len = strlen(sep);
-               *sep = '\0';
-       }
 
+       /* Check the original path first, then fallback to splitted path */
        if ((normalized = realpath(path, NULL)) == NULL)
        {
-               /* device file didn't exist */
-               return -EINVAL;
+               /*
+                * if volume name is present, split into device path and volume
+                * since only the device path needs normalized
+                */
+               sep = strchr(path, DEVNAME_SEPARATOR);
+               if (sep)
+               {
+                       volume_len = strlen(sep);
+                       *sep = '\0';
+               }
+
+               if ((normalized = realpath(path, NULL)) == NULL)
+               {
+                       /* device file didn't exist */
+                       return -EINVAL;
+               }
        }
 
        normalized_len = strlen(normalized);

AristoChen avatar Sep 06 '23 02:09 AristoChen