From d8fd5953c0c39722868853b359c876ff090ba28f Mon Sep 17 00:00:00 2001 From: Stefan Eichenberger Date: Mon, 27 Nov 2017 15:51:14 +0000 Subject: [PATCH] FIX: [uboot] fix defaultconsole if comio shield is available BugzId: 48404 SVN commit 25481@trunk --- board/nm/netbird_v2/board.c | 39 ++++++++++++++++++++++++++++---- board/nm/netbird_v2/fileaccess.c | 32 ++------------------------ 2 files changed, 37 insertions(+), 34 deletions(-) diff --git a/board/nm/netbird_v2/board.c b/board/nm/netbird_v2/board.c index d4a8ca1085..d4db2b5316 100644 --- a/board/nm/netbird_v2/board.c +++ b/board/nm/netbird_v2/board.c @@ -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 diff --git a/board/nm/netbird_v2/fileaccess.c b/board/nm/netbird_v2/fileaccess.c index 58bcb9f582..78723ac1e2 100644 --- a/board/nm/netbird_v2/fileaccess.c +++ b/board/nm/netbird_v2/fileaccess.c @@ -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); -} -