summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWinter Wang <wente.wang@nxp.com>2016-11-21 18:21:07 +0800
committerWinter Wang <wente.wang@nxp.com>2016-11-21 18:31:49 +0800
commit244c4dbc04dec866eff912b0aea8d83eb07be0ee (patch)
tree173fe03daf8a531453999b6dac134fd9fa978dda
parent3197bfd7b43e6eda70116f6439cb0f1e346cf2d1 (diff)
downloadu-boot-imx-244c4dbc04dec866eff912b0aea8d83eb07be0ee.zip
u-boot-imx-244c4dbc04dec866eff912b0aea8d83eb07be0ee.tar.gz
u-boot-imx-244c4dbc04dec866eff912b0aea8d83eb07be0ee.tar.bz2
libavb: fsl: use bootctl to select slot in UNLOCK
if avb verifies fail in UNLOCK, modify fsl_bootctl to read a/b metadata, select curr slot based on metadata. Change-Id: Ic34a687bb4eb1f07bf58338ad7a995f241fdeec0 Signed-off-by: Winter Wang <wente.wang@nxp.com>
-rw-r--r--drivers/usb/gadget/f_fastboot.c13
-rw-r--r--lib/libavb/fsl/fsl_avb.h4
-rw-r--r--lib/libavb/fsl/fsl_bootctl.c38
3 files changed, 45 insertions, 10 deletions
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index 586e38a..b1a4dbb 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -1912,16 +1912,23 @@ int do_boota(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) {
} else { /* lock_status == FASTBOOT_UNLOCK && verify fail */
/* if in unlock state, log the verify state */
printf(" verify FAIL, state: UNLOCK\n");
- printf(" boot 'boot_a' still\n");
#endif
/* if lock/unlock not enabled or verify fail
* in unlock state, will try boot */
size_t num_read;
hdr = &boothdr;
+ char bootimg[8];
+ char *slot = select_slot(&fsl_avb_ops);
+ if (slot == NULL) {
+ printf("boota: no bootable slot\n");
+ goto fail;
+ }
+ sprintf(bootimg, "boot%s", slot);
+ printf(" boot '%s' still\n", bootimg);
/* maybe we should use bootctl to select a/b
* but libavb doesn't export a/b select */
- if (fsl_avb_ops.read_from_partition(&fsl_avb_ops, "boot_a",
+ if (fsl_avb_ops.read_from_partition(&fsl_avb_ops, bootimg,
0, sizeof(boothdr), hdr, &num_read) != AVB_IO_RESULT_OK &&
num_read != sizeof(boothdr)) {
printf("boota: read bootimage head error\n");
@@ -1932,7 +1939,7 @@ int do_boota(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) {
goto fail;
}
image_size = android_image_get_end(hdr) - (ulong)hdr;
- if (fsl_avb_ops.read_from_partition(&fsl_avb_ops, "boot_a",
+ if (fsl_avb_ops.read_from_partition(&fsl_avb_ops, bootimg,
0, image_size, (void *)load_addr, &num_read) != AVB_IO_RESULT_OK &&
num_read != image_size) {
printf("boota: read boot image error\n");
diff --git a/lib/libavb/fsl/fsl_avb.h b/lib/libavb/fsl/fsl_avb.h
index 743bc7c..180186a 100644
--- a/lib/libavb/fsl/fsl_avb.h
+++ b/lib/libavb/fsl/fsl_avb.h
@@ -167,4 +167,8 @@ int rbkidx_erase(const char * kblb_part);
* */
int avbkeyblb_init(uint8_t *plainkey, uint32_t keylen, const char *kblb_part /*"avbkey"*/);
+/* read a/b metadata to get curr slot
+ * return slot suffix '_a'/'_b' or NULL */
+char *select_slot(AvbOps *ops);
+
#endif /* __FSL_AVB_H__ */
diff --git a/lib/libavb/fsl/fsl_bootctl.c b/lib/libavb/fsl/fsl_bootctl.c
index dc55444..23625a1 100644
--- a/lib/libavb/fsl/fsl_bootctl.c
+++ b/lib/libavb/fsl/fsl_bootctl.c
@@ -53,19 +53,19 @@ bool is_slotvar_avb(char *cmd) {
return false;
}
-static char *get_curr_slot(AvbABData *ab_data) {
+static int get_curr_slot(AvbABData *ab_data) {
if (slot_is_bootable(&ab_data->slots[0]) &&
slot_is_bootable(&ab_data->slots[1])) {
if (ab_data->slots[1].priority > ab_data->slots[0].priority)
- return slot_suffix[1];
+ return 1;
else
- return slot_suffix[0];
+ return 0;
} else if (slot_is_bootable(&ab_data->slots[0]))
- return slot_suffix[0];
+ return 0;
else if (slot_is_bootable(&ab_data->slots[1]))
- return slot_suffix[1];
+ return 1;
else
- return "no valid slot";
+ return -1;
}
int get_slotvar_avb(AvbOps *ops, char *cmd, char *buffer, size_t size) {
@@ -102,7 +102,13 @@ int get_slotvar_avb(AvbOps *ops, char *cmd, char *buffer, size_t size) {
}
if (!strcmp_l1("current-slot", cmd)) {
- strlcpy(buffer, get_curr_slot(&ab_data), size);
+ int curr = get_curr_slot(&ab_data);
+ if (curr >= 0 && curr < SLOT_NUM)
+ strlcpy(buffer, slot_suffix[curr], size);
+ else {
+ strlcpy(buffer, "no bootable slot", size);
+ return -1;
+ }
} else if (!strcmp_l1("slot-successful:", cmd)) {
str += strlen("slot-successful:");
@@ -150,3 +156,21 @@ int get_slotvar_avb(AvbOps *ops, char *cmd, char *buffer, size_t size) {
return 0;
}
+
+char *select_slot(AvbOps *ops) {
+ AvbABData ab_data;
+ int curr;
+
+ assert(ops != NULL);
+
+ /* load ab meta */
+ if (ops->read_ab_metadata == NULL ||
+ ops->read_ab_metadata(ops, &ab_data) != AVB_IO_RESULT_OK) {
+ return NULL;
+ }
+ curr = get_curr_slot(&ab_data);
+ if (curr >= 0 && curr < SLOT_NUM)
+ return slot_suffix[curr];
+ else
+ return NULL;
+}