Commit 0798d6fd4191f5ea2e53496d57db482529364d2d
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 Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk> Reviewed-by: Stephen Warren <swarren@nvidia.com>
Showing 1 changed file with 41 additions and 12 deletions Side-by-side Diff
... | ... | @@ -53,29 +53,57 @@ |
53 | 53 | { |
54 | 54 | int ret; |
55 | 55 | block_dev_desc_t *desc; |
56 | + char *var = NULL; | |
57 | + bool bootable = false; | |
58 | + int i; | |
56 | 59 | |
57 | - if (argc < 2 || argc > 3) | |
60 | + if (argc < 2) | |
58 | 61 | return CMD_RET_USAGE; |
59 | 62 | |
63 | + if (argc > 2) { | |
64 | + for (i = 2; i < argc ; i++) { | |
65 | + if (argv[i][0] == '-') { | |
66 | + if (!strcmp(argv[i], "-bootable")) { | |
67 | + bootable = true; | |
68 | + } else { | |
69 | + printf("Unknown option %s\n", argv[i]); | |
70 | + return CMD_RET_USAGE; | |
71 | + } | |
72 | + } else { | |
73 | + var = argv[i]; | |
74 | + break; | |
75 | + } | |
76 | + } | |
77 | + | |
78 | + /* Loops should have been exited at the last argument, which | |
79 | + * as it contained the variable */ | |
80 | + if (argc != i + 1) | |
81 | + return CMD_RET_USAGE; | |
82 | + } | |
83 | + | |
60 | 84 | ret = get_device(argv[0], argv[1], &desc); |
61 | 85 | if (ret < 0) |
62 | 86 | return 1; |
63 | 87 | |
64 | - if (argc == 3) { | |
88 | + if (var != NULL) { | |
65 | 89 | int p; |
66 | - char str[512] = { 0, }; | |
90 | + char str[512] = { '\0', }; | |
67 | 91 | disk_partition_t info; |
68 | 92 | |
69 | 93 | for (p = 1; p < 128; p++) { |
94 | + char t[5]; | |
70 | 95 | int r = get_partition_info(desc, p, &info); |
71 | 96 | |
72 | - if (r == 0) { | |
73 | - char t[5]; | |
74 | - sprintf(t, "%s%d", str[0] ? " " : "", p); | |
75 | - strcat(str, t); | |
76 | - } | |
97 | + if (r != 0) | |
98 | + continue; | |
99 | + | |
100 | + if (bootable && !info.bootable) | |
101 | + continue; | |
102 | + | |
103 | + sprintf(t, "%s%d", str[0] ? " " : "", p); | |
104 | + strcat(str, t); | |
77 | 105 | } |
78 | - setenv(argv[2], str); | |
106 | + setenv(var, str); | |
79 | 107 | return 0; |
80 | 108 | } |
81 | 109 | |
... | ... | @@ -98,7 +126,7 @@ |
98 | 126 | } |
99 | 127 | |
100 | 128 | U_BOOT_CMD( |
101 | - part, 5, 1, do_part, | |
129 | + part, CONFIG_SYS_MAXARGS, 1, do_part, | |
102 | 130 | "disk partition related commands", |
103 | 131 | "part uuid <interface> <dev>:<part>\n" |
104 | 132 | " - print partition UUID\n" |
... | ... | @@ -106,7 +134,8 @@ |
106 | 134 | " - set environment variable to partition UUID\n" |
107 | 135 | "part list <interface> <dev>\n" |
108 | 136 | " - print a device's partition table\n" |
109 | - "part list <interface> <dev> <varname>\n" | |
110 | - " - set environment variable to the list of partitions" | |
137 | + "part list <interface> <dev> [flags] <varname>\n" | |
138 | + " - set environment variable to the list of partitions\n" | |
139 | + " flags can be -bootable (list only bootable partitions)" | |
111 | 140 | ); |
-
mentioned in commit 653447
-
mentioned in commit 653447
-
mentioned in commit 653447
-
mentioned in commit 653447
-
mentioned in commit 653447
-
mentioned in commit 653447
-
mentioned in commit 653447
-
mentioned in commit 653447
-
mentioned in commit 653447
-
mentioned in commit 653447
-
mentioned in commit 653447
-
mentioned in commit 653447
-
mentioned in commit 653447
-
mentioned in commit 653447
-
mentioned in commit 653447
-
mentioned in commit 653447
-
mentioned in commit 653447
-
mentioned in commit 653447
-
mentioned in commit 653447
-
mentioned in commit 653447
-
mentioned in commit 653447
-
mentioned in commit 653447
-
mentioned in commit 653447
-
mentioned in commit 653447
-
mentioned in commit 653447
-
mentioned in commit 653447
-
mentioned in commit 653447
-
mentioned in commit 653447
-
mentioned in commit 653447
-
mentioned in commit 653447
-
mentioned in commit 653447
-
mentioned in commit 653447
-
mentioned in commit 653447
-
mentioned in commit 653447