netbird_v2: fix set defaltconsole

This commit is contained in:
Stefan Eichenberger 2017-11-27 14:52:17 +01:00
parent 9f5e4cd0e9
commit fd055a5672
2 changed files with 37 additions and 34 deletions

View File

@ -80,6 +80,10 @@ static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
static BD_Context bdctx[3]; /* The descriptor context */
#define SHIELD_COM_IO 0
#define SHIELD_DUALCAN 1
static int _bd_init(void)
{
if (bd_get_context(&bdctx[0], BD_EEPROM_ADDR, BD_ADDRESS) != 0) {
@ -482,6 +486,35 @@ static void enable_wlan_clock(void)
#if !defined(CONFIG_SPL_BUILD)
void set_console(void)
{
char buf[8];
char *defaultconsole = getenv("defaultconsole");
int shield_id = bd_get_shield(0);
if (defaultconsole == 0) {
/* Use the default console */
setenv("defaultconsole", "ttyS1\n");
}
/* 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 consoldev is set take this as productive conosle 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);
}
}
static void set_devicetree_name(void)
{
char devicetreename[64];
@ -531,9 +564,6 @@ struct shield_command {
void (*init)(void);
};
#define SHIELD_COM_IO 0
#define SHIELD_DUALCAN 1
static struct shield_command known_shield_commands[] = {
{
SHIELD_COM_IO,
@ -629,13 +659,14 @@ int board_late_init(void)
/* mmcblk0p1 => root0, mmcblk0p2 => root1 so +1 */
setenv_ulong("root_part", boot_partition + 1);
fs_set_console();
check_reset_button();
get_hw_version();
set_devicetree_name();
set_console();
#endif
#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG

View File

@ -16,7 +16,7 @@ int read_file(const char* filename, char *buf, int size)
}
/* File does not exist, do not print an error message */
/* File does not exist, do not print an error message */
if (fs_size(filename, &filesize)) {
return -1;
}
@ -36,36 +36,8 @@ int read_file(const char* filename, char *buf, int size)
return -1;
}
buf[len] = 0;
buf[len] = 0;
return len;
}
void fs_set_console(void)
{
loff_t len;
char buf[50] = "\n";
char *defaultconsole = getenv("defaultconsole");
if (defaultconsole == 0) {
/* This is the default console that should be used for e.g. recovery boot */
sprintf(buf, "ttyS1");
setenv("defaultconsole", buf);
}
/* If consoldev is set take this as productive conosle instead of default console */
if (fs_set_blk_dev("mmc", OVERLAY_PART, FS_TYPE_EXT) != 0) {
puts("Error, can not set blk device\n");
return;
}
fs_read("/root/boot/consoledev", (ulong)buf, 0, 5, &len);
if ((len != 5) || (strstr(buf, "tty")!=buf) || ((buf[4]<'0') && (buf[4]>'1'))) {
puts("Using default console\n");
return;
}
setenv("defaultconsoel", buf);
}