From 7e7ca0c85847e0b7eff094710cc5167df4e852da Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Sat, 29 Dec 2018 10:37:47 -0500 Subject: Fix Xduoo X3 bootloader build, and silence all warnings. Also enable USB bootloader mode Change-Id: I73224c2e694b9941993c89a114b48d2a907e0dfb --- bootloader/xduoox3.c | 34 ++++++- firmware/export/config/xduoox3.h | 1 + firmware/target/mips/ingenic_jz47xx/debug-jz4760.c | 103 +++++++++++++++++++++ .../mips/ingenic_jz47xx/xduoo_x3/sadc-xduoo_x3.c | 4 +- 4 files changed, 136 insertions(+), 6 deletions(-) diff --git a/bootloader/xduoox3.c b/bootloader/xduoox3.c index 3db87a866d..d38639bfd4 100644 --- a/bootloader/xduoox3.c +++ b/bootloader/xduoox3.c @@ -44,6 +44,7 @@ extern void show_logo(void); extern void power_off(void); +#ifdef HAVE_BOOTLOADER_USB_MODE static void show_splash(int timeout, const char *msg) { reset_screen(); @@ -88,6 +89,7 @@ static void usb_mode(void) } } } +#endif static int boot_rockbox(void) { @@ -95,11 +97,17 @@ static int boot_rockbox(void) void (*kernel_entry)(void); printf("Mounting disk...\n"); - rc = disk_mount_all(); - if (rc <= 0) + + while((rc = disk_mount_all()) <= 0) { verbose = true; - error(EDISK,rc, true); +#ifdef HAVE_BOOTLOADER_USB_MODE + error(EDISK, rc, false); + usb_start_monitoring(); + usb_mode(); +#else + error(EDISK, rc, true); +#endif } printf("Loading firmware...\n"); @@ -119,6 +127,7 @@ static int boot_rockbox(void) } } +#if 0 static void reset_configuration(void) { int rc; @@ -135,6 +144,7 @@ static void reset_configuration(void) else show_splash(HZ/2, "Couldn't reset configuration!"); } +#endif int main(void) { @@ -151,8 +161,6 @@ int main(void) show_logo(); - filesystem_init(); - rc = storage_init(); if(rc) { @@ -160,6 +168,22 @@ int main(void) error(EATA, rc, true); } + filesystem_init(); + +#ifdef HAVE_BOOTLOADER_USB_MODE + button_init_device(); + int btn = button_read_device(); + + usb_init(); + + /* Enter USB mode if USB is plugged and PLAY button is pressed */ + if(btn & BUTTON_PLAY) { + usb_start_monitoring(); + if(usb_detect() == USB_INSERTED) + usb_mode(); + } +#endif /* HAVE_BOOTLOADER_USB_MODE */ + /* Don't mount the disks yet, there could be file system/partition errors which are fixable in USB mode */ diff --git a/firmware/export/config/xduoox3.h b/firmware/export/config/xduoox3.h index 6a7f33c842..d4d6f2ee2f 100644 --- a/firmware/export/config/xduoox3.h +++ b/firmware/export/config/xduoox3.h @@ -163,6 +163,7 @@ /* enable these for the experimental usb stack */ #define HAVE_USBSTACK +#define HAVE_BOOTLOADER_USB_MODE /* Connect by events, not by tick polling */ #define USB_STATUS_BY_EVENT diff --git a/firmware/target/mips/ingenic_jz47xx/debug-jz4760.c b/firmware/target/mips/ingenic_jz47xx/debug-jz4760.c index 848fa5343e..ffd9faaf60 100644 --- a/firmware/target/mips/ingenic_jz47xx/debug-jz4760.c +++ b/firmware/target/mips/ingenic_jz47xx/debug-jz4760.c @@ -169,3 +169,106 @@ bool dbg_hw_info(void) } return true; } + +#define CFG_UART_BASE UART1_BASE /* Base of the UART channel */ + +void serial_putc (const char c) +{ + volatile u8 *uart_lsr = (volatile u8 *)(CFG_UART_BASE + OFF_LSR); + volatile u8 *uart_tdr = (volatile u8 *)(CFG_UART_BASE + OFF_TDR); + + if (c == '\n') serial_putc ('\r'); + + /* Wait for fifo to shift out some bytes */ + while ( !((*uart_lsr & (UARTLSR_TDRQ | UARTLSR_TEMT)) == 0x60) ); + + *uart_tdr = (u8)c; +} + +void serial_puts (const char *s) +{ + while (*s) { + serial_putc (*s++); + } +} + +void serial_putsf(const char *format, ...) +{ + static char printfbuf[256]; + int len; + unsigned char *ptr; + va_list ap; + va_start(ap, format); + + ptr = printfbuf; + len = vsnprintf(ptr, sizeof(printfbuf), format, ap); + va_end(ap); + (void)len; + + serial_puts(ptr); + serial_putc('\n'); +} + +void serial_put_hex(unsigned int d) +{ + char c[12]; + int i; + for(i = 0; i < 8;i++) + { + c[i] = (d >> ((7 - i) * 4)) & 0xf; + if(c[i] < 10) + c[i] += 0x30; + else + c[i] += (0x41 - 10); + } + c[8] = '\n'; + c[9] = 0; + serial_puts(c); + +} +void serial_put_dec(unsigned int d) +{ + char c[16]; + int i; + int j = 0; + int x = d; + + while (x /= 10) + j++; + + for (i = j; i >= 0; i--) { + c[i] = d % 10; + c[i] += 0x30; + d /= 10; + } + c[j + 1] = '\n'; + c[j + 2] = 0; + serial_puts(c); +} + +void serial_dump_data(unsigned char* data, int len) +{ + int i; + for(i=0; i>4) & 0xf; + if(a < 10) + a += 0x30; + else + a += (0x41 - 10); + serial_putc( a ); + + a = (*data) & 0xf; + if(a < 10) + a += 0x30; + else + a += (0x41 - 10); + serial_putc( a ); + + serial_putc( ' ' ); + + data++; + } + + serial_putc( '\n' ); +} diff --git a/firmware/target/mips/ingenic_jz47xx/xduoo_x3/sadc-xduoo_x3.c b/firmware/target/mips/ingenic_jz47xx/xduoo_x3/sadc-xduoo_x3.c index 16d5aab782..be02167a5d 100644 --- a/firmware/target/mips/ingenic_jz47xx/xduoo_x3/sadc-xduoo_x3.c +++ b/firmware/target/mips/ingenic_jz47xx/xduoo_x3/sadc-xduoo_x3.c @@ -18,7 +18,7 @@ * KIND, either express or implied. * ****************************************************************************/ - + #include "config.h" #include "system.h" #include "cpu.h" @@ -86,11 +86,13 @@ bool button_hold(void) int button_read_device(void) { +#ifndef BOOTLOADER static bool hold_button = false; bool hold_button_old; hold_button_old = hold_button; hold_button = (__gpio_get_pin(PIN_BTN_HOLD) ? true : false); +#endif int btn = BUTTON_NONE; bool gpio_btn = (__gpio_get_pin(PIN_BTN_POWER) ? false : true); -- cgit v1.2.3