summaryrefslogtreecommitdiff
path: root/drivers/usb/gadget/command.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/gadget/command.c')
-rw-r--r--drivers/usb/gadget/command.c87
1 files changed, 70 insertions, 17 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