From 2a61175aa2ae9acb28da8fba56dd0f34ddeac3c9 Mon Sep 17 00:00:00 2001 From: Rene Straub Date: Thu, 10 Oct 2019 17:36:59 +0200 Subject: [PATCH] nmhw24: align board file with nrsw implementation --- board/nm/nrhw24/board.c | 148 +++++++++++++++++++++++++--------------- 1 file changed, 93 insertions(+), 55 deletions(-) diff --git a/board/nm/nrhw24/board.c b/board/nm/nrhw24/board.c index 74c6fed09e..88cff4444f 100644 --- a/board/nm/nrhw24/board.c +++ b/board/nm/nrhw24/board.c @@ -40,6 +40,11 @@ #include "shield_comio.h" #include "fileaccess.h" + +/* TODO: place in proper header file */ +extern void serial_set_console_index(int index); + + DECLARE_GLOBAL_DATA_PTR; /* @@ -238,26 +243,22 @@ static inline int __maybe_unused read_eeprom(void) */ struct serial_device *default_serial_console(void) { - /* Mux pins for selected UART properly. - * Note: uart indexes start at 0 while - * eserial indexes start at 1. + /* + * Mux pins for selected UART properly. + * Note: UART indexes start at 0 while eserial indexes start at 1. + * + * Provide console on internal UART1 regardless of boot mode. + * This only has a side effect when using X-Modem boot */ - - /* Provide UART on UART2 regardless of boot mode */ - enable_uart1_pin_mux(); - return &eserial2_device; - -#if 0 /* TODO: Check whether really required */ - if ((spl_boot_device() == BOOT_DEVICE_UART) || - (spl_boot_device() == BOOT_DEVICE_JTAG)) { + if (spl_boot_device() == BOOT_DEVICE_UART) { + /* Continue booting from UART in case of serial (xmodem) boot */ enable_uart0_pin_mux(); return &eserial1_device; } else { - /* Use internal uart, if no output shall be seen. */ + /* Regular and JTAG boot use internal UART1 */ enable_uart1_pin_mux(); return &eserial2_device; } -#endif } #ifndef CONFIG_SKIP_LOWLEVEL_INIT @@ -347,6 +348,8 @@ struct reset_registers { uint32_t value_crc; }; +#ifdef CONFIG_NRSW + /* TODO: Move ethernet crc to dedicated file */ static uint32_t ether_crc(size_t len, uint8_t const *p) { @@ -394,6 +397,8 @@ void check_pmic_reset_reason(unsigned int reset_reason_shm_location) da9063_release_i2c_bus(bus); } +#endif + void am33xx_spl_board_init(void) { /* Set CPU speed to 600 MHz (fix) */ @@ -415,7 +420,10 @@ void am33xx_spl_board_init(void) /* Set MPU Frequency to what we detected now that voltages are set */ do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100); +#ifdef CONFIG_NRSW + /* TODO: Move to board_late_init? It is not urgent to have this in SPL. */ check_pmic_reset_reason(RESET_REASON_SHM_LOCATION); +#endif /* Debugger can place marker at end of SRAM to stop boot here */ if (is_jtag_boot(CONFIG_JTAG_MARKER_SPL)) @@ -567,6 +575,7 @@ static void init_gnss(void) REQUEST_AND_SET_GPIO(GPIO_RST_GNSS); } +/* TODO: Double Check - WiFi is enabled by sequencer already */ static void init_wifi(void) { int bus; @@ -600,7 +609,7 @@ int board_init(void) /* Let user know we're starting */ init_leds(); set_status_led(1, 1); /* Orange */ - set_indicator_led(1, 1); /* Orange */ + set_indicator_led(0, 0); /* Off */ printf("OSC: %lu MHz\n", get_osclk()/1000000); @@ -609,32 +618,31 @@ int board_init(void) #if !defined(CONFIG_SPL_BUILD) -/* TODO: Move to top of file or place into header file */ -extern int console_init_f(void); -extern void serial_set_console_index(int index); - /* * Set Linux console based on * - Selection in /root/boot/consoledev * - Available tty interfaces * - ttyS1: standard console (default, internal only) - * - ttyS0: COMIO shield (or used as console by kernel, + * - ttyS0: COM/IO shield (or used as console by kernel, * when no other console available) * - ttyNull0: Dummy device if no real UART is available */ void set_console(void) { const char *defaultconsole = getenv("defaultconsole"); + int shield_id = bd_get_shield(0); /* Set default console to ttyS1 if not yet defined in env */ if (defaultconsole == 0) { setenv("defaultconsole", "ttyS1"); } - /* Always use internal console for u-boot - as comio shield is not ready at that time. - (Needs to be initialized first using the - shieldcmd that is run by bootcmd.) */ + /* + * Always use internal console for u-boot + * as COM/IO shield is not ready at that time. + * (Needs to be initialized first using the + * shieldcmd that is run by bootcmd.) + */ serial_set_console_index(1); #if defined(CONFIG_PRE_CONSOLE_BUFFER) @@ -642,31 +650,33 @@ void set_console(void) console_init_f(); /* stage 1 init of console */ #endif -#if 0 - if (shield_id != SHIELD_COM_IO) { - /* Don't allow changing to ttyS0 for the kernel console, because - * ttyS0 is not available if no comio shield is populated. */ - return; - } + if (shield_id == SHIELD_COM_IO) { + char buf[20]; - /* With comio shield the defaultconsole for the kernel should - be ttyS0 and not ttyS1 */ - setenv("defaultconsole", "ttyS0"); + /* + * With COM/IO shield the defaultconsole for the kernel should + * be ttyS0 (external port). + * If consoledev file is present, take the tty defined in it as console + */ + setenv("defaultconsole", "ttyS0"); - /* If consoledev file is present, take the tty defined in it as console */ - if (read_file("/root/boot/consoledev",buf, sizeof(buf)) > 3) { - if (strstr(buf, "tty") == buf) { - buf[sizeof(buf)-1] = 0; - for (i=0; i 3) { + if (strstr(buf, "tty") == buf) { + int i; + /* TODO: What is this code doing? */ + /* Truncating after whitespace? */ + /* are there broken consoledev files around ? */ + buf[sizeof(buf)-1] = 0; + for (i=0; iname); @@ -836,6 +858,7 @@ static void shield_config(void) shieldcmd = shieldcmd_linux; } +end: setenv("shieldcmd", shieldcmd); } @@ -862,13 +885,24 @@ static bool get_button_state(void) return pressed; } -static void blink_led(void) +static void blink_led(int pulses) { const int pulse_width = 400*1000; /* 400ms */ - /* Assumes status LED is orange */ - udelay(pulse_width); - set_status_led(0, 0); /* Off */ + /* Assumed status led on, indicator off */ + set_status_led(0, 0); + + while (pulses) { + udelay(pulse_width); + set_status_led(1, 1); + set_indicator_led(1, 1); + + udelay(pulse_width); + set_status_led(0, 0); + set_indicator_led(0, 0); + + pulses--; + } udelay(pulse_width); set_status_led(1, 1); /* Orange */ @@ -888,12 +922,11 @@ static void check_reset_button(void) if (counter == 2000) { /* Indicate factory reset threshold */ - blink_led(); + blink_led(1); } else if (counter == 12000) { /* Indicate recovery boot threshold */ - blink_led(); - blink_led(); + blink_led(2); } } while (counter < 12000); @@ -920,6 +953,7 @@ static void check_reset_button(void) /* Boot into recovery for duration > 12s */ puts("Booting recovery image...\n"); + /* TODO: ... internal .. port on HW24 */ /* Set consoledev to external port */ setenv("defaultconsole", "ttyS1"); @@ -964,9 +998,6 @@ int board_late_init(void) set_console(); shield_init(); - set_status_led(1, 1); /* Orange */ - set_indicator_led(0, 0); /* Off */ - check_fct(); check_jtag_boot(); #endif @@ -1165,8 +1196,15 @@ int ft_board_setup(void *blob, bd_t *bd) { ft_bootloader_version(blob); ft_hw_info(blob); + ft_shields(blob); + /* + * Enable uart1 (ttyS0) always as kernel needs it as fallback console, + * if (ttyS1) is not available as console. + */ + ft_enable_node(blob, "/ocp/serial@44e09000"); + return 0; }