From: Mattijs Korpershoek <mkorpershoek@baylibre.com>
To: Dmitry Rokosov <ddrokosov@salutedevices.com>,
Igor Opaniuk <igor.opaniuk@gmail.com>,
Sam Protsenko <semen.protsenko@linaro.org>,
Tom Rini <trini@konsulko.com>, "Andrew F. Davis" <afd@ti.com>,
Neil Armstrong <neil.armstrong@linaro.org>,
Simon Glass <sjg@chromium.org>, Mario Six <mario.six@gdsys.cc>
Cc: u-boot@lists.denx.de, u-boot-amlogic@groups.io,
rockosov@gmail.com, kernel@salutedevices.com,
Dmitry Rokosov <ddrokosov@salutedevices.com>
Subject: Re: [PATCH v3 4/6] cmd: bcb: introduce 'ab_dump' command to print BCB block content
Date: Fri, 11 Oct 2024 16:24:30 +0200 [thread overview]
Message-ID: <878quuhg4h.fsf@baylibre.com> (raw)
In-Reply-To: <20241008-android_ab_master-v3-4-f292c45a33e4@salutedevices.com>
Hi Dmitry,
Thank you for the patch.
On mar., oct. 08, 2024 at 23:18, Dmitry Rokosov <ddrokosov@salutedevices.com> wrote:
> It's really helpful to have the ability to dump BCB block for debugging
> A/B logic on the board supported this partition schema.
>
> Command 'bcb ab_dump' prints all fields of bootloader_control struct
> including slot_metadata for all presented slots.
>
> Output example:
> =====
>> board# bcb ab_dump ubi 0#misc
>> Read 512 bytes from volume misc to 000000000bf07580
>> Read 512 bytes from volume misc to 000000000bf42f40
>> Bootloader Control: [misc]
>> Active Slot: _a
>> Magic Number: 0x42414342
>> Version: 1
>> Number of Slots: 2
>> Recovery Tries Remaining: 0
>> CRC: 0x2c8b50bc (Valid)
>>
>> Slot[0] Metadata:
>> - Priority: 15
>> - Tries Remaining: 0
>> - Successful Boot: 1
>> - Verity Corrupted: 0
>>
>> Slot[1] Metadata:
>> - Priority: 14
>> - Tries Remaining: 7
>> - Successful Boot: 0
>> - Verity Corrupted: 0
> ====
>
> Signed-off-by: Dmitry Rokosov <ddrokosov@salutedevices.com>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
> ---
> boot/android_ab.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> cmd/bcb.c | 35 +++++++++++++++++++++++++++
> include/android_ab.h | 10 ++++++++
> 3 files changed, 113 insertions(+)
>
> diff --git a/boot/android_ab.c b/boot/android_ab.c
> index 0045c8133a8e164f1fdd4c0f9b683de0f13f26e0..c93e51541019d0fe793303c4b3d5286df061906f 100644
> --- a/boot/android_ab.c
> +++ b/boot/android_ab.c
> @@ -372,3 +372,71 @@ int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info,
>
> return slot;
> }
> +
> +int ab_dump_abc(struct blk_desc *dev_desc, struct disk_partition *part_info)
> +{
> + struct bootloader_control *abc;
> + u32 crc32_le;
> + int i, ret;
> + struct slot_metadata *slot;
> +
> + if (!dev_desc || !part_info) {
> + log_err("ANDROID: Empty device descriptor or partition info\n");
> + return -EINVAL;
> + }
> +
> + ret = ab_control_create_from_disk(dev_desc, part_info, &abc, 0);
> + if (ret < 0) {
> + log_err("ANDROID: Cannot create bcb from disk %d\n", ret);
> + return ret;
> + }
> +
> + if (abc->magic != BOOT_CTRL_MAGIC) {
> + log_err("ANDROID: Unknown A/B metadata: %.8x\n", abc->magic);
> + ret = -ENODATA;
> + goto error;
> + }
> +
> + if (abc->version > BOOT_CTRL_VERSION) {
> + log_err("ANDROID: Unsupported A/B metadata version: %.8x\n",
> + abc->version);
> + ret = -ENODATA;
> + goto error;
> + }
> +
> + if (abc->nb_slot > ARRAY_SIZE(abc->slot_info)) {
> + log_err("ANDROID: Wrong number of slots %u, expected %zu\n",
> + abc->nb_slot, ARRAY_SIZE(abc->slot_info));
> + ret = -ENODATA;
> + goto error;
> + }
> +
> + printf("Bootloader Control: [%s]\n", part_info->name);
> + printf("Active Slot: %s\n", abc->slot_suffix);
> + printf("Magic Number: 0x%x\n", abc->magic);
> + printf("Version: %u\n", abc->version);
> + printf("Number of Slots: %u\n", abc->nb_slot);
> + printf("Recovery Tries Remaining: %u\n", abc->recovery_tries_remaining);
> +
> + printf("CRC: 0x%.8x", abc->crc32_le);
> +
> + crc32_le = ab_control_compute_crc(abc);
> + if (abc->crc32_le != crc32_le)
> + printf(" (Invalid, Expected: 0x%.8x)\n", crc32_le);
> + else
> + printf(" (Valid)\n");
> +
> + for (i = 0; i < abc->nb_slot; ++i) {
> + slot = &abc->slot_info[i];
> + printf("\nSlot[%d] Metadata:\n", i);
> + printf("\t- Priority: %u\n", slot->priority);
> + printf("\t- Tries Remaining: %u\n", slot->tries_remaining);
> + printf("\t- Successful Boot: %u\n", slot->successful_boot);
> + printf("\t- Verity Corrupted: %u\n", slot->verity_corrupted);
> + }
> +
> +error:
> + free(abc);
> +
> + return ret;
> +}
> diff --git a/cmd/bcb.c b/cmd/bcb.c
> index 970c58e56cba0e1bdff21b7cd099f69151f0c5b8..4fd32186ae654915b5a42c26d755e5727c211c63 100644
> --- a/cmd/bcb.c
> +++ b/cmd/bcb.c
> @@ -25,6 +25,7 @@ enum bcb_cmd {
> BCB_CMD_FIELD_DUMP,
> BCB_CMD_STORE,
> BCB_CMD_AB_SELECT,
> + BCB_CMD_AB_DUMP,
> };
>
> static const char * const fields[] = {
> @@ -56,6 +57,8 @@ static int bcb_cmd_get(char *cmd)
> return BCB_CMD_FIELD_DUMP;
> if (!strcmp(cmd, "ab_select"))
> return BCB_CMD_AB_SELECT;
> + if (!strcmp(cmd, "ab_dump"))
> + return BCB_CMD_AB_DUMP;
> else
> return -1;
> }
> @@ -93,6 +96,10 @@ static int bcb_is_misused(int argc, char *const argv[])
> if (argc != 4 && argc != 5)
> goto err;
> return 0;
> + case BCB_CMD_AB_DUMP:
> + if (argc != 3)
> + goto err;
> + return 0;
> default:
> printf("Error: 'bcb %s' not supported\n", argv[0]);
> return -1;
> @@ -460,6 +467,28 @@ static int do_bcb_ab_select(struct cmd_tbl *cmdtp, int flag, int argc,
> return CMD_RET_SUCCESS;
> }
>
> +static int do_bcb_ab_dump(struct cmd_tbl *cmdtp, int flag, int argc,
> + char *const argv[])
> +{
> + int ret;
> + struct blk_desc *dev_desc;
> + struct disk_partition part_info;
> +
> + if (part_get_info_by_dev_and_name_or_num(argv[1], argv[2],
> + &dev_desc, &part_info,
> + false) < 0) {
> + return CMD_RET_FAILURE;
> + }
> +
> + ret = ab_dump_abc(dev_desc, &part_info);
> + if (ret < 0) {
> + printf("Cannot dump ABC data, error %d.\n", ret);
> + return CMD_RET_FAILURE;
> + }
> +
> + return CMD_RET_SUCCESS;
> +}
> +
> static struct cmd_tbl cmd_bcb_sub[] = {
> U_BOOT_CMD_MKENT(load, CONFIG_SYS_MAXARGS, 1, do_bcb_load, "", ""),
> U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 1, do_bcb_set, "", ""),
> @@ -469,6 +498,8 @@ static struct cmd_tbl cmd_bcb_sub[] = {
> U_BOOT_CMD_MKENT(store, CONFIG_SYS_MAXARGS, 1, do_bcb_store, "", ""),
> U_BOOT_CMD_MKENT(ab_select, CONFIG_SYS_MAXARGS, 1,
> do_bcb_ab_select, "", ""),
> + U_BOOT_CMD_MKENT(ab_dump, CONFIG_SYS_MAXARGS, 1,
> + do_bcb_ab_dump, "", ""),
> };
>
> static int do_bcb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
> @@ -523,6 +554,10 @@ U_BOOT_CMD(
> " - If '--no-dec' is set, the number of tries remaining will not\n"
> " decremented for the selected boot slot\n"
> "\n"
> + "bcb ab_dump -\n"
> + " Dump boot_control information from specific partition.\n"
> + " <interface> <dev[:part|#part_name]>\n"
> + "\n"
> "Legend:\n"
> "<interface> - storage device interface (virtio, mmc, etc)\n"
> "<dev> - storage device index containing the BCB partition\n"
> diff --git a/include/android_ab.h b/include/android_ab.h
> index 1e53879a25f145a9d18ac0a6553d8c217123aa6f..838230e06f8cbf7a5d79d9d84d9ebe9f96aca10d 100644
> --- a/include/android_ab.h
> +++ b/include/android_ab.h
> @@ -36,4 +36,14 @@ struct disk_partition;
> int ab_select_slot(struct blk_desc *dev_desc, struct disk_partition *part_info,
> bool dec_tries);
>
> +/**
> + * ab_dump_abc() - Dump ABC information for specific partition.
> + *
> + * @dev_desc: Device description pointer
> + * @part_info: Partition information
> + *
> + * Return: 0 on success, or a negative on error
> + */
> +int ab_dump_abc(struct blk_desc *dev_desc, struct disk_partition *part_info);
> +
> #endif /* __ANDROID_AB_H */
>
> --
> 2.43.0
next prev parent reply other threads:[~2024-10-11 14:24 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-08 20:18 [PATCH v3 0/6] android_ab: introduce bcb ab_dump command and provide several bcb fixes Dmitry Rokosov
2024-10-08 20:18 ` [PATCH v3 1/6] include/android_ab: move ab_select_slot() documentation to @ notation Dmitry Rokosov
2024-10-08 20:18 ` [PATCH v3 2/6] treewide: bcb: move ab_select command to bcb subcommands Dmitry Rokosov
2024-10-09 1:56 ` Simon Glass
2024-10-11 13:30 ` Mattijs Korpershoek
[not found] ` <17FD691FA1477948.8140@groups.io>
2024-10-11 14:20 ` Mattijs Korpershoek
2024-10-11 18:00 ` Dmitry Rokosov
2024-10-12 8:49 ` Mattijs Korpershoek
2024-10-14 20:38 ` Dmitry Rokosov
2024-10-14 21:06 ` Simon Glass
2024-10-15 12:10 ` Mattijs Korpershoek
2024-10-15 13:26 ` Dmitry Rokosov
2024-10-15 15:26 ` Mattijs Korpershoek
2024-10-16 14:06 ` Dmitry Rokosov
2024-10-17 11:41 ` Mattijs Korpershoek
2024-10-15 14:42 ` Dmitry Rokosov
2024-10-15 15:27 ` Simon Glass
2024-10-16 15:48 ` Dmitry Rokosov
2024-10-17 11:43 ` Mattijs Korpershoek
2024-10-08 20:18 ` [PATCH v3 3/6] cmd: bcb: change strcmp() usage style in the do_bcb_ab_select() Dmitry Rokosov
2024-10-08 20:18 ` [PATCH v3 4/6] cmd: bcb: introduce 'ab_dump' command to print BCB block content Dmitry Rokosov
2024-10-09 1:57 ` Simon Glass
2024-10-09 13:26 ` Dmitry Rokosov
2024-10-09 21:13 ` Simon Glass
2024-10-10 10:20 ` Dmitry Rokosov
2024-10-10 12:17 ` Mattijs Korpershoek
[not found] ` <17FD1697482D61A4.19251@groups.io>
2024-10-11 14:22 ` Mattijs Korpershoek
2024-10-11 14:45 ` Dmitry Rokosov
2024-10-11 15:06 ` Mattijs Korpershoek
2024-10-11 14:24 ` Mattijs Korpershoek [this message]
2024-10-08 20:18 ` [PATCH v3 5/6] common: android_ab: fix slot suffix for abc block Dmitry Rokosov
2024-10-08 20:18 ` [PATCH v3 6/6] test/py: introduce test for ab_dump command Dmitry Rokosov
2024-10-09 13:28 ` [PATCH v3 0/6] android_ab: introduce bcb ab_dump command and provide several bcb fixes Dmitry Rokosov
2024-10-09 14:05 ` Guillaume LA ROQUE
2024-10-09 14:49 ` Dmitry Rokosov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=878quuhg4h.fsf@baylibre.com \
--to=mkorpershoek@baylibre.com \
--cc=afd@ti.com \
--cc=ddrokosov@salutedevices.com \
--cc=igor.opaniuk@gmail.com \
--cc=kernel@salutedevices.com \
--cc=mario.six@gdsys.cc \
--cc=neil.armstrong@linaro.org \
--cc=rockosov@gmail.com \
--cc=semen.protsenko@linaro.org \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--cc=u-boot-amlogic@groups.io \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox