diff --git a/board/nm/nrhw20/board.c b/board/nm/nrhw20/board.c index e23055eda8..fe046c9b31 100644 --- a/board/nm/nrhw20/board.c +++ b/board/nm/nrhw20/board.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "../common/bdparser.h" #include "../common/board_descriptor.h" @@ -520,44 +521,30 @@ int board_init(void) #if !defined(CONFIG_SPL_BUILD) -// TODO: Check tty logic with NRSW team -// UART1: Fixed to mains connector, always present -// UART0: Mapped to shield slot -// Can only be used when shield is installed +/* + * Set Linux console based on + * - Selection in /root/boot/consoledev + * - Available tty interfaces + * - ttyS1: standard console (default) + * - ttyS0: COM/IO shield + */ void set_console(void) { -#if 0 - int shield_id = bd_get_shield(0); - char buf[8]; -#endif const char *defaultconsole = getenv("defaultconsole"); + char buf[8]; + /* Set default console to ttyS1 if not yet defined in env */ if (defaultconsole == 0) { - /* Use the default console */ setenv("defaultconsole", "ttyS1"); } -#if 0 - /* Don't allow changing to ttyS0 because ttyS0 is not available in the - * kernel if no comio shield is available */ - if (shield_id != SHIELD_COM_IO) { - return; + /* If consoledev file is present, take the tty defined in it as console */ + if (read_file("/root/boot/consoledev",buf, 5) == 5) { + if (strstr(buf, "tty") == buf) { + buf[5] = 0; + setenv("defaultconsole", buf); + } } - - /* With comio shield the defaultconsole should be ttyS0 and not ttyS1 */ - setenv("defaultconsole", "ttyS0"); - - /* If consoledev is set, take this as productive console instead of default console */ - if (read_file("/root/boot/consoledev", buf, 5) != 5) { - puts("Invalid file consoledev\n"); - return; - } - - if (strstr(buf, "tty")==buf) { - buf[5] = 0; - setenv("defaultconsole", buf); - } -#endif } static void set_devicetree_name(void) @@ -624,16 +611,10 @@ static void check_fct(void) } -static void set_fdtshieldcmd(const char *fdt_cmd) -{ - setenv("fdtshieldcmd", fdt_cmd); -} - struct shield_command { int shield_id; const char *name; const char *default_shieldcmd; - const char *fdtshieldcmd; void (*init)(void); }; @@ -642,18 +623,12 @@ static struct shield_command known_shield_commands[] = { SHIELD_COM_IO, "comio", "shield comio mode rs232", - "fdt get value serial0 /aliases serial0;" \ - "fdt set $serial0 status okay", comio_shield_init }, { SHIELD_DUALCAN, "dualcan", "shield dualcan termination off off", - "fdt get value can0 /aliases d_can0;" \ - "fdt get value can1 /aliases d_can1;" \ - "fdt set $can0 status okay;" \ - "fdt set $can1 status okay;", can_shield_init }, }; @@ -692,7 +667,7 @@ static void shield_config(void) return; } - printf("Shield: %s\n", cmd->name); + printf("Shield:%s\n", cmd->name); cmd->init(); shieldcmd = cmd->default_shieldcmd; @@ -707,8 +682,6 @@ static void shield_config(void) } setenv("shieldcmd", shieldcmd); - - set_fdtshieldcmd(cmd->fdtshieldcmd); } static void shield_init(void) @@ -787,11 +760,11 @@ static void check_reset_button(void) printf("Booting recovery image...\n"); + /* Set consoledev to external port */ + setenv("defaultconsole", "ttyS1"); + /* Set bootcmd to run recovery */ setenv("bootcmd", "run recovery"); - - /* set consoledev to external port */ - /* setenv("consoledev", "ttyS1"); */ } } #endif /* !defined(CONFIG_SPL_BUILD) */ @@ -952,3 +925,73 @@ int board_fit_config_name_match(const char *name) return 0; } #endif + +#if defined(CONFIG_OF_BOARD_SETUP) + +static void ft_enable_node(void* blob, const char* name) +{ + int node_ofs = -1; + + node_ofs = fdt_path_offset(blob, name); + if (node_ofs >= 0) { + fdt_setprop_string(blob, node_ofs, "status", "okay"); + } +} + +static void ft_dio(void *blob, int shield_type) +{ + switch (shield_type) { + /* If COM/IO shield is present enable its I/Os */ + case SHIELD_COM_IO: + ft_enable_node(blob, "/netbox_dio_comio"); + break; + + default: + ft_enable_node(blob, "/netbox_dio_default"); + break; + } +} + +static void ft_serial(void *blob, int shield_type) +{ + switch (shield_type) { + /* If COM/IO shield is present enable uart1 (ttyS0) */ + case SHIELD_COM_IO: + /* TODO: Should use alias serial0 */ + ft_enable_node(blob, "/ocp/serial@44e09000"); + break; + + default: + break; + } +} + +static void ft_dcan(void *blob, int shield_type) +{ + switch (shield_type) { + /* If Dual CAN shield is present enable dcan0, dcan1N1 */ + case SHIELD_DUALCAN: + /* TODO: Should use alias d_can0, d_can1 */ + ft_enable_node(blob, "/ocp/can@481cc000"); + ft_enable_node(blob, "/ocp/can@481d0000"); + break; + + default: + break; + } +} + +int ft_board_setup(void *blob, bd_t *bd) +{ + int shield_type = -1; + + shield_type = bd_get_shield(0); + + ft_dio(blob, shield_type); + ft_serial(blob, shield_type); + ft_dcan(blob, shield_type); + + return 0; +} + +#endif diff --git a/include/configs/am335x_nrhw20.h b/include/configs/am335x_nrhw20.h index d2708acb24..4b92c384a7 100755 --- a/include/configs/am335x_nrhw20.h +++ b/include/configs/am335x_nrhw20.h @@ -76,7 +76,7 @@ "sdboot=if mmc dev 1; then echo Copying Linux from SD to RAM...; "\ "if test -e mmc 1:$root_part /boot/$kernel_image; then run sdprod; " \ "else run sdbringup; fi; " \ - "run add_sd_bootargs; run add_version_bootargs; run shieldcmd; run modifyfdtcmd; " \ + "run add_sd_bootargs; run add_version_bootargs; run shieldcmd; " \ "bootz $kernel_addr - $fdt_addr; fi\0" \ "bootcmd=run sdboot\0" \ "ipaddr=192.168.1.1\0" \ @@ -93,11 +93,9 @@ "bootpretryperiod=2000\0" \ "autoload=false\0" \ "shieldcmd=\0" \ - "fdtshieldcmd=\0" \ - "modifyfdtcmd=fdt addr $fdt_addr; run fdtshieldcmd;\0" \ "tftp_recovery=tftpboot $kernel_addr recovery-image; tftpboot $fdt_addr recovery-dtb; " \ "setenv bootargs rdinit=/etc/preinit console=$defaultconsole,115200 " \ - "debug ti_cpsw.rx_packet_max=1526; run shieldcmd; run modifyfdtcmd; " \ + "debug ti_cpsw.rx_packet_max=1526; run shieldcmd; " \ "bootz $kernel_addr - $fdt_addr\0" \ "pxe_recovery=sleep 3 && dhcp && pxe get && pxe boot\0" \ "recovery=run pxe_recovery || setenv ipaddr $ipaddr; setenv serverip $serverip; run tftp_recovery\0" \ @@ -235,6 +233,8 @@ #define CONFIG_CMD_PXE +#define CONFIG_OF_BOARD_SETUP + /* SPL command is not needed */ #undef CONFIG_CMD_SPL