From: Petr Hodina <[email protected]> Select the correct storage media based on the 'storage' env to access the BCB partition.
Signed-off-by: Petr Hodina <[email protected]> --- cmd/phone_util.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/cmd/phone_util.c b/cmd/phone_util.c index 1389b2ca6cd..8367e5729c0 100644 --- a/cmd/phone_util.c +++ b/cmd/phone_util.c @@ -1,14 +1,18 @@ // SPDX-License-Identifier: GPL-2.0+ +#include <bcb.h> #include <button.h> #include <command.h> #include <cyclic.h> #include <dfu.h> +#include <env.h> +#include <fastboot.h> #include <g_dnl.h> #include <net-common.h> #include <stdio.h> #include <asm/system.h> #include <linux/delay.h> +#include <linux/errno.h> #if CONFIG_IS_ENABLED(USB_ETHER) static int do_usbether(struct cmd_tbl *cmdtp, int flag, int argc, @@ -110,3 +114,35 @@ U_BOOT_CMD(dfu_pwr, 1, 0, do_dfu_pwr, " - Run the `dfu` env alias with a cyclic that triggers a\n" " gadget detach when the power button is pressed."); #endif /* CMD_DFU */ + +#if IS_ENABLED(CONFIG_FASTBOOT) +/* + * Pick the BCB partition on the correct storags media + */ +int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason) +{ + static const char * const boot_cmds[] = { + [FASTBOOT_REBOOT_REASON_BOOTLOADER] = "bootonce-bootloader", + [FASTBOOT_REBOOT_REASON_FASTBOOTD] = "boot-fastboot", + [FASTBOOT_REBOOT_REASON_RECOVERY] = "boot-recovery" + }; + const char *storage = env_get("storage"); + int ret; + + if (reason >= FASTBOOT_REBOOT_REASONS_COUNT) + return -EINVAL; + + ret = bcb_find_partition_and_load(storage ?: "scsi", 0, "misc"); + if (ret) + goto out; + + ret = bcb_set(BCB_FIELD_COMMAND, boot_cmds[reason]); + if (ret) + goto out; + + ret = bcb_store(); +out: + bcb_reset(); + return ret; +} +#endif /* CONFIG_FASTBOOT */ -- 2.55.0
