Skip to content

Commit 942592f

Browse files
committed
bootctl: add is-slot-marked-successful command.
This makes it easy to call the newly added isSlotMarkedSuccessful() boot_control HAL method added in the CL at https://android-review.googlesource.com/#/c/185841/ This is useful for e.g. test suites. Also improve error reporting for is-slot-bootable command. Change-Id: I603e07d8310fc1de88114dadbaa1622a76289afb Test: tested on edison (Brillo).
1 parent 001077a commit 942592f

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

bootctl/bootctl.c

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,18 @@ static void usage(FILE* where, int argc, char* argv[])
3737
" %s COMMAND\n"
3838
"\n"
3939
"Commands:\n"
40-
" %s hal-info - Show info about boot_control HAL used.\n"
41-
" %s get-number-slots - Prints number of slots.\n"
42-
" %s get-current-slot - Prints currently running SLOT.\n"
43-
" %s mark-boot-successful - Mark current slot as GOOD.\n"
44-
" %s set-active-boot-slot SLOT - On next boot, load and execute SLOT.\n"
45-
" %s set-slot-as-unbootable SLOT - Mark SLOT as invalid.\n"
46-
" %s is-slot-bootable SLOT - Returns 0 only if SLOT is bootable.\n"
47-
" %s get-suffix SLOT - Prints suffix for SLOT.\n"
40+
" %s hal-info - Show info about boot_control HAL used.\n"
41+
" %s get-number-slots - Prints number of slots.\n"
42+
" %s get-current-slot - Prints currently running SLOT.\n"
43+
" %s mark-boot-successful - Mark current slot as GOOD.\n"
44+
" %s set-active-boot-slot SLOT - On next boot, load and execute SLOT.\n"
45+
" %s set-slot-as-unbootable SLOT - Mark SLOT as invalid.\n"
46+
" %s is-slot-bootable SLOT - Returns 0 only if SLOT is bootable.\n"
47+
" %s is-slot-marked-successful SLOT - Returns 0 only if SLOT is marked GOOD.\n"
48+
" %s get-suffix SLOT - Prints suffix for SLOT.\n"
4849
"\n"
4950
"SLOT parameter is the zero-based slot-number.\n",
50-
argv[0], argv[0], argv[0], argv[0], argv[0],
51+
argv[0], argv[0], argv[0], argv[0], argv[0], argv[0],
5152
argv[0], argv[0], argv[0], argv[0], argv[0]);
5253
}
5354

@@ -112,8 +113,13 @@ static int do_set_slot_as_unbootable(boot_control_module_t *module,
112113
static int do_is_slot_bootable(boot_control_module_t *module, int slot_number)
113114
{
114115
int ret = module->isSlotBootable(module, slot_number);
115-
if (ret == 0)
116+
if (ret == 0) {
117+
return EX_SOFTWARE;
118+
} else if (ret < 0) {
119+
fprintf(stderr, "Error calling isSlotBootable(): %s\n",
120+
strerror(-ret));
116121
return EX_SOFTWARE;
122+
}
117123
return EX_OK;
118124
}
119125

@@ -125,6 +131,24 @@ static int do_get_suffix(boot_control_module_t *module, int slot_number)
125131
return EX_OK;
126132
}
127133

134+
static int do_is_slot_marked_successful(boot_control_module_t *module,
135+
int slot_number)
136+
{
137+
if (module->isSlotMarkedSuccessful == NULL) {
138+
fprintf(stderr, "isSlotMarkedSuccessful() is not implemented by HAL.\n");
139+
return EX_UNAVAILABLE;
140+
}
141+
int ret = module->isSlotMarkedSuccessful(module, slot_number);
142+
if (ret == 0) {
143+
return EX_SOFTWARE;
144+
} else if (ret < 0) {
145+
fprintf(stderr, "Error calling isSlotMarkedSuccessful(): %s\n",
146+
strerror(-ret));
147+
return EX_SOFTWARE;
148+
}
149+
return EX_OK;
150+
}
151+
128152
static int parse_slot(int pos, int argc, char *argv[])
129153
{
130154
if (pos > argc - 1) {
@@ -177,6 +201,8 @@ int main(int argc, char *argv[])
177201
return do_is_slot_bootable(module, parse_slot(2, argc, argv));
178202
} else if (strcmp(argv[1], "get-suffix") == 0) {
179203
return do_get_suffix(module, parse_slot(2, argc, argv));
204+
} else if (strcmp(argv[1], "is-slot-marked-successful") == 0) {
205+
return do_is_slot_marked_successful(module, parse_slot(2, argc, argv));
180206
} else {
181207
usage(stderr, argc, argv);
182208
return EX_USAGE;

0 commit comments

Comments
 (0)