From 8d0a4968d71c46105388b9f416349ef99f4efdf1 Mon Sep 17 00:00:00 2001 From: Alexey Brodkin Date: Tue, 2 Oct 2018 15:04:39 +0300 Subject: [PATCH 01/10] iot_dk: Add localversion string Signed-off-by: Alexey Brodkin --- configs/iot_devkit_defconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/iot_devkit_defconfig b/configs/iot_devkit_defconfig index 1f0f9c3..0c5aba3 100644 --- a/configs/iot_devkit_defconfig +++ b/configs/iot_devkit_defconfig @@ -6,6 +6,7 @@ CONFIG_SYS_DCACHE_OFF=y CONFIG_TARGET_IOT_DEVKIT=y CONFIG_SYS_TEXT_BASE=0x20000000 CONFIG_SYS_CLK_FREQ=16000000 +CONFIG_LOCALVERSION="-iotdk-1.0" # CONFIG_ARCH_FIXUP_FDT_MEMORY is not set CONFIG_SYS_PROMPT="IoTDK# " # CONFIG_CMD_BOOTD is not set From 18e8923f6c27a0c66f35f09223290c4ad2c19f69 Mon Sep 17 00:00:00 2001 From: Alexey Brodkin Date: Tue, 9 Oct 2018 13:26:26 +0300 Subject: [PATCH 02/10] iot_dk: Disable networking support There's no Ethernet controller on the board so no point in having networking support. This also saves us 5.5 kB of precious memory. | # bloat-o-meter u-boot.net u-boot.no_net_regex | tail -1 | Total: Before=127892, After=122334, chg -4.35% Signed-off-by: Alexey Brodkin --- configs/iot_devkit_defconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs/iot_devkit_defconfig b/configs/iot_devkit_defconfig index 0c5aba3..3facce1 100644 --- a/configs/iot_devkit_defconfig +++ b/configs/iot_devkit_defconfig @@ -18,7 +18,6 @@ CONFIG_SYS_PROMPT="IoTDK# " # CONFIG_CMD_LOADS is not set CONFIG_CMD_MMC=y CONFIG_CMD_USB=y -# CONFIG_CMD_NET is not set CONFIG_CMD_FAT=y CONFIG_OF_CONTROL=y CONFIG_OF_EMBED=y @@ -26,6 +25,7 @@ CONFIG_DEFAULT_DEVICE_TREE="iot_devkit" CONFIG_ENV_IS_IN_FAT=y CONFIG_ENV_FAT_INTERFACE="mmc" CONFIG_ENV_FAT_DEVICE_AND_PART="0:1" +# CONFIG_NET is not set CONFIG_DM=y CONFIG_MMC=y CONFIG_MMC_DW=y From ba9f56f3d463f9404f41958cefe2765c9a6bddcf Mon Sep 17 00:00:00 2001 From: Alexey Brodkin Date: Wed, 10 Oct 2018 13:59:33 +0300 Subject: [PATCH 03/10] ARC: make generic print_cpuinfo() weak This allows board to override print_cpuinfo() because they might know better which ARChitect template was used. This way we may not only derive base architecture type and version but more meaningful things like "ARC EM7D" instead of simple "ARC EM", "ARC HS36" instead of "ARC HS". Signed-off-by: Alexey Brodkin --- arch/arc/lib/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arc/lib/cpu.c b/arch/arc/lib/cpu.c index 50cd7cd..a969a16 100644 --- a/arch/arc/lib/cpu.c +++ b/arch/arc/lib/cpu.c @@ -60,7 +60,7 @@ const char *decode_identity(void) } } -int print_cpuinfo(void) +__weak int print_cpuinfo(void) { printf("CPU: %s\n", decode_identity()); return 0; From 5b86ca96d03c781f2035c0ecfea526d42f6999f6 Mon Sep 17 00:00:00 2001 From: Alexey Brodkin Date: Wed, 10 Oct 2018 14:03:47 +0300 Subject: [PATCH 04/10] iot_dk/hsdk: Implement its own print_cpuinfo() ARC IDENTITY register only encodes major architecture type and version while for a particular board/silicon we may know better which template was used and so we may identify CPU more precise, which exactly we do here. Signed-off-by: Alexey Brodkin --- board/synopsys/hsdk/hsdk.c | 8 ++++++++ board/synopsys/iot_devkit/iot_devkit.c | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/board/synopsys/hsdk/hsdk.c b/board/synopsys/hsdk/hsdk.c index fb4286f..4f46d2e 100644 --- a/board/synopsys/hsdk/hsdk.c +++ b/board/synopsys/hsdk/hsdk.c @@ -1046,3 +1046,11 @@ int board_mmc_init(bd_t *bis) return 0; } + +#ifdef CONFIG_DISPLAY_CPUINFO +int print_cpuinfo(void) +{ + printf("CPU: ARC HS38 v2.1c\n"); + return 0; +} +#endif /* CONFIG_DISPLAY_CPUINFO */ diff --git a/board/synopsys/iot_devkit/iot_devkit.c b/board/synopsys/iot_devkit/iot_devkit.c index c185d5c..1d848dd 100644 --- a/board/synopsys/iot_devkit/iot_devkit.c +++ b/board/synopsys/iot_devkit/iot_devkit.c @@ -166,3 +166,11 @@ int checkboard(void) puts("Board: Synopsys IoT Development Kit\n"); return 0; }; + +#ifdef CONFIG_DISPLAY_CPUINFO +int print_cpuinfo(void) +{ + printf("CPU: ARC EM9D\n"); + return 0; +} +#endif /* CONFIG_DISPLAY_CPUINFO */ From 7d388add5592dd65eac21fcbc77ca1cccec5fa38 Mon Sep 17 00:00:00 2001 From: Alexey Brodkin Date: Wed, 10 Oct 2018 14:20:11 +0300 Subject: [PATCH 05/10] iot_dk: Implement board reset It is done by writing some magic sequence in a special register. Signed-off-by: Alexey Brodkin --- board/synopsys/iot_devkit/iot_devkit.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/board/synopsys/iot_devkit/iot_devkit.c b/board/synopsys/iot_devkit/iot_devkit.c index 1d848dd..fb39e6d 100644 --- a/board/synopsys/iot_devkit/iot_devkit.c +++ b/board/synopsys/iot_devkit/iot_devkit.c @@ -17,6 +17,7 @@ DECLARE_GLOBAL_DATA_PTR; #define AHBCKDIV (void *)(SYSCON_BASE + 0x04) #define APBCKDIV (void *)(SYSCON_BASE + 0x08) #define APBCKEN (void *)(SYSCON_BASE + 0x0C) +#define RESET_REG (void *)(SYSCON_BASE + 0x18) #define CLKSEL (void *)(SYSCON_BASE + 0x24) #define CLKSTAT (void *)(SYSCON_BASE + 0x28) #define PLLCON (void *)(SYSCON_BASE + 0x2C) @@ -161,6 +162,13 @@ int board_mmc_init(bd_t *bis) return 0; } +#define IOTDK_RESET_SEQ 0x55AA6699 + +void reset_cpu(ulong addr) +{ + writel(IOTDK_RESET_SEQ, RESET_REG); +} + int checkboard(void) { puts("Board: Synopsys IoT Development Kit\n"); From 031154fe8f2b1b6b2a6e2d1449676a8c6dc42ebf Mon Sep 17 00:00:00 2001 From: Alexey Brodkin Date: Wed, 10 Oct 2018 15:53:45 +0300 Subject: [PATCH 06/10] iot_dk: Add support of 136 MHz clock Signed-off-by: Alexey Brodkin --- board/synopsys/iot_devkit/iot_devkit.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/board/synopsys/iot_devkit/iot_devkit.c b/board/synopsys/iot_devkit/iot_devkit.c index fb39e6d..04e003c 100644 --- a/board/synopsys/iot_devkit/iot_devkit.c +++ b/board/synopsys/iot_devkit/iot_devkit.c @@ -68,6 +68,14 @@ static int set_cpu_freq(unsigned int clk) writel((readl(PLLCON) & PLL_MASK_2) | 0x200191, PLLCON); break; + case 136: + writel(readl(PLLCON) & PLL_MASK_0, PLLCON); + /* pll_off=1, M=17, N=1, OD=1, PLL_OUT_CLK=136M */ + writel((readl(PLLCON) & PLL_MASK_1) | 0x100111, PLLCON); + /* pll_off=0, M=17, N=1, OD=1, PLL_OUT_CLK=136M */ + writel((readl(PLLCON) & PLL_MASK_2) | 0x100111, PLLCON); + break; + case 144: writel(readl(PLLCON) & PLL_MASK_0, PLLCON); /* pll_off=1, M=18, N=1, OD=1, PLL_OUT_CLK=144M */ From 8a8f32d8ff9db59fc3dccbc4da83dd78e13d9c3e Mon Sep 17 00:00:00 2001 From: Alexey Brodkin Date: Wed, 10 Oct 2018 16:15:20 +0300 Subject: [PATCH 07/10] iot_dk: Save CPU clock value to gd->cpu_clk Since gd->cpu_clk is a global item we may once populate it from .dtb ans use it then in other places like for printing CPU info etc. Signed-off-by: Alexey Brodkin --- board/synopsys/iot_devkit/iot_devkit.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/board/synopsys/iot_devkit/iot_devkit.c b/board/synopsys/iot_devkit/iot_devkit.c index 04e003c..40c29e7 100644 --- a/board/synopsys/iot_devkit/iot_devkit.c +++ b/board/synopsys/iot_devkit/iot_devkit.c @@ -108,7 +108,7 @@ extern u8 __ram_end[]; */ int mach_cpu_init(void) { - int offset, freq; + int offset; /* Don't relocate U-Boot */ gd->flags |= GD_FLG_SKIP_RELOC; @@ -129,12 +129,12 @@ int mach_cpu_init(void) if (offset < 0) return offset; - freq = fdtdec_get_int(gd->fdt_blob, offset, "clock-frequency", 0); - if (!freq) + gd->cpu_clk = fdtdec_get_int(gd->fdt_blob, offset, "clock-frequency", 0); + if (!gd->cpu_clk) return -EINVAL; /* If CPU freq > 100 MHz, divide eFLASH clock by 2 */ - if (freq > 100000000) { + if (gd->cpu_clk > 100000000) { u32 reg = readl(AHBCKDIV); reg &= ~(0xF << 8); @@ -142,7 +142,7 @@ int mach_cpu_init(void) writel(reg, AHBCKDIV); } - return set_cpu_freq(freq); + return set_cpu_freq(gd->cpu_clk); } #define ARC_PERIPHERAL_BASE 0xF0000000 @@ -186,7 +186,9 @@ int checkboard(void) #ifdef CONFIG_DISPLAY_CPUINFO int print_cpuinfo(void) { - printf("CPU: ARC EM9D\n"); + char mhz[8]; + + printf("CPU: ARC EM9D at %s MHz\n", strmhz(mhz, gd->cpu_clk)); return 0; } #endif /* CONFIG_DISPLAY_CPUINFO */ From 9f87d47088abdf514bdaed147145d98039bd5682 Mon Sep 17 00:00:00 2001 From: Alexey Brodkin Date: Thu, 11 Oct 2018 12:39:55 +0300 Subject: [PATCH 08/10] axs10x/emdk/hsdk/iot_dk: Implement board_mmc_getcd() So now we may detect MMC/SD-card existence and instead of completely misleading message on missing card: ------------------------>8----------------------- Loading Environment from FAT... Card did not respond to voltage select! ------------------------>8----------------------- we now get very clear one: ------------------------>8----------------------- Loading Environment from FAT... MMC: no card present ------------------------>8----------------------- Signed-off-by: Alexey Brodkin --- board/synopsys/axs10x/axs10x.c | 7 +++++++ board/synopsys/emdk/emdk.c | 7 +++++++ board/synopsys/hsdk/hsdk.c | 7 +++++++ board/synopsys/iot_devkit/iot_devkit.c | 7 +++++++ 4 files changed, 28 insertions(+) diff --git a/board/synopsys/axs10x/axs10x.c b/board/synopsys/axs10x/axs10x.c index af78127..c95f7af 100644 --- a/board/synopsys/axs10x/axs10x.c +++ b/board/synopsys/axs10x/axs10x.c @@ -33,6 +33,13 @@ int board_mmc_init(bd_t *bis) return 0; } +int board_mmc_getcd(struct mmc *mmc) +{ + struct dwmci_host *host = mmc->priv; + + return !(dwmci_readl(host, DWMCI_CDETECT) & 1); +} + #define AXS_MB_CREG 0xE0011000 int board_early_init_f(void) diff --git a/board/synopsys/emdk/emdk.c b/board/synopsys/emdk/emdk.c index bbb946a..79cafef 100644 --- a/board/synopsys/emdk/emdk.c +++ b/board/synopsys/emdk/emdk.c @@ -34,6 +34,13 @@ int board_mmc_init(bd_t *bis) return 0; } +int board_mmc_getcd(struct mmc *mmc) +{ + struct dwmci_host *host = mmc->priv; + + return !(dwmci_readl(host, DWMCI_CDETECT) & 1); +} + #define CREG_BASE 0xF0001000 #define CREG_BOOT_OFFSET 0 #define CREG_BOOT_WP_OFFSET 8 diff --git a/board/synopsys/hsdk/hsdk.c b/board/synopsys/hsdk/hsdk.c index 4f46d2e..b6aefdb 100644 --- a/board/synopsys/hsdk/hsdk.c +++ b/board/synopsys/hsdk/hsdk.c @@ -1019,6 +1019,13 @@ int board_late_init(void) return 0; } +int board_mmc_getcd(struct mmc *mmc) +{ + struct dwmci_host *host = mmc->priv; + + return !(dwmci_readl(host, DWMCI_CDETECT) & 1); +} + int board_mmc_init(bd_t *bis) { struct dwmci_host *host = NULL; diff --git a/board/synopsys/iot_devkit/iot_devkit.c b/board/synopsys/iot_devkit/iot_devkit.c index 40c29e7..f8838fb 100644 --- a/board/synopsys/iot_devkit/iot_devkit.c +++ b/board/synopsys/iot_devkit/iot_devkit.c @@ -170,6 +170,13 @@ int board_mmc_init(bd_t *bis) return 0; } +int board_mmc_getcd(struct mmc *mmc) +{ + struct dwmci_host *host = mmc->priv; + + return !(dwmci_readl(host, DWMCI_CDETECT) & 1); +} + #define IOTDK_RESET_SEQ 0x55AA6699 void reset_cpu(ulong addr) From a2110918559b34219721cf31bbe8bd94a843e1ac Mon Sep 17 00:00:00 2001 From: Alexey Brodkin Date: Thu, 11 Oct 2018 14:14:13 +0300 Subject: [PATCH 09/10] iot_dk: Link for eFlash That's what we'll have in production. But note it won't work for loading via JTAG as eFlash is not directly writable, one needs to use prebootloader to flash uboot.bin from SD-card into eFlash. Signed-off-by: Alexey Brodkin --- configs/iot_devkit_defconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs/iot_devkit_defconfig b/configs/iot_devkit_defconfig index 3facce1..1b6dd9e 100644 --- a/configs/iot_devkit_defconfig +++ b/configs/iot_devkit_defconfig @@ -4,7 +4,7 @@ CONFIG_CPU_ARCEM6=y CONFIG_SYS_ICACHE_OFF=y CONFIG_SYS_DCACHE_OFF=y CONFIG_TARGET_IOT_DEVKIT=y -CONFIG_SYS_TEXT_BASE=0x20000000 +CONFIG_SYS_TEXT_BASE=0x00000000 CONFIG_SYS_CLK_FREQ=16000000 CONFIG_LOCALVERSION="-iotdk-1.0" # CONFIG_ARCH_FIXUP_FDT_MEMORY is not set From 6e63314f432d32d2ce12a51dafa78129e81fe9cf Mon Sep 17 00:00:00 2001 From: Alexey Brodkin Date: Thu, 11 Oct 2018 23:12:05 +0300 Subject: [PATCH 10/10] ARC: Don't use COMMON section for global not-initialized variables By default GCC puts global non-initialized variables in COMMON section. And we used to ignore existence of COMMON section in our linker scripts though smart LD silently appended it right after .bss. And the problem here is variables from COMMON section even though require zeroing in run-time were not zeroed as they were placed right after __bss_end symbol. It was a pure luck we never faced serious problem due to this, but now it is fixed. Now as for some other architectures we'll just force GCC to put those global variables in normal .bss section. This solution is much nicer than adding COMMON section to each and every linker script. Signed-off-by: Alexey Brodkin --- arch/arc/config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arc/config.mk b/arch/arc/config.mk index d255c90..18005d9 100644 --- a/arch/arc/config.mk +++ b/arch/arc/config.mk @@ -43,7 +43,7 @@ PLATFORM_CPPFLAGS += -mcpu=archs endif PLATFORM_CPPFLAGS += -ffixed-r25 -D__ARC__ -gdwarf-2 -mno-sdata -PLATFORM_RELFLAGS += -ffunction-sections -fdata-sections +PLATFORM_RELFLAGS += -ffunction-sections -fdata-sections -fno-common # Needed for relocation LDFLAGS_FINAL += -pie --gc-sections