summaryrefslogtreecommitdiff
path: root/drivers/usb/gadget
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/gadget')
-rw-r--r--drivers/usb/gadget/bcb.h9
-rw-r--r--drivers/usb/gadget/command.c47
-rw-r--r--drivers/usb/gadget/f_fastboot.c70
3 files changed, 76 insertions, 50 deletions
diff --git a/drivers/usb/gadget/bcb.h b/drivers/usb/gadget/bcb.h
index f0bd83b..705c572 100644
--- a/drivers/usb/gadget/bcb.h
+++ b/drivers/usb/gadget/bcb.h
@@ -9,6 +9,11 @@
#include <linux/types.h>
#include <linux/stat.h>
+#define FASTBOOT_BCB_CMD "bootonce-bootloader"
+#ifdef CONFIG_ANDROID_RECOVERY
+#define RECOVERY_BCB_CMD "boot-recovery"
+#endif
+
/* keep same as bootable/recovery/bootloader.h */
struct bootloader_message {
char command[32];
@@ -49,4 +54,8 @@ int rw_block(bool bread, char **ppblock,
uint *pblksize, char *pblock_write, uint offset, uint size);
void set_mmc_id(unsigned int id);
+
+int bcb_write_command(char *bcb_command);
+
+int bcb_read_command(char *command);
#endif
diff --git a/drivers/usb/gadget/command.c b/drivers/usb/gadget/command.c
index 3af3fcf..686065a 100644
--- a/drivers/usb/gadget/command.c
+++ b/drivers/usb/gadget/command.c
@@ -9,8 +9,7 @@
#include "bcb.h"
#ifndef CONFIG_FASTBOOT_STORAGE_NAND
-static char command[32];
-static int read_command(char *command)
+int bcb_read_command(char *command)
{
int ret = 0;
char *p_block = NULL;
@@ -31,7 +30,8 @@ static int read_command(char *command)
return 0;
}
-static int write_command(char *bcb_command)
+
+int bcb_write_command(char *bcb_command)
{
int ret = 0;
char *p_block = NULL;
@@ -61,45 +61,4 @@ static int write_command(char *bcb_command)
free(p_block);
return 0;
}
-
-int recovery_check_and_clean_command(void)
-{
- int ret;
- ret = read_command(command);
- if (ret < 0) {
- printf("read command failed\n");
- return 0;
- }
- if (!strcmp(command, "boot-recovery")) {
- memset(command, 0, 32);
- write_command(command);
- return 1;
- }
- return 0;
-}
-int fastboot_check_and_clean_command(void)
-{
- int ret;
- ret = read_command(command);
- if (ret < 0) {
- printf("read command failed\n");
- return 0;
- }
- if (!strcmp(command, "boot-bootloader")) {
- memset(command, 0, 32);
- write_command(command);
- return 1;
- }
-
- return 0;
-}
-#else
-int recovery_check_and_clean_command(void)
-{
- return 0;
-}
-int fastboot_check_and_clean_command(void)
-{
- return 0;
-}
#endif
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index 26af6b5..00b6c8e 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -1742,21 +1742,79 @@ void fastboot_setup(void)
/*load partitions information for the fastboot dev*/
_fastboot_load_partitions();
- /*check if we need to setup recovery*/
+ parameters_setup();
+}
+
+/* Write the bcb with fastboot bootloader commands */
+static void enable_fastboot_command(void)
+{
+ char fastboot_command[32];
+ memcpy(fastboot_command, FASTBOOT_BCB_CMD, 32);
+ bcb_write_command(fastboot_command);
+}
+
+/* Get the Boot mode from BCB cmd or Key pressed */
+static FbBootMode fastboot_get_bootmode(void)
+{
+ int ret = 0;
+ int boot_mode = BOOTMODE_NORMAL;
+ char command[32];
+
#ifdef CONFIG_ANDROID_RECOVERY
- check_recovery_mode();
+ if(is_recovery_key_pressing()) {
+ boot_mode = BOOTMODE_RECOVERY_KEY_PRESSED;
+ return boot_mode;
+ }
#endif
- parameters_setup();
+ ret = bcb_read_command(command);
+ if (ret < 0) {
+ printf("read command failed\n");
+ return boot_mode;
+ }
+ if (!strcmp(command, FASTBOOT_BCB_CMD)) {
+ memset(command, 0, 32);
+ bcb_write_command(command);
+ boot_mode = BOOTMODE_FASTBOOT_BCB_CMD;
+ }
+#ifdef CONFIG_ANDROID_RECOVERY
+ else if (!strcmp(command, RECOVERY_BCB_CMD)) {
+ memset(command, 0, 32);
+ bcb_write_command(command);
+ boot_mode = BOOTMODE_RECOVERY_BCB_CMD;
+ }
+#endif
+
+ return boot_mode;
}
/* export to lib_arm/board.c */
-void check_fastboot(void)
+void fastboot_run_bootmode(void)
{
- if (fastboot_check_and_clean_flag())
+ FbBootMode boot_mode = fastboot_get_bootmode();
+ switch(boot_mode){
+ case BOOTMODE_FASTBOOT_BCB_CMD:
+ /* Make the boot into fastboot mode*/
+ puts("Fastboot: Got bootloader commands!\n");
run_command("fastboot", 0);
+ break;
+#ifdef CONFIG_ANDROID_RECOVERY
+ case BOOTMODE_RECOVERY_BCB_CMD:
+ case BOOTMODE_RECOVERY_KEY_PRESSED:
+ /* Make the boot into recovery mode */
+ puts("Fastboot: Got Recovery key pressing or recovery commands!\n");
+ board_recovery_setup();
+ break;
+#endif
+ default:
+ /* skip special mode boot*/
+ puts("Fastboot: Normal\n");
+ break;
+ }
}
+
+
#ifdef CONFIG_CMD_BOOTA
/* Section for Android bootimage format support
* Refer:
@@ -3093,7 +3151,7 @@ static void cb_reboot_bootloader(struct usb_ep *ep, struct usb_request *req)
fastboot_tx_write_str("OKAY");
udelay(1000000);
- fastboot_enable_flag();
+ enable_fastboot_command();
do_reset(NULL, 0, 0, NULL);
}
#endif