From ead4864fa6ccd552b1c2b6941e4b16ed6128b02f Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Wed, 11 Aug 2021 10:08:04 +0200 Subject: arm: mvebu: a38x: Define supported UART baudrates Define all standard baudrates plus 3 non-standard high speed: 3125000 4000000 5150000 3125000 matches divisor 5 with 250 MHz TCLK and divisor 4 with 200 MHz TCLK. 4000000 is the rounded value for divisor 4 with 250 MHz TCLK (3906250) and divisor 3 with 200 MHz TCLK (4166666). 5150000 is the rounded value (5208333) for divisor 3 with 250 MHz TCLK. Testing showed that rounded value is more stable then exactly calculated. And it is the highest possible baudrate which is stable on A38x platform. Any other baudrate values above 2500000 are unstable, which is reason why e.g. standard value 3000000 is not defined, and it is needed to use non-standard value 3125000. Tested all defined UART baudrates on Turris Omnia (A38x with 250 MHz TCLK). Signed-off-by: Pali Rohár Reviewed-by: Marek Behún Reviewed-by: Stefan Roese --- include/configs/mv-common.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/configs/mv-common.h b/include/configs/mv-common.h index d61c90a4315..53d7acbb103 100644 --- a/include/configs/mv-common.h +++ b/include/configs/mv-common.h @@ -39,6 +39,15 @@ #define CONFIG_SYS_NS16550_COM1 MV_UART_CONSOLE_BASE #endif +#if defined(CONFIG_ARMADA_38X) && !defined(CONFIG_SYS_BAUDRATE_TABLE) +#define CONFIG_SYS_BAUDRATE_TABLE { 300, 600, 1200, 1800, 2400, 4800, \ + 9600, 19200, 38400, 57600, 115200, \ + 230400, 460800, 500000, 576000, \ + 921600, 1000000, 1152000, 1500000, \ + 2000000, 2500000, 3125000, 4000000, \ + 5150000 } +#endif + /* auto boot */ /* -- cgit v1.2.3 From b984056fa696e795625a2f5292859b73176f7713 Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Wed, 11 Aug 2021 10:14:14 +0200 Subject: tools: kwbimage: Verify supported image version Only image versions 0 and 1 are supported. Verify it in kwbimage_verify_header() function. Signed-off-by: Pali Rohár Reviewed-by: Stefan Roese --- tools/kwbimage.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 00cb338d64f..542779ed484 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1678,9 +1678,7 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size, if (checksum != ext_hdr->checksum) return -FDT_ERR_BADSTRUCTURE; } - } - - if (image_version((void *)ptr) == 1) { + } else if (image_version((void *)ptr) == 1) { struct main_hdr_v1 *mhdr = (struct main_hdr_v1 *)ptr; uint32_t offset; uint32_t size; @@ -1750,6 +1748,8 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size, if (image_checksum32(ptr + offset, size - 4) != *(uint32_t *)(ptr + offset + size - 4)) return -FDT_ERR_BADSTRUCTURE; + } else { + return -FDT_ERR_BADSTRUCTURE; } return 0; -- cgit v1.2.3 From 33a0af2d8041b027cfbf6ab23c93026339aff142 Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Wed, 11 Aug 2021 10:14:15 +0200 Subject: tools: kwbimage: Verify size of v0 image header Check that extended image header size is not larger than file size. Signed-off-by: Pali Rohár Reviewed-by: Stefan Roese --- tools/kwbimage.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 542779ed484..4709c6d5442 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1670,6 +1670,9 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size, if (mhdr->ext & 0x1) { struct ext_hdr_v0 *ext_hdr; + if (header_size + sizeof(*ext_hdr) > image_size) + return -FDT_ERR_BADSTRUCTURE; + ext_hdr = (struct ext_hdr_v0 *) (ptr + sizeof(struct main_hdr_v0)); checksum = image_checksum8(ext_hdr, -- cgit v1.2.3 From a008dbaa8ce2d4142e17780177faa381fd59bb4e Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Wed, 11 Aug 2021 10:14:16 +0200 Subject: tools: kwbimage: Verify size of image data Part of image data is 4 byte checksum, so every image must contain at least 4 bytes. Verify it to prevent memory corruptions. Signed-off-by: Pali Rohár Reviewed-by: Stefan Roese --- tools/kwbimage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 4709c6d5442..f47e52f13a9 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1745,7 +1745,7 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size, return -FDT_ERR_BADSTRUCTURE; size = le32_to_cpu(mhdr->blocksize); - if (offset + size > image_size || size % 4 != 0) + if (size < 4 || offset + size > image_size || size % 4 != 0) return -FDT_ERR_BADSTRUCTURE; if (image_checksum32(ptr + offset, size - 4) != -- cgit v1.2.3 From e515a33040af6c637f8f17d9bd4166b0c3bba22d Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Wed, 11 Aug 2021 10:14:17 +0200 Subject: tools: kwbimage: Use IBR_HDR_* constants instead of raw numbers There are already IBR_HDR_* constants for these numbers, so use them. Signed-off-by: Pali Rohár Reviewed-by: Stefan Roese --- tools/kwbimage.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tools/kwbimage.c b/tools/kwbimage.c index f47e52f13a9..9fab04ce88d 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -59,13 +59,13 @@ struct hash_v1 { }; struct boot_mode boot_modes[] = { - { 0x4D, "i2c" }, - { 0x5A, "spi" }, - { 0x8B, "nand" }, - { 0x78, "sata" }, - { 0x9C, "pex" }, - { 0x69, "uart" }, - { 0xAE, "sdio" }, + { IBR_HDR_I2C_ID, "i2c" }, + { IBR_HDR_SPI_ID, "spi" }, + { IBR_HDR_NAND_ID, "nand" }, + { IBR_HDR_SATA_ID, "sata" }, + { IBR_HDR_PEX_ID, "pex" }, + { IBR_HDR_UART_ID, "uart" }, + { IBR_HDR_SDIO_ID, "sdio" }, {}, }; @@ -75,10 +75,10 @@ struct nand_ecc_mode { }; struct nand_ecc_mode nand_ecc_modes[] = { - { 0x00, "default" }, - { 0x01, "hamming" }, - { 0x02, "rs" }, - { 0x03, "disabled" }, + { IBR_HDR_ECC_DEFAULT, "default" }, + { IBR_HDR_ECC_FORCED_HAMMING, "hamming" }, + { IBR_HDR_ECC_FORCED_RS, "rs" }, + { IBR_HDR_ECC_DISABLED, "disabled" }, {}, }; -- cgit v1.2.3 From 3404aa464696fbb5a976bdde0746e6ca82b8af82 Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Wed, 11 Aug 2021 20:53:29 +0200 Subject: arm: mvebu: axp: Properly check for Armada XP in mach/soc.h File mach/soc.h is included also in 64-bit mvebu processors, so define Armada XP related macros only when compiling for Armada XP. Signed-off-by: Pali Rohár Reviewed-by: Stefan Roese --- arch/arm/mach-mvebu/include/mach/soc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/mach-mvebu/include/mach/soc.h b/arch/arm/mach-mvebu/include/mach/soc.h index 8e8a4058550..aab61f7c15c 100644 --- a/arch/arm/mach-mvebu/include/mach/soc.h +++ b/arch/arm/mach-mvebu/include/mach/soc.h @@ -189,7 +189,7 @@ #define BOOT_FROM_SPI 0x3 #define CONFIG_SYS_TCLK 200000000 /* 200MHz */ -#else +#elif defined(CONFIG_ARMADA_XP) /* SAR values for Armada XP */ #define CONFIG_SAR_REG (MVEBU_REGISTER(0x18230)) #define CONFIG_SAR2_REG (MVEBU_REGISTER(0x18234)) -- cgit v1.2.3 From 8e7fe463059f5d80b40937ec3d70bb41ebfa848d Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Fri, 13 Aug 2021 13:56:36 +0200 Subject: arm: mvebu: espressobin: Enable also SATA support via PCIe Espressobin has one on-board SATA port which is connected directly to CPU. More SATA disks can be connected via mPCIe add-in card with PCIe-SATA controller. So enable required SATA AHCI PCIe drivers in defconfig file. Signed-off-by: Pali Rohár Reviewed-by: Stefan Roese --- configs/mvebu_espressobin-88f3720_defconfig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/configs/mvebu_espressobin-88f3720_defconfig b/configs/mvebu_espressobin-88f3720_defconfig index c8ae0cf6109..4003a25346c 100644 --- a/configs/mvebu_espressobin-88f3720_defconfig +++ b/configs/mvebu_espressobin-88f3720_defconfig @@ -30,6 +30,7 @@ CONFIG_CMD_I2C=y CONFIG_CMD_MMC=y CONFIG_CMD_MTD=y CONFIG_CMD_PCI=y +CONFIG_CMD_SATA=y CONFIG_CMD_SPI=y CONFIG_CMD_USB=y CONFIG_CMD_WDT=y @@ -46,6 +47,7 @@ CONFIG_ENV_OVERWRITE=y CONFIG_ENV_IS_IN_SPI_FLASH=y CONFIG_SYS_RELOC_GD_ENV_ADDR=y CONFIG_NET_RANDOM_ETHADDR=y +CONFIG_AHCI_PCI=y CONFIG_AHCI_MVEBU=y CONFIG_CLK=y CONFIG_CLK_MVEBU=y -- cgit v1.2.3 From be575083c9ca15351e2fd20c996e7fafed6afdce Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Fri, 13 Aug 2021 13:56:37 +0200 Subject: arm: mvebu: turris_mox: Enable SATA support SATA disks could be connected via mPCIe add-in card with PCIe-SATA controller into Mox-B or Mox-G module. Signed-off-by: Pali Rohár Reviewed-by: Stefan Roese --- configs/turris_mox_defconfig | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/configs/turris_mox_defconfig b/configs/turris_mox_defconfig index c19b8379c32..fc5e1fc3766 100644 --- a/configs/turris_mox_defconfig +++ b/configs/turris_mox_defconfig @@ -12,6 +12,7 @@ CONFIG_DM_GPIO=y CONFIG_DEFAULT_DEVICE_TREE="armada-3720-turris-mox" CONFIG_DEBUG_UART_BASE=0xd0012000 CONFIG_DEBUG_UART=y +CONFIG_AHCI=y CONFIG_OF_BOARD_FIXUP=y CONFIG_DISTRO_DEFAULTS=y # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set @@ -32,6 +33,7 @@ CONFIG_CMD_I2C=y CONFIG_CMD_MMC=y CONFIG_CMD_MTD=y CONFIG_CMD_PCI=y +CONFIG_CMD_SATA=y CONFIG_CMD_SPI=y CONFIG_CMD_USB=y CONFIG_CMD_WDT=y @@ -47,6 +49,8 @@ CONFIG_MAC_PARTITION=y CONFIG_ENV_OVERWRITE=y CONFIG_ENV_IS_IN_SPI_FLASH=y CONFIG_SYS_RELOC_GD_ENV_ADDR=y +CONFIG_SCSI_AHCI=y +CONFIG_AHCI_PCI=y CONFIG_BUTTON=y CONFIG_BUTTON_GPIO=y CONFIG_CLK=y @@ -81,6 +85,8 @@ CONFIG_PINCTRL_ARMADA_37XX=y CONFIG_DM_REGULATOR_FIXED=y CONFIG_DM_RTC=y CONFIG_RTC_DS1307=y +CONFIG_SCSI=y +CONFIG_DM_SCSI=y CONFIG_DEBUG_UART_SHIFT=2 CONFIG_DEBUG_UART_ANNOUNCE=y CONFIG_MVEBU_A3700_UART=y -- cgit v1.2.3 From 1b713f15501723efd4731ea2985f6fd81d309158 Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Fri, 13 Aug 2021 13:56:38 +0200 Subject: arm: mvebu: turris_omnia: Enable NVMe support PCIe-based NVMe SSD disks in M.2 2230/2242/2260 form-factor can be connected to Turris Omnia mPCIe slot via passive M.2 <--> mPCIe adapter. So enable PCIe NVMe drivers. Signed-off-by: Pali Rohár Reviewed-by: Stefan Roese --- configs/turris_omnia_defconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/turris_omnia_defconfig b/configs/turris_omnia_defconfig index cd443ceb300..2acc4ada412 100644 --- a/configs/turris_omnia_defconfig +++ b/configs/turris_omnia_defconfig @@ -77,6 +77,7 @@ CONFIG_PHY_MARVELL=y CONFIG_PHY_GIGE=y CONFIG_MVNETA=y CONFIG_MII=y +CONFIG_NVME=y CONFIG_PCI=y CONFIG_PCI_MVEBU=y CONFIG_DM_RTC=y -- cgit v1.2.3 From 167689897bec01fc338240a5bf0db4de384cef79 Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Fri, 13 Aug 2021 13:58:49 +0200 Subject: serial: a37xx: Remove CONFIG_DEBUG_UART_SHIFT options Armada 37xx serial driver does not use CONFIG_DEBUG_UART_SHIFT. So do not define any bogus value for CONFIG_DEBUG_UART_SHIFT option in any Armada 37xx defconfig file. Signed-off-by: Pali Rohár Reviewed-by: Stefan Roese --- configs/mvebu_db-88f3720_defconfig | 1 - configs/mvebu_espressobin-88f3720_defconfig | 1 - configs/turris_mox_defconfig | 1 - configs/uDPU_defconfig | 1 - 4 files changed, 4 deletions(-) diff --git a/configs/mvebu_db-88f3720_defconfig b/configs/mvebu_db-88f3720_defconfig index bc92fdb8ee8..eb50afc0f38 100644 --- a/configs/mvebu_db-88f3720_defconfig +++ b/configs/mvebu_db-88f3720_defconfig @@ -63,7 +63,6 @@ CONFIG_PHY=y CONFIG_MVEBU_COMPHY_SUPPORT=y CONFIG_PINCTRL=y CONFIG_PINCTRL_ARMADA_37XX=y -CONFIG_DEBUG_UART_SHIFT=2 CONFIG_DEBUG_UART_ANNOUNCE=y CONFIG_MVEBU_A3700_UART=y CONFIG_MVEBU_A3700_SPI=y diff --git a/configs/mvebu_espressobin-88f3720_defconfig b/configs/mvebu_espressobin-88f3720_defconfig index 4003a25346c..9641c02d931 100644 --- a/configs/mvebu_espressobin-88f3720_defconfig +++ b/configs/mvebu_espressobin-88f3720_defconfig @@ -79,7 +79,6 @@ CONFIG_MVEBU_COMPHY_SUPPORT=y CONFIG_PINCTRL=y CONFIG_PINCTRL_ARMADA_37XX=y CONFIG_DM_REGULATOR_GPIO=y -CONFIG_DEBUG_UART_SHIFT=2 CONFIG_DEBUG_UART_ANNOUNCE=y CONFIG_MVEBU_A3700_UART=y CONFIG_MVEBU_A3700_SPI=y diff --git a/configs/turris_mox_defconfig b/configs/turris_mox_defconfig index fc5e1fc3766..40f975ead31 100644 --- a/configs/turris_mox_defconfig +++ b/configs/turris_mox_defconfig @@ -87,7 +87,6 @@ CONFIG_DM_RTC=y CONFIG_RTC_DS1307=y CONFIG_SCSI=y CONFIG_DM_SCSI=y -CONFIG_DEBUG_UART_SHIFT=2 CONFIG_DEBUG_UART_ANNOUNCE=y CONFIG_MVEBU_A3700_UART=y CONFIG_MVEBU_A3700_SPI=y diff --git a/configs/uDPU_defconfig b/configs/uDPU_defconfig index 3e6bb32cb88..1ea3aad5ff2 100644 --- a/configs/uDPU_defconfig +++ b/configs/uDPU_defconfig @@ -79,7 +79,6 @@ CONFIG_PINCTRL=y CONFIG_PINCTRL_ARMADA_37XX=y CONFIG_DM_REGULATOR_FIXED=y CONFIG_DM_REGULATOR_GPIO=y -CONFIG_DEBUG_UART_SHIFT=2 CONFIG_DEBUG_UART_ANNOUNCE=y CONFIG_MVEBU_A3700_UART=y CONFIG_MVEBU_A3700_SPI=y -- cgit v1.2.3 From dc595e3e45913ae932bb269739a8a48a27fdd585 Mon Sep 17 00:00:00 2001 From: Marek Behún Date: Mon, 16 Aug 2021 15:19:37 +0200 Subject: arm: mvebu: Move get_boot_device() to cpu.c and make visible Move the function get_boot_device() from spl.c to cpu.c. Make it visible, so that it may be used from other files. Signed-off-by: Marek Behún Reviewed-by: Pali Rohár Reviewed-by: Stefan Roese --- arch/arm/mach-mvebu/cpu.c | 60 ++++++++++++++++++++++++++ arch/arm/mach-mvebu/include/mach/cpu.h | 2 + arch/arm/mach-mvebu/spl.c | 77 ++++------------------------------ 3 files changed, 71 insertions(+), 68 deletions(-) diff --git a/arch/arm/mach-mvebu/cpu.c b/arch/arm/mach-mvebu/cpu.c index 0b935c46fb8..daf8bd66a03 100644 --- a/arch/arm/mach-mvebu/cpu.c +++ b/arch/arm/mach-mvebu/cpu.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #define DDR_BASE_CS_OFF(n) (0x0000 + ((n) << 3)) @@ -80,6 +81,65 @@ int mvebu_soc_family(void) return MVEBU_SOC_UNKNOWN; } +u32 get_boot_device(void) +{ + u32 val; + u32 boot_device; + + /* + * First check, if UART boot-mode is active. This can only + * be done, via the bootrom error register. Here the + * MSB marks if the UART mode is active. + */ + val = readl(CONFIG_BOOTROM_ERR_REG); + boot_device = (val & BOOTROM_ERR_MODE_MASK) >> BOOTROM_ERR_MODE_OFFS; + debug("BOOTROM_REG=0x%08x boot_device=0x%x\n", val, boot_device); + if (boot_device == BOOTROM_ERR_MODE_UART) + return BOOT_DEVICE_UART; + +#ifdef CONFIG_ARMADA_38X + /* + * If the bootrom error code contains any other than zeros it's an + * error condition and the bootROM has fallen back to UART boot + */ + boot_device = (val & BOOTROM_ERR_CODE_MASK) >> BOOTROM_ERR_CODE_OFFS; + if (boot_device) + return BOOT_DEVICE_UART; +#endif + + /* + * Now check the SAR register for the strapped boot-device + */ + val = readl(CONFIG_SAR_REG); /* SAR - Sample At Reset */ + boot_device = (val & BOOT_DEV_SEL_MASK) >> BOOT_DEV_SEL_OFFS; + debug("SAR_REG=0x%08x boot_device=0x%x\n", val, boot_device); + switch (boot_device) { +#ifdef BOOT_FROM_NAND + case BOOT_FROM_NAND: + return BOOT_DEVICE_NAND; +#endif +#ifdef BOOT_FROM_MMC + case BOOT_FROM_MMC: + case BOOT_FROM_MMC_ALT: + return BOOT_DEVICE_MMC1; +#endif + case BOOT_FROM_UART: +#ifdef BOOT_FROM_UART_ALT + case BOOT_FROM_UART_ALT: +#endif + return BOOT_DEVICE_UART; +#ifdef BOOT_FROM_SATA + case BOOT_FROM_SATA: + case BOOT_FROM_SATA_ALT: + return BOOT_DEVICE_SATA; +#endif + case BOOT_FROM_SPI: + return BOOT_DEVICE_SPI; + default: + return BOOT_DEVICE_BOOTROM; + }; +} + #if defined(CONFIG_DISPLAY_CPUINFO) #if defined(CONFIG_ARMADA_375) diff --git a/arch/arm/mach-mvebu/include/mach/cpu.h b/arch/arm/mach-mvebu/include/mach/cpu.h index 79858858c25..a7a62c7e7d5 100644 --- a/arch/arm/mach-mvebu/include/mach/cpu.h +++ b/arch/arm/mach-mvebu/include/mach/cpu.h @@ -148,6 +148,8 @@ void __noreturn return_to_bootrom(void); int mv_sdh_init(unsigned long regbase, u32 max_clk, u32 min_clk, u32 quirks); #endif +u32 get_boot_device(void); + void get_sar_freq(struct sar_freq_modes *sar_freq); /* diff --git a/arch/arm/mach-mvebu/spl.c b/arch/arm/mach-mvebu/spl.c index f0cf60bb148..8d6d4902f69 100644 --- a/arch/arm/mach-mvebu/spl.c +++ b/arch/arm/mach-mvebu/spl.c @@ -171,74 +171,6 @@ int spl_parse_board_header(struct spl_image_info *spl_image, return 0; } -static u32 get_boot_device(void) -{ - u32 val; - u32 boot_device; - - /* - * First check, if UART boot-mode is active. This can only - * be done, via the bootrom error register. Here the - * MSB marks if the UART mode is active. - */ - val = readl(CONFIG_BOOTROM_ERR_REG); - boot_device = (val & BOOTROM_ERR_MODE_MASK) >> BOOTROM_ERR_MODE_OFFS; - debug("BOOTROM_REG=0x%08x boot_device=0x%x\n", val, boot_device); - if (boot_device == BOOTROM_ERR_MODE_UART) - return BOOT_DEVICE_UART; - -#ifdef CONFIG_ARMADA_38X - /* - * If the bootrom error code contains any other than zeros it's an - * error condition and the bootROM has fallen back to UART boot - */ - boot_device = (val & BOOTROM_ERR_CODE_MASK) >> BOOTROM_ERR_CODE_OFFS; - if (boot_device) - return BOOT_DEVICE_UART; -#endif - - /* - * Now check the SAR register for the strapped boot-device - */ - val = readl(CONFIG_SAR_REG); /* SAR - Sample At Reset */ - boot_device = (val & BOOT_DEV_SEL_MASK) >> BOOT_DEV_SEL_OFFS; - debug("SAR_REG=0x%08x boot_device=0x%x\n", val, boot_device); - switch (boot_device) { -#ifdef BOOT_FROM_NAND - case BOOT_FROM_NAND: - return BOOT_DEVICE_NAND; -#endif -#ifdef BOOT_FROM_MMC - case BOOT_FROM_MMC: - case BOOT_FROM_MMC_ALT: - return BOOT_DEVICE_MMC1; -#endif - case BOOT_FROM_UART: -#ifdef BOOT_FROM_UART_ALT - case BOOT_FROM_UART_ALT: -#endif - return BOOT_DEVICE_UART; -#ifdef BOOT_FROM_SATA - case BOOT_FROM_SATA: - case BOOT_FROM_SATA_ALT: - return BOOT_DEVICE_SATA; -#endif - case BOOT_FROM_SPI: - return BOOT_DEVICE_SPI; - default: - return BOOT_DEVICE_BOOTROM; - }; -} - -#else - -static u32 get_boot_device(void) -{ - return BOOT_DEVICE_BOOTROM; -} - -#endif - u32 spl_boot_device(void) { u32 boot_device = get_boot_device(); @@ -285,6 +217,15 @@ u32 spl_boot_device(void) } } +#else + +u32 spl_boot_device(void) +{ + return BOOT_DEVICE_BOOTROM; +} + +#endif + int board_return_to_bootrom(struct spl_image_info *spl_image, struct spl_boot_device *bootdev) { -- cgit v1.2.3 From 008a069b89c690077ff9fa351557c8fc0778755c Mon Sep 17 00:00:00 2001 From: Marek Behún Date: Mon, 16 Aug 2021 15:19:38 +0200 Subject: arm: mvebu: turris_omnia: don't guard by CONFIG_SPL_BUILD macro We do not need to guard code in board_init() and board_late_init() functions with the CONFIG_SPL_BUILD macro, since these functions are not called in SPL. Signed-off-by: Marek Behún Reviewed-by: Pali Rohár Reviewed-by: Stefan Roese --- board/CZ.NIC/turris_omnia/turris_omnia.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/board/CZ.NIC/turris_omnia/turris_omnia.c b/board/CZ.NIC/turris_omnia/turris_omnia.c index a7e5f56eed7..a84a409f43f 100644 --- a/board/CZ.NIC/turris_omnia/turris_omnia.c +++ b/board/CZ.NIC/turris_omnia/turris_omnia.c @@ -129,7 +129,6 @@ static int omnia_mcu_read(u8 cmd, void *buf, int len) return dm_i2c_read(chip, cmd, buf, len); } -#ifndef CONFIG_SPL_BUILD static int omnia_mcu_write(u8 cmd, const void *buf, int len) { struct udevice *chip; @@ -158,7 +157,6 @@ static bool disable_mcu_watchdog(void) return true; } -#endif static bool omnia_detect_sata(void) { @@ -325,7 +323,6 @@ struct mv_ddr_topology_map *mv_ddr_topology_map_get(void) return &board_topology_map_1g; } -#ifndef CONFIG_SPL_BUILD static int set_regdomain(void) { struct omnia_eeprom oep; @@ -394,7 +391,6 @@ static void handle_reset_button(void) } } } -#endif int board_early_init_f(void) { @@ -428,19 +424,15 @@ int board_init(void) /* address of boot parameters */ gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100; -#ifndef CONFIG_SPL_BUILD disable_mcu_watchdog(); -#endif return 0; } int board_late_init(void) { -#ifndef CONFIG_SPL_BUILD set_regdomain(); handle_reset_button(); -#endif pci_init(); return 0; -- cgit v1.2.3 From aeb0ca64dbb5e4b1f58c5b723d92220e7729aa37 Mon Sep 17 00:00:00 2001 From: Marek Behún Date: Mon, 16 Aug 2021 15:19:39 +0200 Subject: arm: mvebu: turris_omnia: disable MCU watchdog in SPL when booting over UART When booting over UART, sending U-Boot proper may take too much time and MCU watchdog will reset the board before U-Boot proper is loaded. Better disable MCU watchdog in SPL when booting over UART. Signed-off-by: Marek Behún Reviewed-by: Pali Rohár Reviewed-by: Stefan Roese --- board/CZ.NIC/turris_omnia/turris_omnia.c | 17 ++++++++++++++++- configs/turris_omnia_defconfig | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/board/CZ.NIC/turris_omnia/turris_omnia.c b/board/CZ.NIC/turris_omnia/turris_omnia.c index a84a409f43f..b0391c973d9 100644 --- a/board/CZ.NIC/turris_omnia/turris_omnia.c +++ b/board/CZ.NIC/turris_omnia/turris_omnia.c @@ -419,12 +419,27 @@ int board_early_init_f(void) return 0; } +void spl_board_init(void) +{ + /* + * If booting from UART, disable MCU watchdog in SPL, since uploading + * U-Boot proper can take too much time and trigger it. + */ + if (get_boot_device() == BOOT_DEVICE_UART) + disable_mcu_watchdog(); +} + int board_init(void) { /* address of boot parameters */ gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100; - disable_mcu_watchdog(); + /* + * If not booting from UART, MCU watchdog was not disabled in SPL, + * disable it now. + */ + if (get_boot_device() != BOOT_DEVICE_UART) + disable_mcu_watchdog(); return 0; } diff --git a/configs/turris_omnia_defconfig b/configs/turris_omnia_defconfig index 2acc4ada412..b2bbbd14694 100644 --- a/configs/turris_omnia_defconfig +++ b/configs/turris_omnia_defconfig @@ -33,6 +33,7 @@ CONFIG_SYS_CONSOLE_INFO_QUIET=y # CONFIG_DISPLAY_BOARDINFO is not set CONFIG_DISPLAY_BOARDINFO_LATE=y CONFIG_MISC_INIT_R=y +CONFIG_SPL_BOARD_INIT=y CONFIG_SPL_I2C=y CONFIG_CMD_MEMTEST=y CONFIG_SYS_ALT_MEMTEST=y -- cgit v1.2.3 From e23162c805d46e7f6d11ba07f397b5e3e3750fda Mon Sep 17 00:00:00 2001 From: Marek Behún Date: Mon, 16 Aug 2021 15:19:40 +0200 Subject: arm: mvebu: turris_omnia: disable MCU watchdog in board_late_init() Disable MCU watchdog in board_late_init() instead of board_init(), so that it is disabled after U-Boot enables SOC watchdog instead of before. This way there is no window when the board is vulnerable. Signed-off-by: Marek Behún Reviewed-by: Pali Rohár Reviewed-by: Stefan Roese --- board/CZ.NIC/turris_omnia/turris_omnia.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/board/CZ.NIC/turris_omnia/turris_omnia.c b/board/CZ.NIC/turris_omnia/turris_omnia.c index b0391c973d9..bac78af04e0 100644 --- a/board/CZ.NIC/turris_omnia/turris_omnia.c +++ b/board/CZ.NIC/turris_omnia/turris_omnia.c @@ -434,6 +434,11 @@ int board_init(void) /* address of boot parameters */ gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100; + return 0; +} + +int board_late_init(void) +{ /* * If not booting from UART, MCU watchdog was not disabled in SPL, * disable it now. @@ -441,11 +446,6 @@ int board_init(void) if (get_boot_device() != BOOT_DEVICE_UART) disable_mcu_watchdog(); - return 0; -} - -int board_late_init(void) -{ set_regdomain(); handle_reset_button(); pci_init(); -- cgit v1.2.3 From f858bb2e6c191da3981838937950cb3c98e488fe Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Tue, 17 Aug 2021 07:03:20 +0200 Subject: kwbimage: check fopen() return value Always check the return value of fopen(). This resolves Coverity CID 338491: Null pointer dereferences (NULL_RETURNS) Signed-off-by: Heinrich Schuchardt Reviewed-by: Stefan Roese Reviewed-by: Pali Rohár --- tools/kwbimage.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 9fab04ce88d..b2694888d96 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -832,6 +832,12 @@ static int kwb_dump_fuse_cmds(struct secure_hdr_v1 *sec_hdr) if (!strcmp(e->name, "a38x")) { FILE *out = fopen("kwb_fuses_a38x.txt", "w+"); + if (!out) { + fprintf(stderr, "Couldn't open eFuse settings: '%s': %s\n", + "kwb_fuses_a38x.txt", strerror(errno)); + return -ENOENT; + } + kwb_dump_fuse_cmds_38x(out, sec_hdr); fclose(out); goto done; @@ -1060,6 +1066,11 @@ int export_pub_kak_hash(RSA *kak, struct secure_hdr_v1 *secure_hdr) int res; hashf = fopen("pub_kak_hash.txt", "w"); + if (!hashf) { + fprintf(stderr, "Couldn't open hash file: '%s': %s\n", + "pub_kak_hash.txt", strerror(errno)); + return 1; + } res = kwb_export_pubkey(kak, &secure_hdr->kak, hashf, "KAK"); -- cgit v1.2.3 From f0317d788221828089fe54433cf5c502d748ef77 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Tue, 17 Aug 2021 07:11:58 +0200 Subject: kwbimage: check return value of image_get_csk_index image_get_csk_index() may return -1 in case of an error. Don't use this value as index. This resolves Coverity CID 338488 Memory - illegal accesses (NEGATIVE_RETURNS) Signed-off-by: Heinrich Schuchardt Reviewed-by: Stefan Roese Reviewed-by: Pali Rohár --- tools/kwbimage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/kwbimage.c b/tools/kwbimage.c index b2694888d96..aa865cc443f 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1087,7 +1087,7 @@ int kwb_sign_csk_with_kak(struct image_tool_params *params, int csk_idx = image_get_csk_index(); struct sig_v1 tmp_sig; - if (csk_idx >= 16) { + if (csk_idx < 0 || csk_idx > 15) { fprintf(stderr, "Invalid CSK index %d\n", csk_idx); return 1; } -- cgit v1.2.3 From 4116a0f38a8ba6bc5e762cd291a65df4946216e7 Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Sun, 22 Aug 2021 12:31:35 +0200 Subject: tools: kwbimage: Remove comment about unimplemented register headers in v1 images Support for register headers in v1 images was implemented in commit 02ba70ad6822 ("tools: kwbimage: Add support for DATA command also for v1 images"). So remove old comment. Signed-off-by: Pali Rohár Fixes: 02ba70ad6822 ("tools: kwbimage: Add support for DATA command also for v1 images") Reviewed-by: Stefan Roese --- tools/kwbimage.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/kwbimage.c b/tools/kwbimage.c index aa865cc443f..d200ff24250 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -5,8 +5,6 @@ * * (C) Copyright 2013 Thomas Petazzoni * - * - * Not implemented: support for the register headers in v1 images */ #include "imagetool.h" -- cgit v1.2.3