Skip to contentSkip to conversation

cmd: ubi.c: skip part command if right partition is already attached

PATCH In review Alexandre Besnard 2 participants 2 messages Apr 4, 2022 – Apr 15, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cmd: ubi.c: skip part command if right partition is already attached

Attaching a UBI partition may take a while, since scanning the memory is required.
It thus makes sense to avoid a detach/scan/attach cycle when the right partition is already attached, and let the calling process call 'detach' beforehand if it needs it.

This commit checks for the currently attached UBI partition, and skips reattaching if not needed, showing an information.

---
 cmd/ubi.c | 5 +++++
 1 file changed, 5 insertions(+)
cmd/ubi.c +5 -0
index fe8ac58bac..fccbfdf48d 100644
@@ -511,6 +511,11 @@ int ubi_part(char *part_name, const char *vid_header_offset)
 	struct mtd_info *mtd;
 	int err = 0;
 
+	if (ubi && ubi->mtd && !strcmp(ubi->mtd->name, part_name)) {
+		printf("UBI partition '%s' already selected\n", part_name);
+		return 0;
+	}
+
 	ubi_detach();
 
 	mtd_probe_devices();
Signature · 1 line
2.35.1
#1 lore raw
Quoted 10 lines · Alexandre Besnard

Attaching a UBI partition may take a while, since scanning the memory is required.
It thus makes sense to avoid a detach/scan/attach cycle when the right partition is already attached, and let the calling process call 'detach' beforehand if it needs it.

This commit checks for the currently attached UBI partition, and skips reattaching if not needed, showing an information.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom