Skip to contentSkip to conversation

dfu: thor: fix: Modify dfu_get_alt() function to support absolute paths

PATCH Superseded Lukasz Majewski 2 participants 5 messages Nov 4, 2014 – Nov 14, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dfu: thor: fix: Modify dfu_get_alt() function to support absolute paths

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).

---
 drivers/dfu/dfu.c | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)
drivers/dfu/dfu.c +27 -2
index 55e6a83..1e9ccdc 100644
@@ -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 patch 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;
Signature · 1 line
2.0.0.rc2
#1 lore raw

PATCH 1/1 dfu: thor: fix: Modify dfu_get_alt() function to support absolute paths

Quoted 31 lines · Lukasz Majewski

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).

---
 drivers/dfu/dfu.c | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)
drivers/dfu/dfu.c +3 -2
index 55e6a83..1e9ccdc 100644
@@ -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)))

drivers/dfu/dfu.c struct dfu_entity *dfu_get_entity(int alt) · line 561

Quoted 10 lines
drivers/dfu/dfu.c +10 -0
+				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 patch must be checked for equality

I think this patch needs patching using s/patch/path/ ;-)

Otherwise I don't see much issues.

Best regards,
Marek Vasut

#2 lore raw

PATCH v2 1/1 dfu: thor: fix: Modify dfu_get_alt() function to support absolute paths

In reply to Lukasz Majewski

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).

---
Changes for v2:
- Fix patch to path in comment

---
 drivers/dfu/dfu.c | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)
drivers/dfu/dfu.c +27 -2
index 55e6a83..deafda2 100644
@@ -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;
Signature · 1 line
2.0.0.rc2
#3 lore raw

PATCH v2 1/1 dfu: thor: fix: Modify dfu_get_alt() function to support absolute paths

Hi Lukasz,

Quoted 59 lines

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).

---
Changes for v2:
- Fix patch to path in comment

---
 drivers/dfu/dfu.c | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)
drivers/dfu/dfu.c +8 -2
index 55e6a83..deafda2 100644
@@ -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

drivers/dfu/dfu.c +3 -0
+			 * compared "plain" file name (uImage)
+			 *
+			 * It is the case for e.g. thor gadget where

lthor SW

drivers/dfu/dfu.c +1 -0
+			 * sends only the file name, so only the

very last part

drivers/dfu/dfu.c +9 -0
+			 * of path must be checked for equality
+			 */
+
+			str = strstr(dfu->name, name);
+			if (!str)
+				continue;
+
+			/*
+			 * Check if matching substring is the last

element of

drivers/dfu/dfu.c struct dfu_entity *dfu_get_entity(int alt) · line 578

Quoted 9 lines
drivers/dfu/dfu.c +6 -0
+			 * dfu->name (uImage)
+			 */
+			if (strlen(dfu->name) ==
+			    ((str - dfu->name) + strlen(name)))
+				return dfu->alt;
+		}
 	}
 
 	return -ENODEV;

Applied to u-boot-dfu repository. Thanks

Signature · 5 lines
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group
#4 lore raw

PATCH v2 1/1 dfu: thor: fix: Modify dfu_get_alt() function to support absolute paths

Quoted 16 lines · Lukasz Majewski

Hi Lukasz,

Quoted 14 lines

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).

[...]

Quoted 7 lines
Quoted 7 lines
drivers/dfu/dfu.c +6 -0
+			 * dfu->name (uImage)
+			 */
+			if (strlen(dfu->name) ==
+			    ((str - dfu->name) + strlen(name)))
+				return dfu->alt;
+		}
Quoted 5 lines

drivers/dfu/dfu.c struct dfu_entity *dfu_get_entity(int alt) · line 578

Quoted 3 lines
drivers/dfu/dfu.c +0 -0
 	}
 
 	return -ENODEV;

Applied to u-boot-dfu repository. Thanks

It's nice to see that you're taking good care of your clones ;-)

Best regards,
Marek Vasut