nrhw20: add shield support

- use OF library to enable shield nodes in devicetree
- delete command line based devicetree configuration
- add console configuration options for COMIO shield
This commit is contained in:
Rene Straub 2018-07-19 15:21:21 +02:00 committed by Marcel Reichmuth
parent 88c11d6396
commit 56df92f9f9
2 changed files with 94 additions and 51 deletions

View File

@ -32,6 +32,7 @@
#include <cpsw.h> #include <cpsw.h>
#include <environment.h> #include <environment.h>
#include <watchdog.h> #include <watchdog.h>
#include <libfdt.h>
#include "../common/bdparser.h" #include "../common/bdparser.h"
#include "../common/board_descriptor.h" #include "../common/board_descriptor.h"
@ -520,44 +521,30 @@ int board_init(void)
#if !defined(CONFIG_SPL_BUILD) #if !defined(CONFIG_SPL_BUILD)
// TODO: Check tty logic with NRSW team /*
// UART1: Fixed to mains connector, always present * Set Linux console based on
// UART0: Mapped to shield slot * - Selection in /root/boot/consoledev
// Can only be used when shield is installed * - Available tty interfaces
* - ttyS1: standard console (default)
* - ttyS0: COM/IO shield
*/
void set_console(void) void set_console(void)
{ {
#if 0
int shield_id = bd_get_shield(0);
char buf[8];
#endif
const char *defaultconsole = getenv("defaultconsole"); const char *defaultconsole = getenv("defaultconsole");
char buf[8];
/* Set default console to ttyS1 if not yet defined in env */
if (defaultconsole == 0) { if (defaultconsole == 0) {
/* Use the default console */
setenv("defaultconsole", "ttyS1"); setenv("defaultconsole", "ttyS1");
} }
#if 0 /* If consoledev file is present, take the tty defined in it as console */
/* Don't allow changing to ttyS0 because ttyS0 is not available in the if (read_file("/root/boot/consoledev",buf, 5) == 5) {
* kernel if no comio shield is available */ if (strstr(buf, "tty") == buf) {
if (shield_id != SHIELD_COM_IO) { buf[5] = 0;
return; 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) 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 { struct shield_command {
int shield_id; int shield_id;
const char *name; const char *name;
const char *default_shieldcmd; const char *default_shieldcmd;
const char *fdtshieldcmd;
void (*init)(void); void (*init)(void);
}; };
@ -642,18 +623,12 @@ static struct shield_command known_shield_commands[] = {
SHIELD_COM_IO, SHIELD_COM_IO,
"comio", "comio",
"shield comio mode rs232", "shield comio mode rs232",
"fdt get value serial0 /aliases serial0;" \
"fdt set $serial0 status okay",
comio_shield_init comio_shield_init
}, },
{ {
SHIELD_DUALCAN, SHIELD_DUALCAN,
"dualcan", "dualcan",
"shield dualcan termination off off", "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 can_shield_init
}, },
}; };
@ -692,7 +667,7 @@ static void shield_config(void)
return; return;
} }
printf("Shield: %s\n", cmd->name); printf("Shield:%s\n", cmd->name);
cmd->init(); cmd->init();
shieldcmd = cmd->default_shieldcmd; shieldcmd = cmd->default_shieldcmd;
@ -707,8 +682,6 @@ static void shield_config(void)
} }
setenv("shieldcmd", shieldcmd); setenv("shieldcmd", shieldcmd);
set_fdtshieldcmd(cmd->fdtshieldcmd);
} }
static void shield_init(void) static void shield_init(void)
@ -787,11 +760,11 @@ static void check_reset_button(void)
printf("Booting recovery image...\n"); printf("Booting recovery image...\n");
/* Set consoledev to external port */
setenv("defaultconsole", "ttyS1");
/* Set bootcmd to run recovery */ /* Set bootcmd to run recovery */
setenv("bootcmd", "run recovery"); setenv("bootcmd", "run recovery");
/* set consoledev to external port */
/* setenv("consoledev", "ttyS1"); */
} }
} }
#endif /* !defined(CONFIG_SPL_BUILD) */ #endif /* !defined(CONFIG_SPL_BUILD) */
@ -952,3 +925,73 @@ int board_fit_config_name_match(const char *name)
return 0; return 0;
} }
#endif #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

View File

@ -76,7 +76,7 @@
"sdboot=if mmc dev 1; then echo Copying Linux from SD to RAM...; "\ "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; " \ "if test -e mmc 1:$root_part /boot/$kernel_image; then run sdprod; " \
"else run sdbringup; fi; " \ "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" \ "bootz $kernel_addr - $fdt_addr; fi\0" \
"bootcmd=run sdboot\0" \ "bootcmd=run sdboot\0" \
"ipaddr=192.168.1.1\0" \ "ipaddr=192.168.1.1\0" \
@ -93,11 +93,9 @@
"bootpretryperiod=2000\0" \ "bootpretryperiod=2000\0" \
"autoload=false\0" \ "autoload=false\0" \
"shieldcmd=\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; " \ "tftp_recovery=tftpboot $kernel_addr recovery-image; tftpboot $fdt_addr recovery-dtb; " \
"setenv bootargs rdinit=/etc/preinit console=$defaultconsole,115200 " \ "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" \ "bootz $kernel_addr - $fdt_addr\0" \
"pxe_recovery=sleep 3 && dhcp && pxe get && pxe boot\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" \ "recovery=run pxe_recovery || setenv ipaddr $ipaddr; setenv serverip $serverip; run tftp_recovery\0" \
@ -235,6 +233,8 @@
#define CONFIG_CMD_PXE #define CONFIG_CMD_PXE
#define CONFIG_OF_BOARD_SETUP
/* SPL command is not needed */ /* SPL command is not needed */
#undef CONFIG_CMD_SPL #undef CONFIG_CMD_SPL