From a37b68820c432ff9b0b3dab597d94f7bbfa5d1e2 Mon Sep 17 00:00:00 2001 From: Rogier Stam Date: Wed, 9 Feb 2022 00:27:00 +0100 Subject: arm: mvebu: Fix Espressobin build for configs where ENV is not in SPI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When storing the UBoot Environment in for example EXT4, the U-Boot build is broken for several reasons: 1. armada-385-turris-omnia-u-boot.dtsi will not allow CONFIG_ENV_OFFSET and CONFIG_ENV_SIZE to be undefined 2. armada-37xx/board.c ft_board_setup function does not exist if CONFIG_ENV_IS_IN_SPI_FLASH is not defined This commit changes these files so that selecting a different location for the environment is possible. Signed-off-by: Rogier Stam Reviewed-by: Pali Rohár --- board/Marvell/mvebu_armada-37xx/board.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'board') diff --git a/board/Marvell/mvebu_armada-37xx/board.c b/board/Marvell/mvebu_armada-37xx/board.c index 6bfec0cc5bf..98e1b36d11b 100644 --- a/board/Marvell/mvebu_armada-37xx/board.c +++ b/board/Marvell/mvebu_armada-37xx/board.c @@ -328,9 +328,10 @@ int board_network_enable(struct mii_dev *bus) return 0; } -#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_ENV_IS_IN_SPI_FLASH) +#ifdef CONFIG_OF_BOARD_SETUP int ft_board_setup(void *blob, struct bd_info *bd) { +#ifdef CONFIG_ENV_IS_IN_SPI_FLASH int ret; int spi_off; int parts_off; @@ -424,6 +425,7 @@ int ft_board_setup(void *blob, struct bd_info *bd) return 0; } +#endif return 0; } #endif -- cgit v1.3.1 From 46ce9c78a99814639763d8ea9ac1bf7354b6ea8d Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Wed, 23 Feb 2022 14:15:47 +0100 Subject: arm: mvebu: a37xx: Move generic mbox code to arch/arm/mach-mvebu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Generic A3720 mbox code is currently in Turris Mox specific board file board/CZ.NIC/turris_mox/mox_sp.c. Move it to board independent arch file arch/arm/mach-mvebu/armada3700/mbox.c. Signed-off-by: Pali Rohár Reviewed-by: Marek Behún Reviewed-by: Stefan Roese --- arch/arm/mach-mvebu/armada3700/Makefile | 2 +- arch/arm/mach-mvebu/armada3700/mbox.c | 67 ++++++++++++++++++++++++++++++++ arch/arm/mach-mvebu/include/mach/mbox.h | 23 +++++++++++ board/CZ.NIC/turris_mox/mox_sp.c | 69 +-------------------------------- 4 files changed, 92 insertions(+), 69 deletions(-) create mode 100644 arch/arm/mach-mvebu/armada3700/mbox.c create mode 100644 arch/arm/mach-mvebu/include/mach/mbox.h (limited to 'board') diff --git a/arch/arm/mach-mvebu/armada3700/Makefile b/arch/arm/mach-mvebu/armada3700/Makefile index cd74726cc77..98350a41e04 100644 --- a/arch/arm/mach-mvebu/armada3700/Makefile +++ b/arch/arm/mach-mvebu/armada3700/Makefile @@ -2,5 +2,5 @@ # # Copyright (C) 2016 Stefan Roese -obj-y = cpu.o +obj-y = cpu.o mbox.o obj-$(CONFIG_MVEBU_EFUSE) += efuse.o diff --git a/arch/arm/mach-mvebu/armada3700/mbox.c b/arch/arm/mach-mvebu/armada3700/mbox.c new file mode 100644 index 00000000000..cb86b967c2e --- /dev/null +++ b/arch/arm/mach-mvebu/armada3700/mbox.c @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2018 Marek Behun + */ + +#include +#include +#include +#include +#include +#include + +#define RWTM_BASE (MVEBU_REGISTER(0xb0000)) +#define RWTM_CMD_PARAM(i) (size_t)(RWTM_BASE + (i) * 4) +#define RWTM_CMD (RWTM_BASE + 0x40) +#define RWTM_CMD_RETSTATUS (RWTM_BASE + 0x80) +#define RWTM_CMD_STATUS(i) (size_t)(RWTM_BASE + 0x84 + (i) * 4) + +#define RWTM_HOST_INT_RESET (RWTM_BASE + 0xc8) +#define RWTM_HOST_INT_MASK (RWTM_BASE + 0xcc) +#define SP_CMD_COMPLETE BIT(0) + +#define MBOX_STS_SUCCESS (0x0 << 30) +#define MBOX_STS_FAIL (0x1 << 30) +#define MBOX_STS_BADCMD (0x2 << 30) +#define MBOX_STS_LATER (0x3 << 30) +#define MBOX_STS_ERROR(s) ((s) & (3 << 30)) +#define MBOX_STS_VALUE(s) (((s) >> 10) & 0xfffff) +#define MBOX_STS_CMD(s) ((s) & 0x3ff) + +int mbox_do_cmd(enum mbox_cmd cmd, u32 *out, int nout) +{ + const int tries = 50; + int i; + u32 status; + + clrbits_le32(RWTM_HOST_INT_MASK, SP_CMD_COMPLETE); + + writel(cmd, RWTM_CMD); + + for (i = 0; i < tries; ++i) { + mdelay(10); + if (readl(RWTM_HOST_INT_RESET) & SP_CMD_COMPLETE) + break; + } + + if (i == tries) { + /* if timed out, don't read status */ + setbits_le32(RWTM_HOST_INT_RESET, SP_CMD_COMPLETE); + return -ETIMEDOUT; + } + + for (i = 0; i < nout; ++i) + out[i] = readl(RWTM_CMD_STATUS(i)); + status = readl(RWTM_CMD_RETSTATUS); + + setbits_le32(RWTM_HOST_INT_RESET, SP_CMD_COMPLETE); + + if (MBOX_STS_CMD(status) != cmd) + return -EIO; + else if (MBOX_STS_ERROR(status) == MBOX_STS_FAIL) + return -(int)MBOX_STS_VALUE(status); + else if (MBOX_STS_ERROR(status) != MBOX_STS_SUCCESS) + return -EIO; + else + return MBOX_STS_VALUE(status); +} diff --git a/arch/arm/mach-mvebu/include/mach/mbox.h b/arch/arm/mach-mvebu/include/mach/mbox.h new file mode 100644 index 00000000000..98120493583 --- /dev/null +++ b/arch/arm/mach-mvebu/include/mach/mbox.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (C) 2018 Marek Behun + */ + +#ifndef _MVEBU_MBOX_H +#define _MVEBU_MBOX_H + +enum mbox_cmd { + MBOX_CMD_GET_RANDOM = 1, + MBOX_CMD_BOARD_INFO, + MBOX_CMD_ECDSA_PUB_KEY, + MBOX_CMD_HASH, + MBOX_CMD_SIGN, + MBOX_CMD_VERIFY, + + MBOX_CMD_OTP_READ, + MBOX_CMD_OTP_WRITE, +}; + +int mbox_do_cmd(enum mbox_cmd cmd, u32 *in, int nout); + +#endif diff --git a/board/CZ.NIC/turris_mox/mox_sp.c b/board/CZ.NIC/turris_mox/mox_sp.c index cc57b9f095f..4de067bbebb 100644 --- a/board/CZ.NIC/turris_mox/mox_sp.c +++ b/board/CZ.NIC/turris_mox/mox_sp.c @@ -8,74 +8,7 @@ #include #include #include - -#define RWTM_BASE (MVEBU_REGISTER(0xb0000)) -#define RWTM_CMD_PARAM(i) (size_t)(RWTM_BASE + (i) * 4) -#define RWTM_CMD (RWTM_BASE + 0x40) -#define RWTM_CMD_RETSTATUS (RWTM_BASE + 0x80) -#define RWTM_CMD_STATUS(i) (size_t)(RWTM_BASE + 0x84 + (i) * 4) - -#define RWTM_HOST_INT_RESET (RWTM_BASE + 0xc8) -#define RWTM_HOST_INT_MASK (RWTM_BASE + 0xcc) -#define SP_CMD_COMPLETE BIT(0) - -#define MBOX_STS_SUCCESS (0x0 << 30) -#define MBOX_STS_FAIL (0x1 << 30) -#define MBOX_STS_BADCMD (0x2 << 30) -#define MBOX_STS_LATER (0x3 << 30) -#define MBOX_STS_ERROR(s) ((s) & (3 << 30)) -#define MBOX_STS_VALUE(s) (((s) >> 10) & 0xfffff) -#define MBOX_STS_CMD(s) ((s) & 0x3ff) - -enum mbox_cmd { - MBOX_CMD_GET_RANDOM = 1, - MBOX_CMD_BOARD_INFO, - MBOX_CMD_ECDSA_PUB_KEY, - MBOX_CMD_HASH, - MBOX_CMD_SIGN, - MBOX_CMD_VERIFY, - - MBOX_CMD_OTP_READ, - MBOX_CMD_OTP_WRITE -}; - -static int mbox_do_cmd(enum mbox_cmd cmd, u32 *out, int nout) -{ - const int tries = 50; - int i; - u32 status; - - clrbits_le32(RWTM_HOST_INT_MASK, SP_CMD_COMPLETE); - - writel(cmd, RWTM_CMD); - - for (i = 0; i < tries; ++i) { - mdelay(10); - if (readl(RWTM_HOST_INT_RESET) & SP_CMD_COMPLETE) - break; - } - - if (i == tries) { - /* if timed out, don't read status */ - setbits_le32(RWTM_HOST_INT_RESET, SP_CMD_COMPLETE); - return -ETIMEDOUT; - } - - for (i = 0; i < nout; ++i) - out[i] = readl(RWTM_CMD_STATUS(i)); - status = readl(RWTM_CMD_RETSTATUS); - - setbits_le32(RWTM_HOST_INT_RESET, SP_CMD_COMPLETE); - - if (MBOX_STS_CMD(status) != cmd) - return -EIO; - else if (MBOX_STS_ERROR(status) == MBOX_STS_FAIL) - return -(int)MBOX_STS_VALUE(status); - else if (MBOX_STS_ERROR(status) != MBOX_STS_SUCCESS) - return -EIO; - else - return MBOX_STS_VALUE(status); -} +#include const char *mox_sp_get_ecdsa_public_key(void) { -- cgit v1.3.1 From 85df8f9a211610d4406e644061220b5e2fd221c7 Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Wed, 23 Feb 2022 14:15:48 +0100 Subject: arm: mvebu: a37xx: Extend mbox_do_cmd() code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow to specify input parameters, define all available mbox commands supported by CZ.NIC's secure firmware and also Marvell's fuse.bin firmware and fix parsing response from Marvell OTP commands. Signed-off-by: Pali Rohár Reviewed-by: Marek Behún Reviewed-by: Stefan Roese --- arch/arm/mach-mvebu/armada3700/mbox.c | 20 ++++++++++++++++++-- arch/arm/mach-mvebu/include/mach/mbox.h | 19 ++++++++++++++++++- board/CZ.NIC/turris_mox/mox_sp.c | 4 ++-- 3 files changed, 38 insertions(+), 5 deletions(-) (limited to 'board') diff --git a/arch/arm/mach-mvebu/armada3700/mbox.c b/arch/arm/mach-mvebu/armada3700/mbox.c index cb86b967c2e..eb1f82845f0 100644 --- a/arch/arm/mach-mvebu/armada3700/mbox.c +++ b/arch/arm/mach-mvebu/armada3700/mbox.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0+ /* * Copyright (C) 2018 Marek Behun + * Copyright (C) 2021 Pali Rohár */ #include @@ -15,6 +16,7 @@ #define RWTM_CMD (RWTM_BASE + 0x40) #define RWTM_CMD_RETSTATUS (RWTM_BASE + 0x80) #define RWTM_CMD_STATUS(i) (size_t)(RWTM_BASE + 0x84 + (i) * 4) +#define MAX_ARGS 16 #define RWTM_HOST_INT_RESET (RWTM_BASE + 0xc8) #define RWTM_HOST_INT_MASK (RWTM_BASE + 0xcc) @@ -27,15 +29,27 @@ #define MBOX_STS_ERROR(s) ((s) & (3 << 30)) #define MBOX_STS_VALUE(s) (((s) >> 10) & 0xfffff) #define MBOX_STS_CMD(s) ((s) & 0x3ff) +#define MBOX_STS_MARVELL_ERROR(s) ((s) == 0 ? 0 : \ + (s) == 2 ? ETIMEDOUT : \ + (s) == 3 ? EINVAL : \ + (s) == 4 ? ENOSYS : \ + EIO) -int mbox_do_cmd(enum mbox_cmd cmd, u32 *out, int nout) +int mbox_do_cmd(enum mbox_cmd cmd, u32 *in, int nin, u32 *out, int nout) { const int tries = 50; int i; u32 status; + if (nin > MAX_ARGS || nout > MAX_ARGS) + return -EINVAL; + clrbits_le32(RWTM_HOST_INT_MASK, SP_CMD_COMPLETE); + for (i = 0; i < nin; i++) + writel(in[i], RWTM_CMD_PARAM(i)); + for (; i < MAX_ARGS; i++) + writel(0x0, RWTM_CMD_PARAM(i)); writel(cmd, RWTM_CMD); for (i = 0; i < tries; ++i) { @@ -57,9 +71,11 @@ int mbox_do_cmd(enum mbox_cmd cmd, u32 *out, int nout) setbits_le32(RWTM_HOST_INT_RESET, SP_CMD_COMPLETE); if (MBOX_STS_CMD(status) != cmd) - return -EIO; + return -MBOX_STS_MARVELL_ERROR(status); else if (MBOX_STS_ERROR(status) == MBOX_STS_FAIL) return -(int)MBOX_STS_VALUE(status); + else if (MBOX_STS_ERROR(status) == MBOX_STS_BADCMD) + return -ENOSYS; else if (MBOX_STS_ERROR(status) != MBOX_STS_SUCCESS) return -EIO; else diff --git a/arch/arm/mach-mvebu/include/mach/mbox.h b/arch/arm/mach-mvebu/include/mach/mbox.h index 98120493583..f1cb55f2bfe 100644 --- a/arch/arm/mach-mvebu/include/mach/mbox.h +++ b/arch/arm/mach-mvebu/include/mach/mbox.h @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0+ */ /* * Copyright (C) 2018 Marek Behun + * Copyright (C) 2021 Pali Rohár */ #ifndef _MVEBU_MBOX_H @@ -16,8 +17,24 @@ enum mbox_cmd { MBOX_CMD_OTP_READ, MBOX_CMD_OTP_WRITE, + + MBOX_CMD_REBOOT, + + /* OTP read commands supported by Marvell fuse.bin firmware */ + MBOX_CMD_OTP_READ_1B = 257, + MBOX_CMD_OTP_READ_8B, + MBOX_CMD_OTP_READ_32B, + MBOX_CMD_OTP_READ_64B, + MBOX_CMD_OTP_READ_256B, + + /* OTP write commands supported by Marvell fuse.bin firmware */ + MBOX_CMD_OTP_WRITE_1B = 513, + MBOX_CMD_OTP_WRITE_8B, + MBOX_CMD_OTP_WRITE_32B, + MBOX_CMD_OTP_WRITE_64B, + MBOX_CMD_OTP_WRITE_256B, }; -int mbox_do_cmd(enum mbox_cmd cmd, u32 *in, int nout); +int mbox_do_cmd(enum mbox_cmd cmd, u32 *in, int nin, u32 *out, int nout); #endif diff --git a/board/CZ.NIC/turris_mox/mox_sp.c b/board/CZ.NIC/turris_mox/mox_sp.c index 4de067bbebb..93e96b014fc 100644 --- a/board/CZ.NIC/turris_mox/mox_sp.c +++ b/board/CZ.NIC/turris_mox/mox_sp.c @@ -19,7 +19,7 @@ const char *mox_sp_get_ecdsa_public_key(void) if (public_key[0]) return public_key; - res = mbox_do_cmd(MBOX_CMD_ECDSA_PUB_KEY, out, 16); + res = mbox_do_cmd(MBOX_CMD_ECDSA_PUB_KEY, NULL, 0, out, 16); if (res < 0) return NULL; @@ -47,7 +47,7 @@ int mbox_sp_get_board_info(u64 *sn, u8 *mac1, u8 *mac2, int *bv, int *ram) u32 out[8]; int res; - res = mbox_do_cmd(MBOX_CMD_BOARD_INFO, out, 8); + res = mbox_do_cmd(MBOX_CMD_BOARD_INFO, NULL, 0, out, 8); if (res < 0) return res; -- cgit v1.3.1 From 6ac08dc1a83d786d8749525df32c94b94bb36123 Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Fri, 8 Apr 2022 16:30:12 +0200 Subject: board: turris: Move Turris Atsha OTP code to separate file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OTP code is not Atsha generic but also it is not Omnia specific. It is common for all Turris routers which use Atsha cryptochip for storing OTP. So move this common Turris specific Atsha OTP code from Turris Omnia into separate file. It will be used also by other Turris routers. Signed-off-by: Pali Rohár Reviewed-by: Marek Behún --- board/CZ.NIC/turris_atsha_otp.c | 121 +++++++++++++++++++++++++++++++ board/CZ.NIC/turris_atsha_otp.h | 9 +++ board/CZ.NIC/turris_omnia/Makefile | 2 +- board/CZ.NIC/turris_omnia/turris_omnia.c | 108 +-------------------------- 4 files changed, 135 insertions(+), 105 deletions(-) create mode 100644 board/CZ.NIC/turris_atsha_otp.c create mode 100644 board/CZ.NIC/turris_atsha_otp.h (limited to 'board') diff --git a/board/CZ.NIC/turris_atsha_otp.c b/board/CZ.NIC/turris_atsha_otp.c new file mode 100644 index 00000000000..a4a77c74fb1 --- /dev/null +++ b/board/CZ.NIC/turris_atsha_otp.c @@ -0,0 +1,121 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2017 Marek Behun + * Copyright (C) 2016 Tomas Hlavacek + */ + +#include +#include +#include +#include + +#include "turris_atsha_otp.h" + +#define TURRIS_ATSHA_OTP_VERSION 0 +#define TURRIS_ATSHA_OTP_SERIAL 1 +#define TURRIS_ATSHA_OTP_MAC0 3 +#define TURRIS_ATSHA_OTP_MAC1 4 + +static struct udevice *get_atsha204a_dev(void) +{ + static struct udevice *dev; + + if (dev) + return dev; + + if (uclass_get_device_by_name(UCLASS_MISC, "atsha204a@64", &dev)) { + puts("Cannot find ATSHA204A on I2C bus!\n"); + dev = NULL; + } + + return dev; +} + +static void increment_mac(u8 *mac) +{ + int i; + + for (i = 5; i >= 3; i--) { + mac[i] += 1; + if (mac[i]) + break; + } +} + +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 turris_atsha_otp_init_mac_addresses(void) +{ + struct udevice *dev = get_atsha204a_dev(); + u8 mac0[4], mac1[4], mac[6]; + int ret; + + if (!dev) + return -1; + + ret = atsha204a_wakeup(dev); + if (ret) + return ret; + + ret = atsha204a_read(dev, ATSHA204A_ZONE_OTP, false, + TURRIS_ATSHA_OTP_MAC0, mac0); + if (ret) + return ret; + + ret = atsha204a_read(dev, ATSHA204A_ZONE_OTP, false, + TURRIS_ATSHA_OTP_MAC1, mac1); + if (ret) + return ret; + + atsha204a_sleep(dev); + + mac[0] = mac0[1]; + mac[1] = mac0[2]; + mac[2] = mac0[3]; + mac[3] = mac1[1]; + mac[4] = mac1[2]; + mac[5] = mac1[3]; + + set_mac_if_invalid(1, mac); + increment_mac(mac); + set_mac_if_invalid(2, mac); + increment_mac(mac); + set_mac_if_invalid(0, mac); + + return 0; +} + +int turris_atsha_otp_get_serial_number(u32 *version_num, u32 *serial_num) +{ + struct udevice *dev = get_atsha204a_dev(); + int ret; + + if (!dev) + return -1; + + ret = atsha204a_wakeup(dev); + if (ret) + return ret; + + ret = atsha204a_read(dev, ATSHA204A_ZONE_OTP, false, + TURRIS_ATSHA_OTP_VERSION, + (u8 *)version_num); + if (ret) + return ret; + + ret = atsha204a_read(dev, ATSHA204A_ZONE_OTP, false, + TURRIS_ATSHA_OTP_SERIAL, + (u8 *)serial_num); + if (ret) + return ret; + + atsha204a_sleep(dev); + return 0; +} diff --git a/board/CZ.NIC/turris_atsha_otp.h b/board/CZ.NIC/turris_atsha_otp.h new file mode 100644 index 00000000000..667d01af731 --- /dev/null +++ b/board/CZ.NIC/turris_atsha_otp.h @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#ifndef TURRIS_ATSHA_OTP_H +#define TURRIS_ATSHA_OTP_H + +int turris_atsha_otp_init_mac_addresses(void); +int turris_atsha_otp_get_serial_number(u32 *version_num, u32 *serial_num); + +#endif diff --git a/board/CZ.NIC/turris_omnia/Makefile b/board/CZ.NIC/turris_omnia/Makefile index ccdf6c352ca..b79555ab467 100644 --- a/board/CZ.NIC/turris_omnia/Makefile +++ b/board/CZ.NIC/turris_omnia/Makefile @@ -2,4 +2,4 @@ # # Copyright (C) 2017 Marek Behun -obj-y := turris_omnia.o +obj-y := turris_omnia.o ../turris_atsha_otp.o diff --git a/board/CZ.NIC/turris_omnia/turris_omnia.c b/board/CZ.NIC/turris_omnia/turris_omnia.c index 33cec6587e1..719e8750e60 100644 --- a/board/CZ.NIC/turris_omnia/turris_omnia.c +++ b/board/CZ.NIC/turris_omnia/turris_omnia.c @@ -14,8 +14,6 @@ #include #include #include -#include -#include #include #include #include @@ -25,10 +23,10 @@ #include #include #include -# include #include "../drivers/ddr/marvell/a38x/ddr3_init.h" #include <../serdes/a38x/high_speed_env_spec.h> +#include "../turris_atsha_otp.h" DECLARE_GLOBAL_DATA_PTR; @@ -71,11 +69,6 @@ enum status_word_bits { MSATA_IND_STSBIT = 0x0020, }; -#define OMNIA_ATSHA204_OTP_VERSION 0 -#define OMNIA_ATSHA204_OTP_SERIAL 1 -#define OMNIA_ATSHA204_OTP_MAC0 3 -#define OMNIA_ATSHA204_OTP_MAC1 4 - /* * Those values and defines are taken from the Marvell U-Boot version * "u-boot-2013.01-2014_T3.0" @@ -594,49 +587,12 @@ int board_late_init(void) return 0; } -static struct udevice *get_atsha204a_dev(void) -{ - static struct udevice *dev; - - if (dev) - return dev; - - if (uclass_get_device_by_name(UCLASS_MISC, "atsha204a@64", &dev)) { - puts("Cannot find ATSHA204A on I2C bus!\n"); - dev = NULL; - } - - return dev; -} - int show_board_info(void) { u32 version_num, serial_num; - int err = 1; - - struct udevice *dev = get_atsha204a_dev(); - - if (dev) { - err = atsha204a_wakeup(dev); - if (err) - goto out; - - err = atsha204a_read(dev, ATSHA204A_ZONE_OTP, false, - OMNIA_ATSHA204_OTP_VERSION, - (u8 *)&version_num); - if (err) - goto out; - - err = atsha204a_read(dev, ATSHA204A_ZONE_OTP, false, - OMNIA_ATSHA204_OTP_SERIAL, - (u8 *)&serial_num); - if (err) - goto out; - - atsha204a_sleep(dev); - } + int err; -out: + err = turris_atsha_otp_get_serial_number(&version_num, &serial_num); printf("Model: Turris Omnia\n"); printf(" RAM size: %i MiB\n", omnia_get_ram_size_gb() * 1024); if (err) @@ -648,65 +604,9 @@ out: return 0; } -static void increment_mac(u8 *mac) -{ - int i; - - for (i = 5; i >= 3; i--) { - mac[i] += 1; - if (mac[i]) - break; - } -} - -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; - struct udevice *dev = get_atsha204a_dev(); - u8 mac0[4], mac1[4], mac[6]; - - if (!dev) - goto out; - - err = atsha204a_wakeup(dev); - if (err) - goto out; - - err = atsha204a_read(dev, ATSHA204A_ZONE_OTP, false, - OMNIA_ATSHA204_OTP_MAC0, mac0); - if (err) - goto out; - - err = atsha204a_read(dev, ATSHA204A_ZONE_OTP, false, - OMNIA_ATSHA204_OTP_MAC1, mac1); - if (err) - goto out; - - atsha204a_sleep(dev); - - mac[0] = mac0[1]; - mac[1] = mac0[2]; - mac[2] = mac0[3]; - mac[3] = mac1[1]; - mac[4] = mac1[2]; - mac[5] = mac1[3]; - - set_mac_if_invalid(1, mac); - increment_mac(mac); - set_mac_if_invalid(2, mac); - increment_mac(mac); - set_mac_if_invalid(0, mac); - -out: + turris_atsha_otp_init_mac_addresses(); return 0; } -- cgit v1.3.1 From ada791db3eb13ad5ac0447c8c8b0343c4d771fb9 Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Fri, 8 Apr 2022 16:30:13 +0200 Subject: board: turris: Do not cache Atsha device in BSS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Atsha device is used prior relocation and at this early stage BSS does not have to be ready yet. So do not cache Atsha device in BSS. Fixes support for other Turris routers. Signed-off-by: Pali Rohár Reviewed-by: Marek Behún --- board/CZ.NIC/turris_atsha_otp.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'board') diff --git a/board/CZ.NIC/turris_atsha_otp.c b/board/CZ.NIC/turris_atsha_otp.c index a4a77c74fb1..840721a9b73 100644 --- a/board/CZ.NIC/turris_atsha_otp.c +++ b/board/CZ.NIC/turris_atsha_otp.c @@ -18,10 +18,8 @@ static struct udevice *get_atsha204a_dev(void) { - static struct udevice *dev; - - if (dev) - return dev; + /* Cannot be static because BSS does not have to be ready at this early stage */ + struct udevice *dev; if (uclass_get_device_by_name(UCLASS_MISC, "atsha204a@64", &dev)) { puts("Cannot find ATSHA204A on I2C bus!\n"); -- cgit v1.3.1 From 98bbb6e7ab9b263a84c50a581c30089f9126c708 Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Fri, 8 Apr 2022 16:30:14 +0200 Subject: board: turris: Allow to specify first eth idx of first MAC address MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Turris Omnia uses first MAC address from OTP for second ethernet interface. Second MAC address for third interface and third MAC address for first interface. Other Turris routers do not have this rotate by one mapping. So add function parameter for specifying id of the first ethernet interface. Signed-off-by: Pali Rohár Reviewed-by: Marek Behún --- board/CZ.NIC/turris_atsha_otp.c | 8 ++++---- board/CZ.NIC/turris_atsha_otp.h | 2 +- board/CZ.NIC/turris_omnia/turris_omnia.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'board') diff --git a/board/CZ.NIC/turris_atsha_otp.c b/board/CZ.NIC/turris_atsha_otp.c index 840721a9b73..7a39b7f61d5 100644 --- a/board/CZ.NIC/turris_atsha_otp.c +++ b/board/CZ.NIC/turris_atsha_otp.c @@ -49,7 +49,7 @@ static void set_mac_if_invalid(int i, u8 *mac) eth_env_set_enetaddr_by_index("eth", i, mac); } -int turris_atsha_otp_init_mac_addresses(void) +int turris_atsha_otp_init_mac_addresses(int first_idx) { struct udevice *dev = get_atsha204a_dev(); u8 mac0[4], mac1[4], mac[6]; @@ -81,11 +81,11 @@ int turris_atsha_otp_init_mac_addresses(void) mac[4] = mac1[2]; mac[5] = mac1[3]; - set_mac_if_invalid(1, mac); + set_mac_if_invalid((first_idx + 0) % 3, mac); increment_mac(mac); - set_mac_if_invalid(2, mac); + set_mac_if_invalid((first_idx + 1) % 3, mac); increment_mac(mac); - set_mac_if_invalid(0, mac); + set_mac_if_invalid((first_idx + 2) % 3, mac); return 0; } diff --git a/board/CZ.NIC/turris_atsha_otp.h b/board/CZ.NIC/turris_atsha_otp.h index 667d01af731..bd4308fdc3e 100644 --- a/board/CZ.NIC/turris_atsha_otp.h +++ b/board/CZ.NIC/turris_atsha_otp.h @@ -3,7 +3,7 @@ #ifndef TURRIS_ATSHA_OTP_H #define TURRIS_ATSHA_OTP_H -int turris_atsha_otp_init_mac_addresses(void); +int turris_atsha_otp_init_mac_addresses(int first_idx); int turris_atsha_otp_get_serial_number(u32 *version_num, u32 *serial_num); #endif diff --git a/board/CZ.NIC/turris_omnia/turris_omnia.c b/board/CZ.NIC/turris_omnia/turris_omnia.c index 719e8750e60..da2fee578c4 100644 --- a/board/CZ.NIC/turris_omnia/turris_omnia.c +++ b/board/CZ.NIC/turris_omnia/turris_omnia.c @@ -606,7 +606,7 @@ int show_board_info(void) int misc_init_r(void) { - turris_atsha_otp_init_mac_addresses(); + turris_atsha_otp_init_mac_addresses(1); return 0; } -- cgit v1.3.1 From 08b99b67753a26ce142965151244261cdd73c490 Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Fri, 8 Apr 2022 16:30:15 +0200 Subject: board: turris: Rename atsha204a@64 DT node to crypto@64 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DT node name should be generic, therefore rename atsha204a@64 to crypto@64. Signed-off-by: Pali Rohár Reviewed-by: Marek Behún --- arch/arm/dts/armada-385-turris-omnia-u-boot.dtsi | 2 +- board/CZ.NIC/turris_atsha_otp.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'board') diff --git a/arch/arm/dts/armada-385-turris-omnia-u-boot.dtsi b/arch/arm/dts/armada-385-turris-omnia-u-boot.dtsi index 008787e664c..64ebe2c6d47 100644 --- a/arch/arm/dts/armada-385-turris-omnia-u-boot.dtsi +++ b/arch/arm/dts/armada-385-turris-omnia-u-boot.dtsi @@ -29,7 +29,7 @@ u-boot,dm-pre-reloc; /* ATSHA204A at address 0x64 */ - atsha204a@64 { + crypto@64 { u-boot,dm-pre-reloc; compatible = "atmel,atsha204a"; reg = <0x64>; diff --git a/board/CZ.NIC/turris_atsha_otp.c b/board/CZ.NIC/turris_atsha_otp.c index 7a39b7f61d5..8c39f5e5241 100644 --- a/board/CZ.NIC/turris_atsha_otp.c +++ b/board/CZ.NIC/turris_atsha_otp.c @@ -21,7 +21,7 @@ static struct udevice *get_atsha204a_dev(void) /* Cannot be static because BSS does not have to be ready at this early stage */ struct udevice *dev; - if (uclass_get_device_by_name(UCLASS_MISC, "atsha204a@64", &dev)) { + if (uclass_get_device_by_name(UCLASS_MISC, "crypto@64", &dev)) { puts("Cannot find ATSHA204A on I2C bus!\n"); dev = NULL; } -- cgit v1.3.1 From ac47bd230cd3430589c63f81e57b3d30e0abe0db Mon Sep 17 00:00:00 2001 From: Tony Dinh Date: Sun, 17 Apr 2022 16:42:32 -0700 Subject: arm: kirkwood: Sheevaplug : Use Marvell uclass mvgbe and PHY driver for Ethernet The Globalscale Technologies Sheevaplug board has the network chip Marvell 88E1116R. Use uclass mvgbe and the compatible driver M88E1310 driver to bring up Ethernet. - Remove CONFIG_RESET_PHY_R symbol from all board files - Use uclass mvgbe to bring up the network. And remove ad-hoc code. - Enable CONFIG_PHY_MARVELL to properly configure the network. - Miscellaneous changes: Move constants to .c file and remove header file board/Marvell/sheevaplug/sheevaplug.h, use BIT macro, and add/cleanup comments. Signed-off-by: Tony Dinh --- board/Marvell/sheevaplug/sheevaplug.c | 83 ++++++----------------------------- board/Marvell/sheevaplug/sheevaplug.h | 24 ---------- configs/sheevaplug_defconfig | 4 +- include/configs/sheevaplug.h | 19 ++------ 4 files changed, 20 insertions(+), 110 deletions(-) delete mode 100644 board/Marvell/sheevaplug/sheevaplug.h (limited to 'board') diff --git a/board/Marvell/sheevaplug/sheevaplug.c b/board/Marvell/sheevaplug/sheevaplug.c index 5952d158b28..26ee39ef77f 100644 --- a/board/Marvell/sheevaplug/sheevaplug.c +++ b/board/Marvell/sheevaplug/sheevaplug.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0+ /* - * Copyright (C) 2021 Tony Dinh + * Copyright (C) 2021-2022 Tony Dinh * (C) Copyright 2009 * Marvell Semiconductor * Written-by: Prafulla Wadaskar @@ -8,17 +8,21 @@ #include #include -#include -#include +#include #include #include #include #include #include -#include "sheevaplug.h" +#include DECLARE_GLOBAL_DATA_PTR; +#define SHEEVAPLUG_OE_LOW (~(0)) +#define SHEEVAPLUG_OE_HIGH (~(0)) +#define SHEEVAPLUG_OE_VAL_LOW BIT(29) /* USB_PWEN low */ +#define SHEEVAPLUG_OE_VAL_HIGH BIT(17) /* LED pin high */ + int board_early_init_f(void) { /* @@ -88,6 +92,11 @@ int board_early_init_f(void) return 0; } +int board_eth_init(struct bd_info *bis) +{ + return cpu_eth_init(bis); +} + int board_init(void) { /* @@ -95,72 +104,8 @@ int board_init(void) */ gd->bd->bi_arch_number = MACH_TYPE_SHEEVAPLUG; - /* adress of boot parameters */ + /* address of boot parameters */ gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100; return 0; } - -static int fdt_get_phy_addr(const char *path) -{ - const void *fdt = gd->fdt_blob; - const u32 *reg; - const u32 *val; - int node, phandle, addr; - - /* Find the node by its full path */ - node = fdt_path_offset(fdt, path); - if (node >= 0) { - /* Look up phy-handle */ - val = fdt_getprop(fdt, node, "phy-handle", NULL); - if (val) { - phandle = fdt32_to_cpu(*val); - if (!phandle) - return -1; - /* Follow it to its node */ - node = fdt_node_offset_by_phandle(fdt, phandle); - if (node) { - /* Look up reg */ - reg = fdt_getprop(fdt, node, "reg", NULL); - if (reg) { - addr = fdt32_to_cpu(*reg); - return addr; - } - } - } - } - return -1; -} - -#ifdef CONFIG_RESET_PHY_R -/* Configure and enable MV88E1116 PHY */ -void reset_phy(void) -{ - u16 reg; - int phyaddr; - char *name = "ethernet-controller@72000"; - char *eth0_path = "/ocp@f1000000/ethernet-controller@72000/ethernet0-port@0"; - - if (miiphy_set_current_dev(name)) - return; - - phyaddr = fdt_get_phy_addr(eth0_path); - if (phyaddr < 0) - return; - - /* - * Enable RGMII delay on Tx and Rx for CPU port - * Ref: sec 4.7.2 of chip datasheet - */ - miiphy_write(name, phyaddr, MV88E1116_PGADR_REG, 2); - miiphy_read(name, phyaddr, MV88E1116_MAC_CTRL_REG, ®); - reg |= (MV88E1116_RGMII_RXTM_CTRL | MV88E1116_RGMII_TXTM_CTRL); - miiphy_write(name, phyaddr, MV88E1116_MAC_CTRL_REG, reg); - miiphy_write(name, phyaddr, MV88E1116_PGADR_REG, 0); - - /* reset the phy */ - miiphy_reset(name, phyaddr); - - printf("88E1116 Initialized on %s\n", name); -} -#endif /* CONFIG_RESET_PHY_R */ diff --git a/board/Marvell/sheevaplug/sheevaplug.h b/board/Marvell/sheevaplug/sheevaplug.h deleted file mode 100644 index e026c1b53bd..00000000000 --- a/board/Marvell/sheevaplug/sheevaplug.h +++ /dev/null @@ -1,24 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * (C) Copyright 2009 - * Marvell Semiconductor - * Written-by: Prafulla Wadaskar - */ - -#ifndef __SHEEVAPLUG_H -#define __SHEEVAPLUG_H - -#define SHEEVAPLUG_OE_LOW (~(0)) -#define SHEEVAPLUG_OE_HIGH (~(0)) -#define SHEEVAPLUG_OE_VAL_LOW (1 << 29) /* USB_PWEN low */ -#define SHEEVAPLUG_OE_VAL_HIGH (1 << 17) /* LED pin high */ - -/* PHY related */ -#define MV88E1116_LED_FCTRL_REG 10 -#define MV88E1116_CPRSP_CR3_REG 21 -#define MV88E1116_MAC_CTRL_REG 21 -#define MV88E1116_PGADR_REG 22 -#define MV88E1116_RGMII_TXTM_CTRL (1 << 4) -#define MV88E1116_RGMII_RXTM_CTRL (1 << 5) - -#endif /* __SHEEVAPLUG_H */ diff --git a/configs/sheevaplug_defconfig b/configs/sheevaplug_defconfig index 0525bb436ec..0477cd79e3e 100644 --- a/configs/sheevaplug_defconfig +++ b/configs/sheevaplug_defconfig @@ -21,7 +21,6 @@ CONFIG_USE_BOOTCOMMAND=y CONFIG_BOOTCOMMAND="${x_bootcmd_kernel}; setenv bootargs ${x_bootargs} ${x_bootargs_root}; bootm 0x6400000;" CONFIG_USE_PREBOOT=y # CONFIG_DISPLAY_BOARDINFO is not set -CONFIG_RESET_PHY_R=y CONFIG_HUSH_PARSER=y CONFIG_CMD_BOOTZ=y # CONFIG_CMD_FLASH is not set @@ -29,13 +28,13 @@ CONFIG_CMD_MMC=y CONFIG_CMD_NAND=y CONFIG_CMD_SATA=y CONFIG_CMD_USB=y -# CONFIG_CMD_SETEXPR is not set CONFIG_CMD_DHCP=y CONFIG_CMD_MII=y CONFIG_CMD_PING=y CONFIG_CMD_EXT2=y CONFIG_CMD_EXT4=y CONFIG_CMD_FAT=y +CONFIG_CMD_FS_GENERIC=y CONFIG_CMD_JFFS2=y CONFIG_CMD_MTDPARTS=y CONFIG_MTDIDS_DEFAULT="nand0=orion_nand" @@ -54,6 +53,7 @@ CONFIG_SYS_SATA_MAX_DEVICE=2 CONFIG_MVEBU_MMC=y CONFIG_MTD=y CONFIG_MTD_RAW_NAND=y +CONFIG_PHY_MARVELL=y CONFIG_DM_ETH=y CONFIG_MVGBE=y CONFIG_MII=y diff --git a/include/configs/sheevaplug.h b/include/configs/sheevaplug.h index 0cc58c3a7d9..58345e4e1be 100644 --- a/include/configs/sheevaplug.h +++ b/include/configs/sheevaplug.h @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0+ */ /* + * (C) Copyright 2022 Tony Dinh * (C) Copyright 2009-2014 * Gerald Kerma * Marvell Semiconductor @@ -14,17 +15,8 @@ /* * Environment variables configurations */ -/* - * max 4k env size is enough, but in case of nand - * it has to be rounded to sector size - */ - -/* - * Default environment variables - */ - #define CONFIG_EXTRA_ENV_SETTINGS "x_bootargs=console" \ - "=ttyS0,115200 mtdparts="CONFIG_MTDPARTS_DEFAULT \ + "=ttyS0,115200 mtdparts=" CONFIG_MTDPARTS_DEFAULT \ "x_bootcmd_kernel=nand read 0x6400000 0x100000 0x400000\0" \ "x_bootcmd_usb=usb start\0" \ "x_bootargs_root=root=/dev/mtdblock3 rw rootfstype=jffs2\0" @@ -32,16 +24,13 @@ /* * Ethernet Driver configuration */ -#ifdef CONFIG_CMD_NET #define CONFIG_MVGBE_PORTS {1, 0} /* enable port 0 only */ #define CONFIG_PHY_BASE_ADR 0 -#endif /* CONFIG_CMD_NET */ /* - * SATA driver configuration + * Support large disk for SATA and USB */ -#ifdef CONFIG_SATA +#define CONFIG_SYS_64BIT_LBA #define CONFIG_LBA48 -#endif /* CONFIG_SATA */ #endif /* _CONFIG_SHEEVAPLUG_H */ -- cgit v1.3.1