diff --git a/arch/arm/dts/armada-385-nbhw18-common.dtsi b/arch/arm/dts/armada-385-nbhw18-common.dtsi index 7676f6c607..fa06b40278 100644 --- a/arch/arm/dts/armada-385-nbhw18-common.dtsi +++ b/arch/arm/dts/armada-385-nbhw18-common.dtsi @@ -24,10 +24,6 @@ ethernet3 = ð2; }; - chosen { - stdout-path = "serial0:115200n8"; - }; - memory { device_type = "memory"; reg = <0x00000000 0x40000000>; /* 1 GB */ @@ -141,7 +137,6 @@ pinctrl-names = "default"; pinctrl-0 = <&uart0_pins>; status = "okay"; - u-boot,dm-pre-reloc; }; serial@12100 { diff --git a/arch/arm/dts/armada-385-nbhw18-spl.dts b/arch/arm/dts/armada-385-nbhw18-spl.dts new file mode 100644 index 0000000000..2aab4ccfb9 --- /dev/null +++ b/arch/arm/dts/armada-385-nbhw18-spl.dts @@ -0,0 +1,48 @@ +/* + * Device Tree file for the NetModule NBHW17 (NB2800) base variant + * + * Copyright (C) 2016 NetModule + * + * Stefan Eichenberger + * + * This file is licensed under the terms of the GNU General Public + * License version 2. This program is licensed "as is" without any + * warranty of any kind, whether express or implied. + */ + +/dts-v1/; +#include "armada-385-nbhw18-common.dtsi" + +/ { + model = "NetModule Router NBHW18 with Armada A385 (NB2800)"; + chosen { + stdout-path = "serial0:115200n8"; + }; + + + soc { + internal-regs { + serial@12000 { + u-boot,dm-spl; + }; + }; + }; +}; + +ð0 { + status = "okay"; +}; + +// SFP-Port +ð1 { + status = "disabled"; + fixed-link { + speed = <1000>; + full-duplex; + }; +}; + +ð2 { + status = "okay"; +}; + diff --git a/board/nm/common/nbhw_env.c b/board/nm/common/nbhw_env.c index 3daf5133cd..7a02183135 100644 --- a/board/nm/common/nbhw_env.c +++ b/board/nm/common/nbhw_env.c @@ -1,14 +1,14 @@ #include -#include "fs.h" +#include "nbhw_fileaccess.h" #include "nbhw_bd.h" #define MAX_PARTITION_ENTRIES 8 void find_and_set_active_partition(void) { - u8 boot_partition = bd_get_boot_partition(); - if (boot_partition > 1) { + u8 boot_partition = bd_get_boot_partition(); + if (boot_partition > 1) { boot_partition = 0; } @@ -18,41 +18,23 @@ void find_and_set_active_partition(void) void set_console(void) { - char buf[50] = "\n"; + char buf[50] = "\0"; char *defaultconsole = env_get("defaultconsole"); - - if (defaultconsole == 0) { - /* This is the default console that should be used for e.g. recovery boot */ -#if 0 - /* TODO: fix this */ - sprintf(buf, "ttyS%d", CONFIG_SYS_DUART_CHAN); -#endif - env_set("defaultconsole", buf); - } - + int len = 0; #if defined(CONFIG_PRE_CONSOLE_BUFFER) - /* If consoldev is set take this as productive conosle instead of default console */ - if (fs_set_blk_dev("mmc", "0:3", FS_TYPE_EXT) != 0) { - puts("Error, can not set blk device\n"); - goto use_default_console; - } + read_file_set_blk_dev("mmc", "0:3", FS_TYPE_EXT); - len = fs_read("/root/boot/consoledev", (ulong)buf, 0, 5); + len = read_file("/root/boot/consoledev", buf, 16); if ((len != 5) || (strstr(buf, "tty")!=buf) || ((buf[4]<'0') && (buf[4]>'1'))) { - puts("Using default console\n"); - goto use_default_console; - } - - if (buf[4]=='1') { - CONFIG_SYS_DUART_CHAN = 1; - } else { - CONFIG_SYS_DUART_CHAN = 0; + buf[0] = 0; } use_default_console: - - sprintf(buf, "ttyS%d", CONFIG_SYS_DUART_CHAN); + if (buf[0] == 0) { + strncpy(buf, defaultconsole, sizeof(buf)); + } + printf("consoledev: %s\n", buf); env_set("consoledev", buf); #endif } diff --git a/board/nm/common/nbhw_fileaccess.c b/board/nm/common/nbhw_fileaccess.c index 50ce73c738..acaecb55d7 100644 --- a/board/nm/common/nbhw_fileaccess.c +++ b/board/nm/common/nbhw_fileaccess.c @@ -1,19 +1,47 @@ #include #include +char l_ifname[32]; +char l_dev_part_str[32]; +int l_fstype; + + +void read_file_set_blk_dev(const char *ifname, + const char *dev_part_str, int fstype) +{ + strncpy(l_ifname, ifname, sizeof(l_ifname)); + strncpy(l_dev_part_str, dev_part_str, sizeof(l_dev_part_str)); + l_fstype = fstype; +} + int read_file(const char* filename, char *buf, int size) { loff_t filesize = 0; loff_t len; int ret; + if (fs_set_blk_dev("mmc", "0:3", FS_TYPE_EXT) != 0) { + puts("Error, can not set blk device\n"); + return -1; + } + + /* U-Boot returns an error if size != len therefore + * get first the length... */ if (fs_size(filename, &filesize)) { puts("Can't get filesize\n"); return -1; } - if (filesize < size) + if (filesize < size){ size = filesize; + len = filesize; + } + + /* U-Boot forgets the block device after an action, so do it again ...*/ + if (fs_set_blk_dev("mmc", "0:3", FS_TYPE_EXT) != 0) { + puts("Error, can not set blk device\n"); + return -1; + } if ((ret = fs_read(filename, (ulong)buf, 0, size, &len))) { printf("Can't read file %s (size %d, len %lld, ret %d)\n", filename, size, len, ret); diff --git a/board/nm/common/nbhw_fileaccess.h b/board/nm/common/nbhw_fileaccess.h index 6bfa392aaf..fb2f73a448 100644 --- a/board/nm/common/nbhw_fileaccess.h +++ b/board/nm/common/nbhw_fileaccess.h @@ -10,5 +10,7 @@ #include int read_file(const char* filename, char *buf, int size); +void read_file_set_blk_dev(const char *ifname, + const char *dev_part_str, int fstype); #endif // FILEACCESS_H diff --git a/board/nm/nbhw18_v1/Makefile b/board/nm/nbhw18_v1/Makefile index 62afef2642..529711e28f 100644 --- a/board/nm/nbhw18_v1/Makefile +++ b/board/nm/nbhw18_v1/Makefile @@ -25,4 +25,3 @@ obj-y := board.o nbhw_gpio.o \ ../common/nbhw_bd.o endif - diff --git a/board/nm/nbhw18_v1/board.c b/board/nm/nbhw18_v1/board.c index cd89983d97..ba1347423b 100644 --- a/board/nm/nbhw18_v1/board.c +++ b/board/nm/nbhw18_v1/board.c @@ -16,6 +16,7 @@ #include #include #include +#include #include @@ -86,6 +87,45 @@ static inline int __maybe_unused read_eeprom(void) return _bd_init(); } + +extern int console_init_f(void); + +static int init_console(void) +{ + int ret; + struct udevice *dev; + char *consoledev; + char buf[16] = "serial@12100"; + + debug("init console\n"); + + /* Make sure all devices are probed, it seems + * that this stuff is buggy in U-Boot */ + ret = uclass_first_device(UCLASS_SERIAL, &dev); + if (ret) { + printf("Could not find any serial device\n"); + return ret; + } + + while (list_is_last(&dev->uclass_node, &dev->uclass->dev_head) == 0) { + uclass_next_device(&dev); + } + + + set_console(); + + consoledev = env_get("consoledev"); + if (strncmp(consoledev, "ttyS0", 5) == 0) { + strncpy(buf, "serial@12000", sizeof(buf)); + } + + env_set("stdin", buf); + env_set("stdout", buf); + env_set("stderr", buf); + + return 0; +} + int hws_board_topology_load(struct serdes_map **serdes_map_array, u8 *count) { int i; @@ -199,13 +239,13 @@ void spl_board_init(void) if (err) return; - puts("SPL: select partition\n"); + debug("SPL: select partition\n"); mmcp = find_mmc_device(0); mmc_init(mmcp); printf("Partition found: %p\n", mmcp); /* select boot0 as bootpart */ mmcp->part_config |= (1 << 3); - puts("Partition switched to boot0\n"); + debug("Partition switched to boot0\n"); } static void set_gpios(void) @@ -250,8 +290,6 @@ int board_init(void) if (read_eeprom() < 0) puts("Could not get board ID.\n"); - set_console(); - set_gpios(); /* @@se: With this call we disable a debug feature, that allows one to read out the memory @@ -265,6 +303,29 @@ int board_init(void) return 0; } +int board_early_init_r(void) +{ + /* We need to force mmc_initialization here, so that + * we have mmc available for read of /boot/consoledev */ + mmc_initialize(gd->bd); + /* We need to force the env relocation so that it won't overwritte the + * serial devices that we set in init_console */ + env_relocate(); + gd->env_valid = ENV_VALID; + init_console(); + + return 0; +} + +int misc_init_r(void) +{ + /* Because U-Boot is buggy, we need to call this funktion again + * it will print the pre console buffer */ + console_init_f(); + + return 0; +} + static void set_phy_page(const char *miidev, int phy_addr, int page) { miiphy_write(miidev, phy_addr, 22, page); @@ -284,7 +345,6 @@ static void set_phy_fast_blink_mode(int phy_addr) int board_late_init(void) { - gpio_request(21, "RST_ETH_PHY_N"); gpio_direction_output(21, 0); @@ -313,18 +373,30 @@ int board_network_enable(struct mii_dev *bus) int checkboard(void) { - puts("Board: NetModule NBHW18\n"); + debug("Board: NetModule NBHW18\n"); return 0; } int board_fit_config_name_match(const char *name) { +#ifdef CONFIG_SPL_BUILD + /* SPL has enabled serial0 per default and will output everything + * independend of /boot/consoledev */ +#define DEFAULT_DTB_NAME "armada-385-nbhw18-spl" +#else + /* U-Boot will read /boot/consoledev and based on that it + * enables its own serial console */ +#define DEFAULT_DTB_NAME "armada-385-nbhw18-v1" +#endif + /* Check if name fits our dts */ - return 0; + return strcmp(DEFAULT_DTB_NAME, name); } #ifdef CONFIG_OF_BOARD_FIXUP + + int fdt_enable_by_ofname(void *rw_fdt_blob, char *ofname) { int offset = fdt_path_offset(rw_fdt_blob, ofname); @@ -334,7 +406,9 @@ int fdt_enable_by_ofname(void *rw_fdt_blob, char *ofname) int board_fix_fdt(void *fdt_blob) { - puts("Enable SFP Port\n"); + debug("Enable SFP Port\n"); + return fdt_enable_by_ofname(fdt_blob, "/soc/internal-regs/ethernet@30000"); } + #endif diff --git a/board/nm/nbhw18_v1/nbhw_fpga_config.c b/board/nm/nbhw18_v1/nbhw_fpga_config.c index 7ce6734dca..4573e2dec8 100644 --- a/board/nm/nbhw18_v1/nbhw_fpga_config.c +++ b/board/nm/nbhw18_v1/nbhw_fpga_config.c @@ -1,4 +1,4 @@ -#define DEBUG +#undef DEBUG #include #include #include diff --git a/include/configs/armada-385-nbhw18-v1.h b/include/configs/armada-385-nbhw18-v1.h index acd6b59caf..2a2f9706dc 100644 --- a/include/configs/armada-385-nbhw18-v1.h +++ b/include/configs/armada-385-nbhw18-v1.h @@ -89,7 +89,7 @@ "eth2addr=00:11:22:33:44:56\0" \ "eth3addr=00:11:22:33:44:57\0" \ "ethact=ethernet@34000\0" \ - "add_sd_bootargs=setenv bootargs $bootargs root=/dev/mmcblk0p$root_part rootfstype=ext4 console=ttyS1,115200 rootwait loglevel=4\0" \ + "add_sd_bootargs=setenv bootargs $bootargs root=/dev/mmcblk0p$root_part rootfstype=ext4 console=$consoledev,115200 rootwait loglevel=4\0" \ "add_version_bootargs=setenv bootargs $bootargs\0" \ "fdt_skip_update=yes\0" \ "sdbringup=echo Try bringup boot && ext4load mmc 0:$root_part $kernel_addr /boot/zImage && " \ @@ -114,7 +114,8 @@ "tftptimeoutcountmax=5\0" \ "bootpretryperiod=2000\0" \ "autoload=false\0" \ - "tftp_recovery=tftpboot $kernel_addr recovery-image; tftpboot $fdt_addr recovery-dtb; setenv bootargs rdinit=/etc/preinit console=ttyO1,115200 debug; bootz $kernel_addr - $fdt_addr\0" \ + "defaultconsole=ttyS1\0" \ + "tftp_recovery=tftpboot $kernel_addr recovery-image; tftpboot $fdt_addr recovery-dtb; setenv bootargs rdinit=/etc/preinit console=$defaultconsole,115200 debug; bootz $kernel_addr - $fdt_addr\0" \ "pxe_recovery=sleep 3 && dhcp && pxe get && pxe boot\0" \ "load_fpga=ext4load mmc 0:$root_part $kernel_addr /logic/LG00000000 && nbhw_fpga program lattice 0xffffffff $kernel_addr $filesize && nbhw_fpga configure\0" \ "recovery=run pxe_recovery || setenv ipaddr $ipaddr; setenv serverip $serverip; run tftp_recovery\0" /* setenv ipaddr and serverip is necessary, because dhclient can destroy the IPs inernally */ @@ -145,6 +146,7 @@ #ifdef CONFIG_SPL_BUILD #define CONFIG_SYS_MALLOC_SIMPLE +#define CONFIG_OF_STDOUT_VIA_ALIAS #endif #define CONFIG_SPL_STACK (0x40000000 + ((192 - 16) << 10)) @@ -189,6 +191,12 @@ #undef CONFIG_AUTOBOOT_DELAY_STR #define CONFIG_AUTOBOOT_STOP_STR "s" -#define CONFIG_OF_BOARD_FIXUP +#ifndef CONFIG_SPL_BUILD +#undef CONFIG_REQUIRE_SERIAL_CONSOLE +/* Wee need early init r to actually print the pre console buffer + * because u-boot is buggy */ +#define CONFIG_BOARD_EARLY_INIT_R +#define CONFIG_MISC_INIT_R +#endif #endif /* _CONFIG_DB_88F6820_GP_H */