From d3159c6b18115cb395ec3c8eb539d9471d2bf862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Sat, 9 Oct 2021 19:33:40 +0200 Subject: arm: mvebu: turris_mox: Use show_board_info() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We are printing board information in last_stage_init(), but U-Boot has dedicated function, show_board_info(), for this. Move code which prints board information (board version, serial number, module topology, ...) to show_board_info(). Signed-off-by: Marek Behún Reviewed-by: Stefan Roese --- board/CZ.NIC/turris_mox/turris_mox.c | 67 ++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 34 deletions(-) (limited to 'board') diff --git a/board/CZ.NIC/turris_mox/turris_mox.c b/board/CZ.NIC/turris_mox/turris_mox.c index 428cd23a19..ff0ed28045 100644 --- a/board/CZ.NIC/turris_mox/turris_mox.c +++ b/board/CZ.NIC/turris_mox/turris_mox.c @@ -485,44 +485,34 @@ static void handle_reset_button(void) } } -static void mox_print_info(void) +int show_board_info(void) { - int ret, board_version, ram_size; - u64 serial_number; + int i, ret, board_version, ram_size, is_sd; const char *pub_key; + const u8 *topology; + u64 serial_number; + + printf("Model: CZ.NIC Turris Mox Board\n"); ret = mbox_sp_get_board_info(&serial_number, NULL, NULL, &board_version, &ram_size); - if (ret < 0) - return; - - printf("Turris Mox:\n"); - printf(" Board version: %i\n", board_version); - printf(" RAM size: %i MiB\n", ram_size); - printf(" Serial Number: %016llX\n", serial_number); + if (ret < 0) { + printf(" Cannot read board info: %i\n", ret); + } else { + printf(" Board version: %i\n", board_version); + printf(" RAM size: %i MiB\n", ram_size); + printf(" Serial Number: %016llX\n", serial_number); + } pub_key = mox_sp_get_ecdsa_public_key(); if (pub_key) printf(" ECDSA Public Key: %s\n", pub_key); else - printf("Cannot read ECDSA Public Key\n"); -} - -int last_stage_init(void) -{ - int ret, i; - const u8 *topology; - int is_sd; - struct mii_dev *bus; - struct gpio_desc reset_gpio = {}; - - mox_print_info(); + printf(" Cannot read ECDSA Public Key\n"); ret = mox_get_topology(&topology, &module_count, &is_sd); - if (ret) { + if (ret) printf("Cannot read module topology!\n"); - return 0; - } printf(" SD/eMMC version: %s\n", is_sd ? "SD" : "eMMC"); @@ -554,8 +544,7 @@ int last_stage_init(void) } } - /* now check if modules are connected in supported mode */ - + /* check if modules are connected in supported mode */ for (i = 0; i < module_count; ++i) { switch (topology[i]) { case MOX_MODULE_SFP: @@ -616,8 +605,17 @@ int last_stage_init(void) } } - /* now configure modules */ + if (module_count) + printf("\n"); + + return 0; +} + +int last_stage_init(void) +{ + struct gpio_desc reset_gpio = {}; + /* configure modules */ if (get_reset_gpio(&reset_gpio) < 0) return 0; @@ -633,16 +631,19 @@ int last_stage_init(void) mdelay(50); } + /* + * check if the addresses are set by reading Scratch & Misc register + * 0x70 of Peridot (and potentially Topaz) modules + */ if (peridot || topaz) { - /* - * now check if the addresses are set by reading Scratch & Misc - * register 0x70 of Peridot (and potentially Topaz) modules - */ + struct mii_dev *bus; bus = miiphy_get_dev_by_name("neta@30000"); if (!bus) { printf("Cannot get MDIO bus device!\n"); } else { + int i; + for (i = 0; i < peridot; ++i) check_switch_address(bus, 0x10 + i); @@ -653,8 +654,6 @@ int last_stage_init(void) } } - printf("\n"); - handle_reset_button(); return 0; -- cgit v1.2.3 From f3c71e75b08b7cbe35acc29d89e90c05edd70d40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Sat, 9 Oct 2021 19:33:41 +0200 Subject: arm: mvebu: turris_mox: Always handle reset button MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Handle reset button even if we can't configure modules. This happens if we fail retrieving reset GPIO with which we can reset the modules. (Note that this GPIO is different from reset button GPIO.) Signed-off-by: Marek Behún Reviewed-by: Stefan Roese --- board/CZ.NIC/turris_mox/turris_mox.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'board') diff --git a/board/CZ.NIC/turris_mox/turris_mox.c b/board/CZ.NIC/turris_mox/turris_mox.c index ff0ed28045..7c5acfd1d9 100644 --- a/board/CZ.NIC/turris_mox/turris_mox.c +++ b/board/CZ.NIC/turris_mox/turris_mox.c @@ -617,7 +617,7 @@ int last_stage_init(void) /* configure modules */ if (get_reset_gpio(&reset_gpio) < 0) - return 0; + goto handle_reset_btn; if (peridot > 0) { if (configure_peridots(&reset_gpio) < 0) { @@ -654,6 +654,7 @@ int last_stage_init(void) } } +handle_reset_btn: handle_reset_button(); return 0; -- cgit v1.2.3 From 0034d84a66eaa51263a4881274b75de5b1c4f800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Sat, 9 Oct 2021 19:33:42 +0200 Subject: arm: mvebu: turris_mox: Better check for valid ethernet addresses in env MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently we overwrite ethaddr and eth1addr only if these variables don't exist. Better overwrite them even if the env variable exists, but is invalid - eth_env_get_enetaddr_by_index() checks for validity. Refactor the code to use a for cycle. Signed-off-by: Marek Behún Reviewed-by: Stefan Roese --- board/CZ.NIC/turris_mox/turris_mox.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'board') diff --git a/board/CZ.NIC/turris_mox/turris_mox.c b/board/CZ.NIC/turris_mox/turris_mox.c index 7c5acfd1d9..2202eb8cfb 100644 --- a/board/CZ.NIC/turris_mox/turris_mox.c +++ b/board/CZ.NIC/turris_mox/turris_mox.c @@ -359,20 +359,22 @@ static int get_reset_gpio(struct gpio_desc *reset_gpio) int misc_init_r(void) { - int ret; - u8 mac1[6], mac2[6]; + u8 mac[2][6]; + int i, ret; - ret = mbox_sp_get_board_info(NULL, mac1, mac2, NULL, NULL); + ret = mbox_sp_get_board_info(NULL, mac[0], mac[1], NULL, NULL); if (ret < 0) { printf("Cannot read data from OTP!\n"); return 0; } - if (is_valid_ethaddr(mac1) && !env_get("ethaddr")) - eth_env_set_enetaddr("ethaddr", mac1); + for (i = 0; i < 2; ++i) { + u8 oldmac[6]; - if (is_valid_ethaddr(mac2) && !env_get("eth1addr")) - eth_env_set_enetaddr("eth1addr", mac2); + if (is_valid_ethaddr(mac[i]) && + !eth_env_get_enetaddr_by_index("eth", i, oldmac)) + eth_env_set_enetaddr_by_index("eth", i, mac[i]); + } return 0; } -- cgit v1.2.3 From 1335e31ecc2cd7e4e51b730499198c7548ac0a3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Sat, 9 Oct 2021 19:33:43 +0200 Subject: arm: mvebu: turris_omnia: Overwrite ethaddr only if invalid MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently we always overwrite ethaddrs with those from EEPROM. In order to allow user to use a cloned MAC address in U-Boot, change the code so that it sets ethaddr variables only if they aren't set or are invalid. Signed-off-by: Marek Behún Reviewed-by: Stefan Roese --- board/CZ.NIC/turris_omnia/turris_omnia.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'board') diff --git a/board/CZ.NIC/turris_omnia/turris_omnia.c b/board/CZ.NIC/turris_omnia/turris_omnia.c index a48e1f5c30..7a86111890 100644 --- a/board/CZ.NIC/turris_omnia/turris_omnia.c +++ b/board/CZ.NIC/turris_omnia/turris_omnia.c @@ -518,6 +518,15 @@ static void increment_mac(u8 *mac) } } +static void set_mac_if_invalid(int i, u8 *mac) +{ + u8 oldmac[6]; + + if (is_valid_ethaddr(mac) && + !eth_env_get_enetaddr_by_index("eth", i, oldmac)) + eth_env_set_enetaddr_by_index("eth", i, mac); +} + int misc_init_r(void) { int err; @@ -550,18 +559,11 @@ int misc_init_r(void) mac[4] = mac1[2]; mac[5] = mac1[3]; - if (is_valid_ethaddr(mac)) - eth_env_set_enetaddr("eth1addr", mac); - + set_mac_if_invalid(1, mac); increment_mac(mac); - - if (is_valid_ethaddr(mac)) - eth_env_set_enetaddr("eth2addr", mac); - + set_mac_if_invalid(2, mac); increment_mac(mac); - - if (is_valid_ethaddr(mac)) - eth_env_set_enetaddr("ethaddr", mac); + set_mac_if_invalid(0, mac); out: return 0; -- cgit v1.2.3 From dc096a5e905b1ccd53d8337ec16414ec076602ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Sat, 9 Oct 2021 19:33:44 +0200 Subject: arm: mvebu: turris_omnia: Use show_board_info() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We are printing board information in checkboard() function, which is called from the default weak implementation of show_board_info(). Rename checkboard() to show_board_info(). This throws away the weak implementation of show_board_info(). Signed-off-by: Marek Behún Reviewed-by: Stefan Roese --- board/CZ.NIC/turris_omnia/turris_omnia.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'board') diff --git a/board/CZ.NIC/turris_omnia/turris_omnia.c b/board/CZ.NIC/turris_omnia/turris_omnia.c index 7a86111890..39051a803a 100644 --- a/board/CZ.NIC/turris_omnia/turris_omnia.c +++ b/board/CZ.NIC/turris_omnia/turris_omnia.c @@ -468,7 +468,7 @@ static struct udevice *get_atsha204a_dev(void) return dev; } -int checkboard(void) +int show_board_info(void) { u32 version_num, serial_num; int err = 1; @@ -496,7 +496,7 @@ int checkboard(void) } out: - printf("Turris Omnia:\n"); + printf("Model: Turris Omnia\n"); printf(" RAM size: %i MiB\n", omnia_get_ram_size_gb() * 1024); if (err) printf(" Serial Number: unknown\n"); -- cgit v1.2.3