]> git.sur5r.net Git - u-boot/commitdiff
dfu: thor: fix: Modify dfu_get_alt() function to support absolute paths
authorLukasz Majewski <l.majewski@samsung.com>
Wed, 5 Nov 2014 09:54:16 +0000 (10:54 +0100)
committerMarek Vasut <marex@denx.de>
Fri, 14 Nov 2014 20:09:06 +0000 (21:09 +0100)
Recently the ext4 file system imposed passing absolute path with its file
name parameter.
As a result dfu_alt_info env variable has been modified to provide absolute
path when ext4 file system is accessed (e.g. /uImage ext4 0 2;).

Unfortunately, lthor flashing program provides plain file name (like uImage)
and hence those two file names do not match anymore.

Presented commit also allows lthor to write files to sub directories (like
/boot/bin/uImage).

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Reviewed-by: Marek Vasut <marex@denx.de>
drivers/dfu/dfu.c

index 55e6a83b9ad6956ccc1013bdb227d99d5f9ddfbc..deafda29c98bf2d400e1b6ed72239e8d4c13f3b8 100644 (file)
@@ -544,10 +544,35 @@ struct dfu_entity *dfu_get_entity(int alt)
 int dfu_get_alt(char *name)
 {
        struct dfu_entity *dfu;
+       char *str;
 
        list_for_each_entry(dfu, &dfu_list, list) {
-               if (!strncmp(dfu->name, name, strlen(dfu->name)))
-                       return dfu->alt;
+               if (dfu->name[0] != '/') {
+                       if (!strncmp(dfu->name, name, strlen(dfu->name)))
+                               return dfu->alt;
+               } else {
+                       /*
+                        * One must also consider absolute path
+                        * (/boot/bin/uImage) available at dfu->name when
+                        * compared "plain" file name (uImage)
+                        *
+                        * It is the case for e.g. thor gadget where lthor SW
+                        * sends only the file name, so only the very last part
+                        * of path must be checked for equality
+                        */
+
+                       str = strstr(dfu->name, name);
+                       if (!str)
+                               continue;
+
+                       /*
+                        * Check if matching substring is the last element of
+                        * dfu->name (uImage)
+                        */
+                       if (strlen(dfu->name) ==
+                           ((str - dfu->name) + strlen(name)))
+                               return dfu->alt;
+               }
        }
 
        return -ENODEV;