Skip to contentSkip to conversation

Add support for booting into userspace fastboot

PATCH Superseded Roman Kovalivskyi 2 participants 5 messages Jun 4, 2020

Subsystems (6)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add support for booting into userspace fastboot

Android 10 adds support for dynamic partitions and in order to support them userspace fastboot must be used[1]. New tool called fastbootd is included into recovery image.

Userspace fastboot works from recovery and is launched if:
1) - Dynamic partitioning is enabled
2) - Boot control block has 'boot-fastboot' value into command field

The bootloader is expected[2] to load and boot into the recovery image upon seeing boot-fastboot in the BCB command. Recovery then parses the BCB message and switches to fastbootd mode.

Please note that boot script is expected to handle 'boot-fastboot' command in BCB and load into recovery mode.

Bootloader must support[3] 'reboot fastboot' command which should reboot device into userspace fastboot to accomodate those changes.

Another command that bootloader must support[3] is 'reboot recovery'. This command should simply reboot device into recovery mode.

Changes since v1[4]:
* Added missing handling of reboot commands for network protocol
* Extended fastboot_set_reboot_flag command to accept reboot reason
* Made former fastboot_set_flag function as an optional implementation of fastboot_set_reboot_flag which could be turned on by Kconfig

[1] - https://source.android.com/devices/bootloader/fastbootd
[2] - https://source.android.com/devices/bootloader/fastbootd#unified_fastboot_and_recovery
[3] - https://source.android.com/devices/bootloader/fastbootd#modifications_to_the_bootloader
[4] - http://patchwork.ozlabs.org/project/uboot/cover/cover.1590539734.git.roman.kovalivskyi at globallogic.com/

Roman Kovalivskyi (1):
fastboot: add default fastboot_set_reboot_flag implementation

Roman Stratiienko (1):
fastboot: add support for 'reboot fastboot' command

 arch/arm/mach-meson/board-common.c |  7 ++++-
 arch/arm/mach-rockchip/board.c     |  7 ++++-
 board/amazon/kc1/kc1.c             |  7 ++++-
 board/lg/sniper/sniper.c           |  7 ++++-
 board/ti/am57xx/board.c            |  7 ++++-
 board/ti/dra7xx/evm.c              |  7 ++++-
 drivers/fastboot/Kconfig           |  9 +++++++
 drivers/fastboot/fb_command.c      | 40 +++++++++++++++++++++++++++-
 drivers/fastboot/fb_common.c       | 42 +++++++++++++++++++++++++++++-
 drivers/usb/gadget/f_fastboot.c    |  2 ++
 include/fastboot.h                 | 13 ++++++++-
 net/fastboot.c                     |  2 ++
 12 files changed, 141 insertions(+), 9 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/2 fastboot: add support for 'reboot fastboot' command

From: Roman Stratiienko <[email protected]>

Android 10 adds support for dynamic partitions and in order to support this userspace fastboot must be used[1]. New tool fastbootd is included into recovery.

Userspace fastboot works from recovery and is launched if:
1) - Dynamic partitioning is enabled
2) - Boot control block has 'boot-fastboot' value into command field The bootloader is expected to load and boot into the recovery image upon seeing boot-fastboot in the BCB command. Recovery then parses the BCB message and switches to fastbootd mode[2].

Please note that boot script is expected to handle 'boot-fastboot' command in BCB and load into recovery mode.

Bootloader must support 'reboot fastboot' command which should reboot device into userspace fastboot to accomodate those changes[3].

Another command that bootloader must support[3] is 'reboot recovery'. This command should simply reboot device into recovery mode.

[1] - https://source.android.com/devices/bootloader/fastbootd
[2] - https://source.android.com/devices/bootloader/fastbootd#unified_fastboot_and_recovery
[3] - https://source.android.com/devices/bootloader/fastbootd#modifications_to_the_bootloader

Change-Id I9d2bdc9a6f6f31ea98572fe155e1cc8341e9af76
---
 arch/arm/mach-meson/board-common.c |  6 ++++-
 arch/arm/mach-rockchip/board.c     |  6 ++++-
 board/amazon/kc1/kc1.c             |  6 ++++-
 board/lg/sniper/sniper.c           |  6 ++++-
 board/ti/am57xx/board.c            |  6 ++++-
 board/ti/dra7xx/evm.c              |  6 ++++-
 drivers/fastboot/fb_command.c      | 40 +++++++++++++++++++++++++++++-
 drivers/fastboot/fb_common.c       |  5 +++-
 drivers/usb/gadget/f_fastboot.c    |  2 ++
 include/fastboot.h                 | 13 +++++++++-
 net/fastboot.c                     |  2 ++
 11 files changed, 89 insertions(+), 9 deletions(-)
arch/arm/mach-meson/board-common.c +5 -1
index 19e5bfd3660c..ffa0ccf003cf 100644
@@ -5,6 +5,7 @@
 
 #include <common.h>
 #include <cpu_func.h>
+#include <fastboot.h>
 #include <init.h>
 #include <net.h>
 #include <asm/arch/boot.h>
@@ -153,8 +154,11 @@ int board_late_init(void)
 #if CONFIG_IS_ENABLED(FASTBOOT)
 static unsigned int reboot_reason = REBOOT_REASON_NORMAL;
 
-int fastboot_set_reboot_flag()
+int fastboot_set_reboot_flag(int reason)
 {
+	if (reason != FASTBOOT_REBOOT_BOOTLOADER)
+		return -ENOTSUPP;
+
 	reboot_reason = REBOOT_REASON_BOOTLOADER;
 
 	printf("Using reboot reason: 0x%x\n", reboot_reason);
arch/arm/mach-rockchip/board.c +5 -1
index 430c0cbf41e4..ca9f63bce72c 100644
@@ -6,6 +6,7 @@
 #include <clk.h>
 #include <cpu_func.h>
 #include <dm.h>
+#include <fastboot.h>
 #include <init.h>
 #include <log.h>
 #include <ram.h>
@@ -152,8 +153,11 @@ int board_usb_init(int index, enum usb_init_type init)
 #endif /* CONFIG_USB_GADGET */
 
 #if CONFIG_IS_ENABLED(FASTBOOT)
-int fastboot_set_reboot_flag(void)
+int fastboot_set_reboot_flag(int reason)
 {
+	if (reason != FASTBOOT_REBOOT_BOOTLOADER)
+		return -ENOTSUPP;
+
 	printf("Setting reboot to fastboot flag ...\n");
 	/* Set boot mode to fastboot */
 	writel(BOOT_FASTBOOT, CONFIG_ROCKCHIP_BOOT_MODE_REG);
board/amazon/kc1/kc1.c +5 -1
index fb1828ff44da..d61a0db7cb62 100644
@@ -8,6 +8,7 @@
 #include <config.h>
 #include <common.h>
 #include <env.h>
+#include <fastboot.h>
 #include <init.h>
 #include <linux/ctype.h>
 #include <linux/usb/musb.h>
@@ -163,8 +164,11 @@ void get_board_serial(struct tag_serialnr *serialnr)
 	omap_die_id_get_board_serial(serialnr);
 }
 
-int fastboot_set_reboot_flag(void)
+int fastboot_set_reboot_flag(int reason)
 {
+	if (reason != FASTBOOT_REBOOT_BOOTLOADER)
+		return -ENOTSUPP;
+
 	return omap_reboot_mode_store("b");
 }
 
board/lg/sniper/sniper.c +5 -1
index 2825eccc035a..cbbe56597e71 100644
@@ -9,6 +9,7 @@
 #include <common.h>
 #include <dm.h>
 #include <env.h>
+#include <fastboot.h>
 #include <init.h>
 #include <linux/ctype.h>
 #include <linux/usb/musb.h>
@@ -175,8 +176,11 @@ void reset_misc(void)
 	omap_reboot_mode_store(reboot_mode);
 }
 
-int fastboot_set_reboot_flag(void)
+int fastboot_set_reboot_flag(int reason)
 {
+	if (reason != FASTBOOT_REBOOT_BOOTLOADER)
+		return -ENOTSUPP;
+
 	return omap_reboot_mode_store("b");
 }
 
board/ti/am57xx/board.c +5 -1
index 8720eb87a55d..28c7e890448c 100644
@@ -9,6 +9,7 @@
 
 #include <common.h>
 #include <env.h>
+#include <fastboot.h>
 #include <fdt_support.h>
 #include <image.h>
 #include <init.h>
@@ -1169,8 +1170,11 @@ int board_fit_config_name_match(const char *name)
 #endif
 
 #if CONFIG_IS_ENABLED(FASTBOOT) && !CONFIG_IS_ENABLED(ENV_IS_NOWHERE)
-int fastboot_set_reboot_flag(void)
+int fastboot_set_reboot_flag(int reason)
 {
+	if (reason != FASTBOOT_REBOOT_BOOTLOADER)
+		return -ENOTSUPP;
+
 	printf("Setting reboot to fastboot flag ...\n");
 	env_set("dofastboot", "1");
 	env_save();
board/ti/dra7xx/evm.c +5 -1
index acf7ff169170..aa53a5e8b7e6 100644
@@ -12,6 +12,7 @@
 #include <common.h>
 #include <env.h>
 #include <fdt_support.h>
+#include <fastboot.h>
 #include <image.h>
 #include <init.h>
 #include <spl.h>
@@ -1050,8 +1051,11 @@ int board_fit_config_name_match(const char *name)
 #endif
 
 #if CONFIG_IS_ENABLED(FASTBOOT) && !CONFIG_IS_ENABLED(ENV_IS_NOWHERE)
-int fastboot_set_reboot_flag(void)
+int fastboot_set_reboot_flag(int reason)
 {
+	if (reason != FASTBOOT_REBOOT_BOOTLOADER)
+		return -ENOTSUPP;
+
 	printf("Setting reboot to fastboot flag ...\n");
 	env_set("dofastboot", "1");
 	env_save();
drivers/fastboot/fb_command.c +39 -1
index 49f6a61c3745..f385aa8e0542 100644
@@ -37,6 +37,8 @@ static void flash(char *, char *);
 static void erase(char *, char *);
 #endif
 static void reboot_bootloader(char *, char *);
+static void reboot_fastbootd(char *, char *);
+static void reboot_recovery(char *, char *);
 #if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT)
 static void oem_format(char *, char *);
 #endif
@@ -79,6 +81,14 @@ static const struct {
 		.command = "reboot-bootloader",
 		.dispatch = reboot_bootloader
 	},
+	[FASTBOOT_COMMAND_REBOOT_FASTBOOTD] =  {
+		.command = "reboot-fastboot",
+		.dispatch = reboot_fastbootd
+	},
+	[FASTBOOT_COMMAND_REBOOT_RECOVERY] =  {
+		.command = "reboot-recovery",
+		.dispatch = reboot_recovery
+	},
 	[FASTBOOT_COMMAND_SET_ACTIVE] =  {
 		.command = "set_active",
 		.dispatch = okay
@@ -307,12 +317,40 @@ static void erase(char *cmd_parameter, char *response)
  */
 static void reboot_bootloader(char *cmd_parameter, char *response)
 {
-	if (fastboot_set_reboot_flag())
+	if (fastboot_set_reboot_flag(FASTBOOT_REBOOT_BOOTLOADER))
 		fastboot_fail("Cannot set reboot flag", response);
 	else
 		fastboot_okay(NULL, response);
 }
 
+/**
+ * reboot_fastbootd() - Sets reboot fastboot flag.
+ *
+ * @cmd_parameter: Pointer to command parameter
+ * @response: Pointer to fastboot response buffer
+ */
+static void reboot_fastbootd(char *cmd_parameter, char *response)
+{
+	if (fastboot_set_reboot_flag(FASTBOOT_REBOOT_FASTBOOTD))
+		fastboot_fail("Cannot set fastboot flag", response);
+	else
+		fastboot_okay(NULL, response);
+}
+
+/**
+ * reboot_recovery() - Sets reboot recovery flag.
+ *
+ * @cmd_parameter: Pointer to command parameter
+ * @response: Pointer to fastboot response buffer
+ */
+static void reboot_recovery(char *cmd_parameter, char *response)
+{
+	if (fastboot_set_reboot_flag(FASTBOOT_REBOOT_RECOVERY))
+		fastboot_fail("Cannot set recovery flag", response);
+	else
+		fastboot_okay(NULL, response);
+}
+
 #if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT)
 /**
  * oem_format() - Execute the OEM format command
drivers/fastboot/fb_common.c +4 -1
index c3735a44af74..012a6288c187 100644
@@ -88,8 +88,11 @@ void fastboot_okay(const char *reason, char *response)
  * which sets whatever flag your board specific Android bootloader flow
  * requires in order to re-enter the bootloader.
  */
-int __weak fastboot_set_reboot_flag(void)
+int __weak fastboot_set_reboot_flag(int reason)
 {
+	if (reason != FASTBOOT_REBOOT_BOOTLOADER)
+		return -ENOTSUPP;
+
 	return -ENOSYS;
 }
 
drivers/usb/gadget/f_fastboot.c +2 -0
index 384c0f6f6e27..30f7a52087fc 100644
@@ -455,6 +455,8 @@ static void rx_handler_command(struct usb_ep *ep, struct usb_request *req)
 
 		case FASTBOOT_COMMAND_REBOOT:
 		case FASTBOOT_COMMAND_REBOOT_BOOTLOADER:
+		case FASTBOOT_COMMAND_REBOOT_FASTBOOTD:
+		case FASTBOOT_COMMAND_REBOOT_RECOVERY:
 			fastboot_func->in_req->complete = compl_do_reset;
 			break;
 		}
include/fastboot.h +12 -1
index 1933b1d98e3b..1830d859afb6 100644
@@ -32,6 +32,8 @@ enum {
 	FASTBOOT_COMMAND_CONTINUE,
 	FASTBOOT_COMMAND_REBOOT,
 	FASTBOOT_COMMAND_REBOOT_BOOTLOADER,
+	FASTBOOT_COMMAND_REBOOT_FASTBOOTD,
+	FASTBOOT_COMMAND_REBOOT_RECOVERY,
 	FASTBOOT_COMMAND_SET_ACTIVE,
 #if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT)
 	FASTBOOT_COMMAND_OEM_FORMAT,
@@ -40,6 +42,15 @@ enum {
 	FASTBOOT_COMMAND_COUNT
 };
 
+/**
+ * Reboot reasons
+ */
+enum {
+	FASTBOOT_REBOOT_BOOTLOADER,
+	FASTBOOT_REBOOT_FASTBOOTD,
+	FASTBOOT_REBOOT_RECOVERY
+};
+
 /**
  * fastboot_response() - Writes a response of the form "$tag$reason".
  *
@@ -77,7 +88,7 @@ void fastboot_okay(const char *reason, char *response);
  * which sets whatever flag your board specific Android bootloader flow
  * requires in order to re-enter the bootloader.
  */
-int fastboot_set_reboot_flag(void);
+int fastboot_set_reboot_flag(int reason);
 
 /**
  * fastboot_set_progress_callback() - set progress callback
net/fastboot.c +2 -0
index 0c57fb9947df..7e7a601b9fe6 100644
@@ -227,6 +227,8 @@ static void fastboot_send(struct fastboot_header header, char *fastboot_data,
 
 		case FASTBOOT_COMMAND_REBOOT:
 		case FASTBOOT_COMMAND_REBOOT_BOOTLOADER:
+		case FASTBOOT_COMMAND_REBOOT_FASTBOOTD:
+		case FASTBOOT_COMMAND_REBOOT_RECOVERY:
 			do_reset(NULL, 0, 0, NULL);
 			break;
 		}
Signature · 1 line
2.17.1
#2 lore raw

PATCH v2 1/2 fastboot: add support for 'reboot fastboot' command

Hi Roman,

??, 4 ???. 2020 ?. ? 10:56, Roman Kovalivskyi
<[email protected]>:

Quoted 269 lines

From: Roman Stratiienko <[email protected]>

Android 10 adds support for dynamic partitions and in order to support this userspace fastboot must be used[1]. New tool fastbootd is included into recovery.

Userspace fastboot works from recovery and is launched if:
1) - Dynamic partitioning is enabled
2) - Boot control block has 'boot-fastboot' value into command field The bootloader is expected to load and boot into the recovery image upon seeing boot-fastboot in the BCB command. Recovery then parses the BCB message and switches to fastbootd mode[2].

Please note that boot script is expected to handle 'boot-fastboot' command in BCB and load into recovery mode.

Bootloader must support 'reboot fastboot' command which should reboot device into userspace fastboot to accomodate those changes[3].

Another command that bootloader must support[3] is 'reboot recovery'. This command should simply reboot device into recovery mode.

[1] - https://source.android.com/devices/bootloader/fastbootd
[2] - https://source.android.com/devices/bootloader/fastbootd#unified_fastboot_and_recovery
[3] - https://source.android.com/devices/bootloader/fastbootd#modifications_to_the_bootloader

Change-Id I9d2bdc9a6f6f31ea98572fe155e1cc8341e9af76
---
 arch/arm/mach-meson/board-common.c |  6 ++++-
 arch/arm/mach-rockchip/board.c     |  6 ++++-
 board/amazon/kc1/kc1.c             |  6 ++++-
 board/lg/sniper/sniper.c           |  6 ++++-
 board/ti/am57xx/board.c            |  6 ++++-
 board/ti/dra7xx/evm.c              |  6 ++++-
 drivers/fastboot/fb_command.c      | 40 +++++++++++++++++++++++++++++-
 drivers/fastboot/fb_common.c       |  5 +++-
 drivers/usb/gadget/f_fastboot.c    |  2 ++
 include/fastboot.h                 | 13 +++++++++-
 net/fastboot.c                     |  2 ++
 11 files changed, 89 insertions(+), 9 deletions(-)
arch/arm/mach-meson/board-common.c +5 -1
index 19e5bfd3660c..ffa0ccf003cf 100644
@@ -5,6 +5,7 @@
 
 #include <common.h>
 #include <cpu_func.h>
+#include <fastboot.h>
 #include <init.h>
 #include <net.h>
 #include <asm/arch/boot.h>
@@ -153,8 +154,11 @@ int board_late_init(void)
 #if CONFIG_IS_ENABLED(FASTBOOT)
 static unsigned int reboot_reason = REBOOT_REASON_NORMAL;
 
-int fastboot_set_reboot_flag()
+int fastboot_set_reboot_flag(int reason)
 {
+       if (reason != FASTBOOT_REBOOT_BOOTLOADER)
+               return -ENOTSUPP;
+
        reboot_reason = REBOOT_REASON_BOOTLOADER;
 
        printf("Using reboot reason: 0x%x\n", reboot_reason);
arch/arm/mach-rockchip/board.c +5 -1
index 430c0cbf41e4..ca9f63bce72c 100644
@@ -6,6 +6,7 @@
 #include <clk.h>
 #include <cpu_func.h>
 #include <dm.h>
+#include <fastboot.h>
 #include <init.h>
 #include <log.h>
 #include <ram.h>
@@ -152,8 +153,11 @@ int board_usb_init(int index, enum usb_init_type init)
 #endif /* CONFIG_USB_GADGET */
 
 #if CONFIG_IS_ENABLED(FASTBOOT)
-int fastboot_set_reboot_flag(void)
+int fastboot_set_reboot_flag(int reason)
 {
+       if (reason != FASTBOOT_REBOOT_BOOTLOADER)
+               return -ENOTSUPP;
+
        printf("Setting reboot to fastboot flag ...\n");
        /* Set boot mode to fastboot */
        writel(BOOT_FASTBOOT, CONFIG_ROCKCHIP_BOOT_MODE_REG);
board/amazon/kc1/kc1.c +5 -1
index fb1828ff44da..d61a0db7cb62 100644
@@ -8,6 +8,7 @@
 #include <config.h>
 #include <common.h>
 #include <env.h>
+#include <fastboot.h>
 #include <init.h>
 #include <linux/ctype.h>
 #include <linux/usb/musb.h>
@@ -163,8 +164,11 @@ void get_board_serial(struct tag_serialnr *serialnr)
        omap_die_id_get_board_serial(serialnr);
 }
 
-int fastboot_set_reboot_flag(void)
+int fastboot_set_reboot_flag(int reason)
 {
+       if (reason != FASTBOOT_REBOOT_BOOTLOADER)
+               return -ENOTSUPP;
+
        return omap_reboot_mode_store("b");
 }
 
board/lg/sniper/sniper.c +5 -1
index 2825eccc035a..cbbe56597e71 100644
@@ -9,6 +9,7 @@
 #include <common.h>
 #include <dm.h>
 #include <env.h>
+#include <fastboot.h>
 #include <init.h>
 #include <linux/ctype.h>
 #include <linux/usb/musb.h>
@@ -175,8 +176,11 @@ void reset_misc(void)
        omap_reboot_mode_store(reboot_mode);
 }
 
-int fastboot_set_reboot_flag(void)
+int fastboot_set_reboot_flag(int reason)
 {
+       if (reason != FASTBOOT_REBOOT_BOOTLOADER)
+               return -ENOTSUPP;
+
        return omap_reboot_mode_store("b");
 }
 
board/ti/am57xx/board.c +5 -1
index 8720eb87a55d..28c7e890448c 100644
@@ -9,6 +9,7 @@
 
 #include <common.h>
 #include <env.h>
+#include <fastboot.h>
 #include <fdt_support.h>
 #include <image.h>
 #include <init.h>
@@ -1169,8 +1170,11 @@ int board_fit_config_name_match(const char *name)
 #endif
 
 #if CONFIG_IS_ENABLED(FASTBOOT) && !CONFIG_IS_ENABLED(ENV_IS_NOWHERE)
-int fastboot_set_reboot_flag(void)
+int fastboot_set_reboot_flag(int reason)
 {
+       if (reason != FASTBOOT_REBOOT_BOOTLOADER)
+               return -ENOTSUPP;
+
        printf("Setting reboot to fastboot flag ...\n");
        env_set("dofastboot", "1");
        env_save();
board/ti/dra7xx/evm.c +5 -1
index acf7ff169170..aa53a5e8b7e6 100644
@@ -12,6 +12,7 @@
 #include <common.h>
 #include <env.h>
 #include <fdt_support.h>
+#include <fastboot.h>
 #include <image.h>
 #include <init.h>
 #include <spl.h>
@@ -1050,8 +1051,11 @@ int board_fit_config_name_match(const char *name)
 #endif
 
 #if CONFIG_IS_ENABLED(FASTBOOT) && !CONFIG_IS_ENABLED(ENV_IS_NOWHERE)
-int fastboot_set_reboot_flag(void)
+int fastboot_set_reboot_flag(int reason)
 {
+       if (reason != FASTBOOT_REBOOT_BOOTLOADER)
+               return -ENOTSUPP;
+
        printf("Setting reboot to fastboot flag ...\n");
        env_set("dofastboot", "1");
        env_save();
drivers/fastboot/fb_command.c +39 -1
index 49f6a61c3745..f385aa8e0542 100644
@@ -37,6 +37,8 @@ static void flash(char *, char *);
 static void erase(char *, char *);
 #endif
 static void reboot_bootloader(char *, char *);
+static void reboot_fastbootd(char *, char *);
+static void reboot_recovery(char *, char *);
 #if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT)
 static void oem_format(char *, char *);
 #endif
@@ -79,6 +81,14 @@ static const struct {
                .command = "reboot-bootloader",
                .dispatch = reboot_bootloader
        },
+       [FASTBOOT_COMMAND_REBOOT_FASTBOOTD] =  {
+               .command = "reboot-fastboot",
+               .dispatch = reboot_fastbootd
+       },
+       [FASTBOOT_COMMAND_REBOOT_RECOVERY] =  {
+               .command = "reboot-recovery",
+               .dispatch = reboot_recovery
+       },
        [FASTBOOT_COMMAND_SET_ACTIVE] =  {
                .command = "set_active",
                .dispatch = okay
@@ -307,12 +317,40 @@ static void erase(char *cmd_parameter, char *response)
  */
 static void reboot_bootloader(char *cmd_parameter, char *response)
 {
-       if (fastboot_set_reboot_flag())
+       if (fastboot_set_reboot_flag(FASTBOOT_REBOOT_BOOTLOADER))
                fastboot_fail("Cannot set reboot flag", response);
        else
                fastboot_okay(NULL, response);
 }
 
+/**
+ * reboot_fastbootd() - Sets reboot fastboot flag.
+ *
+ * @cmd_parameter: Pointer to command parameter
+ * @response: Pointer to fastboot response buffer
+ */
+static void reboot_fastbootd(char *cmd_parameter, char *response)
+{
+       if (fastboot_set_reboot_flag(FASTBOOT_REBOOT_FASTBOOTD))
+               fastboot_fail("Cannot set fastboot flag", response);
+       else
+               fastboot_okay(NULL, response);
+}
+
+/**
+ * reboot_recovery() - Sets reboot recovery flag.
+ *
+ * @cmd_parameter: Pointer to command parameter
+ * @response: Pointer to fastboot response buffer
+ */
+static void reboot_recovery(char *cmd_parameter, char *response)
+{
+       if (fastboot_set_reboot_flag(FASTBOOT_REBOOT_RECOVERY))
+               fastboot_fail("Cannot set recovery flag", response);
+       else
+               fastboot_okay(NULL, response);
+}
+
 #if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT)
 /**
  * oem_format() - Execute the OEM format command
drivers/fastboot/fb_common.c +0 -0
index c3735a44af74..012a6288c187 100644

drivers/fastboot/fb_common.c void fastboot_okay(const char *reason, char *response) · line 95

Quoted 9 lines
drivers/fastboot/fb_common.c +4 -1
@@ -88,8 +88,11 @@ void fastboot_okay(const char *reason, char *response)
  * which sets whatever flag your board specific Android bootloader flow
  * requires in order to re-enter the bootloader.
  */
-int __weak fastboot_set_reboot_flag(void)
+int __weak fastboot_set_reboot_flag(int reason)
 {
+       if (reason != FASTBOOT_REBOOT_BOOTLOADER)
+               return -ENOTSUPP;
+

This check is redundant here. Please remove.

Quoted 30 lines
drivers/fastboot/fb_common.c +0 -0
        return -ENOSYS;
 }
 
drivers/usb/gadget/f_fastboot.c +2 -0
index 384c0f6f6e27..30f7a52087fc 100644
@@ -455,6 +455,8 @@ static void rx_handler_command(struct usb_ep *ep, struct usb_request *req)
 
                case FASTBOOT_COMMAND_REBOOT:
                case FASTBOOT_COMMAND_REBOOT_BOOTLOADER:
+               case FASTBOOT_COMMAND_REBOOT_FASTBOOTD:
+               case FASTBOOT_COMMAND_REBOOT_RECOVERY:
                        fastboot_func->in_req->complete = compl_do_reset;
                        break;
                }
include/fastboot.h +2 -0
index 1933b1d98e3b..1830d859afb6 100644
@@ -32,6 +32,8 @@ enum {
        FASTBOOT_COMMAND_CONTINUE,
        FASTBOOT_COMMAND_REBOOT,
        FASTBOOT_COMMAND_REBOOT_BOOTLOADER,
+       FASTBOOT_COMMAND_REBOOT_FASTBOOTD,
+       FASTBOOT_COMMAND_REBOOT_RECOVERY,
        FASTBOOT_COMMAND_SET_ACTIVE,
 #if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT)
        FASTBOOT_COMMAND_OEM_FORMAT,

include/fastboot.h enum { · line 51

Quoted 10 lines
include/fastboot.h +7 -0
@@ -40,6 +42,15 @@ enum {
        FASTBOOT_COMMAND_COUNT
 };
 
+/**
+ * Reboot reasons
+ */
+enum {
+       FASTBOOT_REBOOT_BOOTLOADER,
+       FASTBOOT_REBOOT_FASTBOOTD,
+       FASTBOOT_REBOOT_RECOVERY

Please put FASTBOOT_REBOOT_REASON_COUNT at the end of the list.

Quoted 30 lines
include/fastboot.h +3 -1
+};
+
 /**
  * fastboot_response() - Writes a response of the form "$tag$reason".
  *
@@ -77,7 +88,7 @@ void fastboot_okay(const char *reason, char *response);
  * which sets whatever flag your board specific Android bootloader flow
  * requires in order to re-enter the bootloader.
  */
-int fastboot_set_reboot_flag(void);
+int fastboot_set_reboot_flag(int reason);
 
 /**
  * fastboot_set_progress_callback() - set progress callback
net/fastboot.c +2 -1
index 0c57fb9947df..7e7a601b9fe6 100644
@@ -227,6 +227,8 @@ static void fastboot_send(struct fastboot_header header, char *fastboot_data,
 
                case FASTBOOT_COMMAND_REBOOT:
                case FASTBOOT_COMMAND_REBOOT_BOOTLOADER:
+               case FASTBOOT_COMMAND_REBOOT_FASTBOOTD:
+               case FASTBOOT_COMMAND_REBOOT_RECOVERY:
                        do_reset(NULL, 0, 0, NULL);
                        break;
                }
--

2.17.1

#3 lore raw

PATCH v2 2/2 fastboot: add default fastboot_set_reboot_flag implementation

In reply to Roman Kovalivskyi

Default implementation of fastboot_set_reboot_flag function that depends on "bcb" commands could be used in general case if there are no need to make any platform-specific implementation, otherwise it could be disabled via Kconfig option FASTBOOT_USE_BCB_SET_REBOOT_FLAG.

Please note that FASTBOOT_USE_BCB_SET_REBOOT_FLAG is mutually exclusive with some platforms which already have their own implementation of this function.

---
 drivers/fastboot/Kconfig     |  9 +++++++++
 drivers/fastboot/fb_common.c | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)
drivers/fastboot/Kconfig +9 -0
index d4436dfc9173..bcb43bc5d556 100644
@@ -165,6 +165,15 @@ config FASTBOOT_CMD_OEM_FORMAT
 	  relies on the env variable partitions to contain the list of
 	  partitions as required by the gpt command.
 
+config FASTBOOT_USE_BCB_SET_REBOOT_FLAG
+	bool "Enable default fastboot_set_reboot_flag implementation"
+	depends on CMD_BCB && !ARCH_MESON && !ARCH_ROCKCHIP && !TARGET_KC1 && \
+		!TARGET_SNIPER && !TARGET_AM57XX_EVM && !TARGET_DRA7XX_EVM
+	default 1
+	help
+		Add default implementation of fastboot_set_reboot_flag that uses
+		"bcb" commands.
+
 endif # FASTBOOT
 
 endmenu
drivers/fastboot/fb_common.c +36 -0
index 012a6288c187..77fe22e88f3d 100644
@@ -88,6 +88,41 @@ void fastboot_okay(const char *reason, char *response)
  * which sets whatever flag your board specific Android bootloader flow
  * requires in order to re-enter the bootloader.
  */
+#if CONFIG_IS_ENABLED(FASTBOOT_USE_BCB_SET_REBOOT_FLAG)
+int fastboot_set_reboot_flag(int reason)
+{
+	char cmd[32];
+
+	snprintf(cmd, sizeof(cmd), "bcb load %d misc",
+		 CONFIG_FASTBOOT_FLASH_MMC_DEV);
+
+	if (run_command(cmd, 0))
+		return -ENODEV;
+
+	switch (reason) {
+	case FASTBOOT_REBOOT_BOOTLOADER:
+		snprintf(cmd, sizeof(cmd),
+			 "bcb set command bootonce-bootloader");
+		break;
+	case FASTBOOT_REBOOT_FASTBOOTD:
+		snprintf(cmd, sizeof(cmd), "bcb set command boot-fastboot");
+		break;
+	case FASTBOOT_REBOOT_RECOVERY:
+		snprintf(cmd, sizeof(cmd), "bcb set command boot-recovery");
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	if (run_command(cmd, 0))
+		return -ENOEXEC;
+
+	if (run_command("bcb store", 0))
+		return -EIO;
+
+	return 0;
+}
+#else
 int __weak fastboot_set_reboot_flag(int reason)
 {
 	if (reason != FASTBOOT_REBOOT_BOOTLOADER)
@@ -95,6 +130,7 @@ int __weak fastboot_set_reboot_flag(int reason)
 
 	return -ENOSYS;
 }
+#endif
 
 /**
  * fastboot_get_progress_callback() - Return progress callback
Signature · 1 line
2.17.1
#4 lore raw

PATCH v2 2/2 fastboot: add default fastboot_set_reboot_flag implementation

Hi Roman,

??, 4 ???. 2020 ?. ? 10:56, Roman Kovalivskyi
<[email protected]>:

Quoted 41 lines

Default implementation of fastboot_set_reboot_flag function that depends on "bcb" commands could be used in general case if there are no need to make any platform-specific implementation, otherwise it could be disabled via Kconfig option FASTBOOT_USE_BCB_SET_REBOOT_FLAG.

Please note that FASTBOOT_USE_BCB_SET_REBOOT_FLAG is mutually exclusive with some platforms which already have their own implementation of this function.

---
 drivers/fastboot/Kconfig     |  9 +++++++++
 drivers/fastboot/fb_common.c | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)
drivers/fastboot/Kconfig +9 -0
index d4436dfc9173..bcb43bc5d556 100644
@@ -165,6 +165,15 @@ config FASTBOOT_CMD_OEM_FORMAT
          relies on the env variable partitions to contain the list of
          partitions as required by the gpt command.
 
+config FASTBOOT_USE_BCB_SET_REBOOT_FLAG
+       bool "Enable default fastboot_set_reboot_flag implementation"
+       depends on CMD_BCB && !ARCH_MESON && !ARCH_ROCKCHIP && !TARGET_KC1 && \
+               !TARGET_SNIPER && !TARGET_AM57XX_EVM && !TARGET_DRA7XX_EVM
+       default 1
+       help
+               Add default implementation of fastboot_set_reboot_flag that uses
+               "bcb" commands.
+
 endif # FASTBOOT
 
 endmenu
drivers/fastboot/fb_common.c +0 -0
index 012a6288c187..77fe22e88f3d 100644

drivers/fastboot/fb_common.c void fastboot_okay(const char *reason, char *response) · line 90

Quoted 3 lines
drivers/fastboot/fb_common.c +0 -0
@@ -88,6 +88,41 @@ void fastboot_okay(const char *reason, char *response)
  * which sets whatever flag your board specific Android bootloader flow
  * requires in order to re-enter the bootloader.
  */

Consider creating an array :
const char *bcb_boot_reason_commands = {"bootonce-bootloader", "boot-fastboot", "boot-recovery");

drivers/fastboot/fb_common.c void fastboot_okay(const char *reason, char *response) · line 95

Quoted 5 lines
drivers/fastboot/fb_common.c +5 -0
+#if CONFIG_IS_ENABLED(FASTBOOT_USE_BCB_SET_REBOOT_FLAG)
+int fastboot_set_reboot_flag(int reason)
+{
+       char cmd[32];
+

Check the reason range is in between 0 to FASTBOOT_REBOOT_REASON_COUNT-1.

Quoted 10 lines
drivers/fastboot/fb_common.c +10 -0
+       snprintf(cmd, sizeof(cmd), "bcb load %d misc",
+                CONFIG_FASTBOOT_FLASH_MMC_DEV);
+
+       if (run_command(cmd, 0))
+               return -ENODEV;
+
+       switch (reason) {
+       case FASTBOOT_REBOOT_BOOTLOADER:
+               snprintf(cmd, sizeof(cmd),
+                        "bcb set command bootonce-bootloader");

drivers/fastboot/fb_common.c void fastboot_okay(const char *reason, char *response) · line 115

Quoted 10 lines
drivers/fastboot/fb_common.c +10 -0
+               break;
+       case FASTBOOT_REBOOT_FASTBOOTD:
+               snprintf(cmd, sizeof(cmd), "bcb set command boot-fastboot");
+               break;
+       case FASTBOOT_REBOOT_RECOVERY:
+               snprintf(cmd, sizeof(cmd), "bcb set command boot-recovery");
+               break;
+       default:
+               return -EINVAL;
+       }

Instead of doing switch-case, consider using:
snprintf(cmd, sizeof(cmd), "bcb set command %s",
bcb_boot_reason_commands[reason]);

Quoted 22 lines
drivers/fastboot/fb_common.c +11 -1
+
+       if (run_command(cmd, 0))
+               return -ENOEXEC;
+
+       if (run_command("bcb store", 0))
+               return -EIO;
+
+       return 0;
+}
+#else
 int __weak fastboot_set_reboot_flag(int reason)
 {
        if (reason != FASTBOOT_REBOOT_BOOTLOADER)
@@ -95,6 +130,7 @@ int __weak fastboot_set_reboot_flag(int reason)
 
        return -ENOSYS;
 }
+#endif
 
 /**
  * fastboot_get_progress_callback() - Return progress callback
--
Quoted 2 lines

2.17.1

Why not move this logic into a separate file?

Regards,
Roman Stratiienko