Skip to contentSkip to conversation

Boot from the bootable paritions

PATCH Superseded Sjoerd Simons 3 participants 6 messages Feb 19, 2015 – Feb 24, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Boot from the bootable paritions

In the discussion after the submission of the "Let the distro boot command scan all partitions" patchset it became clear the general consensus was that u-boot should not simply scan all partitions but instead only partitions with the bootable flag set, falling back to parition 1 as was previously done.

This set of patches implements that

Sjoerd Simons (3):
part: Add support for list filtering on bootable partitions config_cmd_default.h: Add 'env exists' command config_distro_bootcmd.h: Prefer booting from bootable paritions

 common/cmd_part.c               | 48 ++++++++++++++++++++++++++++++-----------
 include/config_cmd_default.h    |  1 +
 include/config_distro_bootcmd.h |  3 ++-
 3 files changed, 39 insertions(+), 13 deletions(-)
Signature · 1 line
2.1.4
#1 lore raw

PATCH 1/3 part: Add support for list filtering on bootable partitions

Add an optional -bootable parameter to the part list commands to only put the list of bootable partitions in the environment variable

---
 common/cmd_part.c | 48 ++++++++++++++++++++++++++++++++++++------------
 1 file changed, 36 insertions(+), 12 deletions(-)
common/cmd_part.c +36 -12
index c99f527..e1fe641 100644
@@ -53,29 +53,52 @@ static int do_part_list(int argc, char * const argv[])
 {
 	int ret;
 	block_dev_desc_t *desc;
+	char *var = NULL;
+	bool bootable = false;
+	int i;
 
-	if (argc < 2 || argc > 3)
+	if (argc < 2)
 		return CMD_RET_USAGE;
 
+	for (i = 2; i < argc; i++) {
+		if (argv[i][0] == '-') {
+			if (!strcmp(argv[i], "-bootable")) {
+				bootable = true;
+			} else {
+				printf("Unknown option %s\n", argv[i]);
+				return CMD_RET_USAGE;
+			}
+		} else if (var == NULL) {
+			var = argv[i];
+		} else {
+			printf("duplicated varname\n");
+			return CMD_RET_USAGE;
+		}
+	}
+
 	ret = get_device(argv[0], argv[1], &desc);
 	if (ret < 0)
 		return 1;
 
-	if (argc == 3) {
+	if (var != NULL) {
 		int p;
-		char str[512] = { 0, };
+		char str[512] = { '\0', };
 	  disk_partition_t info;
 
 		for (p = 1; p < 128; p++) {
+			char t[5];
 			int r = get_partition_info(desc, p, &info);
 
-			if (r == 0) {
-				char t[5];
-				sprintf(t, "%s%d", str[0] ? " " : "", p);
-				strcat(str, t);
-			}
+			if (r != 0)
+				continue;
+
+			if (bootable && !info.bootable)
+				continue;
+
+			sprintf(t, "%s%d", str[0] ? " " : "", p);
+			strcat(str, t);
 		}
-		setenv(argv[2], str);
+		setenv(var, str);
 		return 0;
 	}
 
@@ -98,7 +121,7 @@ static int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 }
 
 U_BOOT_CMD(
-	part,	5,	1,	do_part,
+	part,	CONFIG_SYS_MAXARGS,	1,	do_part,
 	"disk partition related commands",
 	"part uuid <interface> <dev>:<part>\n"
 	"    - print partition UUID\n"
@@ -106,6 +129,7 @@ U_BOOT_CMD(
 	"    - set environment variable to partition UUID\n"
 	"part list <interface> <dev>\n"
 	"    - print a device's partition table\n"
-	"part list <interface> <dev> <varname>\n"
-	"    - set environment variable to the list of partitions"
+	"part list <interface> <dev> [flags] <varname>\n"
+	"    - set environment variable to the list of partitions\n"
+	"      flags can be -bootable (list only bootable partitions)"
 );
Signature · 1 line
2.1.4
#2 lore raw

PATCH 1/3 part: Add support for list filtering on bootable partitions

Quoted 10 lines · Sjoerd Simons

Add an optional -bootable parameter to the part list commands to only put the list of bootable partitions in the environment variable

common/cmd_part.c +5 -0
 
+	for (i = 2; i < argc; i++) {
+		if (argv[i][0] == '-') {
+			if (!strcmp(argv[i], "-bootable")) {
+				bootable = true;
+			} else {

common/cmd_part.c static int do_part_list(int argc, char * const argv[]) · line 77

Quoted 10 lines
common/cmd_part.c +10 -0
+				printf("Unknown option %s\n", argv[i]);
+				return CMD_RET_USAGE;
+			}
+		} else if (var == NULL) {
+			var = argv[i];
+		} else {
+			printf("duplicated varname\n");
+			return CMD_RET_USAGE;
+		}
+	}

I'd prefer that to validate the command-line doesn't have multiple variable names, or the variable name specified before the -bootable flag, so that only the following options are valid:

... var
... -bootable var

and not:

... var1 var2
... var -bootable

etc.

This could be tightened up later I suppose. Other than that, this series looks good at a quick glance, so:

#3 lore raw

PATCH 2/3 config_cmd_default.h: Add 'env exists' command

In reply to Sjoerd Simons

env exists allows scripts to query whether an environment variable exists. Enable by default as it adds only a trivial amount of code and can be useful in scripts.

---
 include/config_cmd_default.h | 1 +
 1 file changed, 1 insertion(+)
include/config_cmd_default.h +1 -0
index 73c9544..e79a13b 100644
@@ -21,6 +21,7 @@
 #define CONFIG_CMD_CONSOLE	/* coninfo			*/
 #define CONFIG_CMD_ECHO		/* echo arguments		*/
 #define CONFIG_CMD_EDITENV	/* editenv			*/
+#define CONFIG_CMD_ENV_EXISTS	/* query whether env variables exists */
 #define CONFIG_CMD_FPGA		/* FPGA configuration Support	*/
 #define CONFIG_CMD_IMI		/* iminfo			*/
 #define CONFIG_CMD_ITEST	/* Integer (and string) test	*/
Signature · 1 line
2.1.4
#4 lore raw

PATCH 3/3 config_distro_bootcmd.h: Prefer booting from bootable paritions

In reply to Sjoerd Simons

List bootable partitions and only scan those for bootable files, falling back to partition 1 if there are no bootable partitions

---
 include/config_distro_bootcmd.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/config_distro_bootcmd.h +2 -1
index 07a0b3b..ad2dda1 100644
@@ -197,7 +197,8 @@
 		"done\0"                                                  \
 	\
 	"scan_dev_for_boot_part="                                         \
-		"part list ${devtype} ${devnum} devplist; "               \
+		"part list ${devtype} ${devnum} -bootable devplist; "     \
+		"env exists devplist || setenv devplist 1; "              \
 		"for bootpart in ${devplist}; do "                        \
 			"if fstype ${devtype} ${devnum}:${bootpart} "     \
 					"bootfstype; then "               \
Signature · 1 line
2.1.4
#5 lore raw

cover Boot from the bootable paritions

In reply to Sjoerd Simons

Hi,

Quoted 6 lines · Sjoerd Simons

In the discussion after the submission of the "Let the distro boot command scan all partitions" patchset it became clear the general consensus was that u-boot should not simply scan all partitions but instead only partitions with the bootable flag set, falling back to parition 1 as was previously done.

This set of patches implements that

Thanks for working on this. Since the initial scan all partitions patch-set is in v2015.04, I believe that we should add this one to v2015.04 too, so that we do not change behavior after the official v2015.04 release.

So I've taken the liberty to review this, to expedite the process of getting this upstream. All 3 patches look good to me and are:

Regards,

Hans