diff options
Diffstat (limited to 'drivers/usb/gadget')
-rw-r--r-- | drivers/usb/gadget/command.c | 87 | ||||
-rw-r--r-- | drivers/usb/gadget/f_fastboot.c | 12 |
2 files changed, 76 insertions, 23 deletions
diff --git a/drivers/usb/gadget/command.c b/drivers/usb/gadget/command.c index 3af3fcf..9693022 100644 --- a/drivers/usb/gadget/command.c +++ b/drivers/usb/gadget/command.c @@ -6,10 +6,13 @@ #include <common.h> #include <g_dnl.h> +#ifdef CONFIG_FASTBOOT_STORAGE_NAND +#include <nand.h> +#endif #include "bcb.h" -#ifndef CONFIG_FASTBOOT_STORAGE_NAND static char command[32]; +#ifndef CONFIG_FASTBOOT_STORAGE_NAND static int read_command(char *command) { int ret = 0; @@ -62,44 +65,94 @@ static int write_command(char *bcb_command) return 0; } -int recovery_check_and_clean_command(void) +#else +#define ALIGN_BYTES 64 +#define MISC_PAGES 3 +static int read_command(char *command) +{ + char read_cmd[128]; + char *addr_str; + char *nand_str; + ulong misc_info_size; + nand_info_t *nand = &nand_info[0]; + if (command == NULL) + return -1; + memset(read_cmd, 0, 128); + misc_info_size = MISC_PAGES * nand->writesize; + nand_str = (char *)memalign(ALIGN_BYTES, misc_info_size); + sprintf(read_cmd, "nand read 0x%x ${misc_nand_offset} \ + 0x%x", nand_str, misc_info_size); + run_command(read_cmd, 0); + /* The offset of bootloader_message is 1 PAGE. + The offset of bootloader_message and the size of misc info + need align with user space and recovery. + */ + addr_str = nand_str + nand->writesize; + memcpy(command, (char *)addr_str, 32); + free(nand_str); + return 0; +} +static int write_command(char *command) +{ + char cmd[128]; + char *addr_str; + char *nand_str; + ulong misc_info_size; + nand_info_t *nand = &nand_info[0]; + if (command == NULL) + return -1; + memset(cmd, 0, 128); + misc_info_size = MISC_PAGES * nand->writesize; + nand_str = (char *)memalign(ALIGN_BYTES, misc_info_size); + sprintf(cmd, "nand read 0x%x ${misc_nand_offset} \ + 0x%x", nand_str, misc_info_size); + run_command(cmd, 0); + /* the offset of bootloader_message is 1 PAGE*/ + addr_str = nand_str + nand->writesize; + memcpy((char *)addr_str, command, 32); + /* erase 3 pages which hold BCB struct.*/ + sprintf(cmd, "nand erase ${misc_nand_offset} 0x%x",nand->erasesize); + run_command(cmd, 0); + sprintf(cmd, "nand write 0x%x ${misc_nand_offset} 0x%x",nand_str, misc_info_size); + run_command(cmd, 0); + free(nand_str); + return 0; +} +#endif +bool recovery_check_and_clean_command(void) { int ret; ret = read_command(command); if (ret < 0) { printf("read command failed\n"); - return 0; + return false; } if (!strcmp(command, "boot-recovery")) { memset(command, 0, 32); write_command(command); - return 1; + return true; } - return 0; + return false; } -int fastboot_check_and_clean_command(void) +bool fastboot_check_and_clean_command(void) { int ret; ret = read_command(command); if (ret < 0) { printf("read command failed\n"); - return 0; + return false; } if (!strcmp(command, "boot-bootloader")) { memset(command, 0, 32); write_command(command); - return 1; + return true; } - return 0; + return false; } -#else -int recovery_check_and_clean_command(void) -{ - return 0; -} -int fastboot_check_and_clean_command(void) +void fastboot_enable_command(void) { - return 0; + char fastboot_command[32]; + memcpy(fastboot_command,"boot-bootloader",32); + write_command(fastboot_command); } -#endif diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index 89b5f24..42fd5ac 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -1565,21 +1565,21 @@ void fastboot_setup(void) /*get the fastboot dev*/ _fastboot_setup_dev(); + /*load partitions information for the fastboot dev*/ + _fastboot_load_partitions(); + /*check if we need to setup recovery*/ #ifdef CONFIG_ANDROID_RECOVERY - check_recovery_mode(); + check_recovery_mode(); #endif - /*load partitions information for the fastboot dev*/ - _fastboot_load_partitions(); - parameters_setup(); } /* export to lib_arm/board.c */ void check_fastboot(void) { - if (fastboot_check_and_clean_flag()) + if (fastboot_check_and_clean_command()) run_command("fastboot", 0); } @@ -2640,7 +2640,7 @@ static void cb_reboot_bootloader(struct usb_ep *ep, struct usb_request *req) fastboot_tx_write_str("OKAY"); udelay(1000000); - fastboot_enable_flag(); + fastboot_enable_command(); do_reset(NULL, 0, 0, NULL); } #endif |