Skip to contentSkip to conversation

Refactor the architecture parts of mt7628

PATCH New Stefan Roese 2 participants 37 messages Apr 21, 2020 – Apr 27, 2020

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v7 cover Refactor the architecture parts of mt7628

This patch series are divided into two parts:

The main part is to rewrite the whole architecture code of mt7628:
* Lock parts of the d-cache for initial stack so the rest of the code can be reimplemented in C.
* Memory controller & DDR initialization have been fully written to support detecting DDR size automatically.
* DDR calibration has also been reimplemented with a clear logic.
* Implemented a new sysreset driver to take advantage of the reset controller so we can drop the use of syscon-based sysreset to reduce size.

The second part is to add SPL support for mt7628:
* With SPL enabled we can build the ROM-bootable and RAM-bootable binary simultaneously, and we can drop RAM boot related configs and defconfig files.
* Generate compressed u-boot.bin image for SPL to reduce size of final combined binary.
* Enable DM support for SPL for a more flexible device probing.
* Add a demo board (mt7628_rfb) aims at router application.

Changes since v2:
* Dropped a patch which removes unused parts of mt7628a.dtsi
* Move lzma decompression support to common spl_nor.c
* Move u-boot,dm-pre-reloc to u-boot-mt7628.dtsi

Changes since v3:
* Rebased on newest master branch
* Add a test for binman etype u-boot-lzma-img to make sure binman passes 100% code coverage
* Use u-boot-with-spl.bin for SPL-enabled output file
* Remove unused code from spl_nor loader.

Changes since v5:
* Rebased on newest master branch
* Made lzma decompressing support for legacy U-Boot images more generic, so that it can be easily integrated into other devices loaders as well

Changes since v6:
* Add spl_image_get_comp() to enable the compiler to optimize the switch/case statement away due to Dead Code Elimination as suggested by Daniel
* Moved cache flush to MIPS specific file as suggested by Daniel

Stefan Roese (6):
spl: Extract legacy image handling into separate file
spl: spl_legacy: Use IS_ENABLED() to remove #ifdef
spl: spl_nor: Move legacy image loading into spl_legacy.c
spl: spl_nor: Remove unused variable 'ret' warning
mips: spl: Flush cache before jumping to U-Boot proper
mips: mtmips: Increase CONFIG_SPL_SYS_MALLOC_F_LEN

Weijie Gao (20):
mips: add support to restore exception vector base before booting
linux
mips: mtmips: add predefined i-cache/d-cache size and linesize
mips: add an option to support initialize SRAM for initial stack
mips: start.S: avoid overwriting outside gd when clearing global data
in stack
sysreset: add reset controller based reboot driver
mips: mtmips: make use of sysreset-resetctrl for mt7628 soc
configs: enable CONFIG_RESTORE_EXCEPTION_VECTOR_BASE for all mtmips
boards
mips: add a mtmips-specific field to architecture-specific global data
mips: add a option to support not reserving malloc space on initial
stack
mips: mtmips: rewrite lowlevel codes of mt7628
dts: mtmips: add alternative pinmux node for uart2
mips: enable support for appending dtb to spl binary
mips: add an option to enable u_boot_list section for SPL loaders in
u-boot-spl.lds
lib: enable lzma decompression support for SPL build
Makefile: add support to generate LZMA compressed u-boot image
tools: binman: add etype file for u-boot-lzma-img
spl: spl_legacy: Add lzma decompression support for legacy image
mips: mtmips: add SPL support
mips: mtmips: enable SPL for all boards
mips: mtmips: add support for mt7628-rfb

 Makefile                                      |  19 +
 arch/mips/Kconfig                             |  66 ++++
 arch/mips/cpu/start.S                         |  16 +-
 arch/mips/cpu/u-boot-spl.lds                  |   4 +-
 arch/mips/dts/Makefile                        |   1 +
 arch/mips/dts/mediatek,mt7628-rfb.dts         |  67 ++++
 arch/mips/dts/mt7628-u-boot.dtsi              |  56 +++
 arch/mips/dts/mt7628a.dtsi                    |  17 +-
 arch/mips/include/asm/global_data.h           |   3 +
 arch/mips/include/asm/u-boot-mips.h           |   2 +
 arch/mips/lib/Makefile                        |   1 +
 arch/mips/lib/bootm.c                         |   3 +
 arch/mips/lib/spl.c                           |  21 ++
 arch/mips/lib/traps.c                         |  19 +
 arch/mips/mach-mtmips/Kconfig                 | 135 +++----
 arch/mips/mach-mtmips/Makefile                |   8 +-
 arch/mips/mach-mtmips/cpu.c                   |  58 +---
 arch/mips/mach-mtmips/ddr_cal.c               | 211 +++++++++++
 arch/mips/mach-mtmips/ddr_calibrate.c         | 309 -----------------
 arch/mips/mach-mtmips/ddr_init.c              | 194 +++++++++++
 arch/mips/mach-mtmips/include/mach/ddr.h      |  52 +++
 arch/mips/mach-mtmips/include/mach/mc.h       | 180 ++++++++++
 arch/mips/mach-mtmips/include/mach/serial.h   |  13 +
 arch/mips/mach-mtmips/lowlevel_init.S         | 328 ------------------
 arch/mips/mach-mtmips/mt7628/Makefile         |   6 +
 arch/mips/mach-mtmips/mt7628/ddr.c            | 173 +++++++++
 arch/mips/mach-mtmips/mt7628/init.c           | 109 ++++++
 arch/mips/mach-mtmips/mt7628/lowlevel_init.S  | 161 +++++++++
 arch/mips/mach-mtmips/mt7628/mt7628.h         | 104 ++++++
 arch/mips/mach-mtmips/mt7628/serial.c         |  34 ++
 arch/mips/mach-mtmips/mt76xx.h                |  32 --
 arch/mips/mach-mtmips/spl.c                   |  44 +++
 board/gardena/smart-gateway-mt7688/board.c    |   2 +
 board/mediatek/mt7628/Kconfig                 |  12 +
 board/mediatek/mt7628/MAINTAINERS             |   7 +
 board/mediatek/mt7628/Makefile                |   3 +
 board/mediatek/mt7628/board.c                 |   8 +
 common/spl/Makefile                           |   1 +
 common/spl/spl.c                              |  56 +--
 common/spl/spl_legacy.c                       | 131 +++++++
 common/spl/spl_nor.c                          |  27 +-
 ...gardena-smart-gateway-mt7688-ram_defconfig |  74 ----
 .../gardena-smart-gateway-mt7688_defconfig    |  14 +-
 configs/linkit-smart-7688-ram_defconfig       |  65 ----
 configs/linkit-smart-7688_defconfig           |  14 +-
 configs/mt7628_rfb_defconfig                  |  46 +++
 drivers/sysreset/Kconfig                      |   6 +
 drivers/sysreset/Makefile                     |   1 +
 drivers/sysreset/sysreset_resetctl.c          |  48 +++
 .../configs/gardena-smart-gateway-mt7688.h    |  21 +-
 include/configs/linkit-smart-7688.h           |  22 +-
 include/configs/mt7628.h                      |  56 +++
 include/spl.h                                 |  13 +
 lib/Kconfig                                   |   5 +
 lib/Makefile                                  |   1 +
 tools/binman/README.entries                   |  15 +
 tools/binman/etype/u_boot_lzma_img.py         |  28 ++
 tools/binman/ftest.py                         |   7 +
 tools/binman/test/156_u_boot_lzma_img.dts     |  11 +
 59 files changed, 2108 insertions(+), 1032 deletions(-)
 create mode 100644 arch/mips/dts/mediatek,mt7628-rfb.dts
 create mode 100644 arch/mips/dts/mt7628-u-boot.dtsi
 create mode 100644 arch/mips/lib/spl.c
 create mode 100644 arch/mips/mach-mtmips/ddr_cal.c
 delete mode 100644 arch/mips/mach-mtmips/ddr_calibrate.c
 create mode 100644 arch/mips/mach-mtmips/ddr_init.c
 create mode 100644 arch/mips/mach-mtmips/include/mach/ddr.h
 create mode 100644 arch/mips/mach-mtmips/include/mach/mc.h
 create mode 100644 arch/mips/mach-mtmips/include/mach/serial.h
 delete mode 100644 arch/mips/mach-mtmips/lowlevel_init.S
 create mode 100644 arch/mips/mach-mtmips/mt7628/Makefile
 create mode 100644 arch/mips/mach-mtmips/mt7628/ddr.c
 create mode 100644 arch/mips/mach-mtmips/mt7628/init.c
 create mode 100644 arch/mips/mach-mtmips/mt7628/lowlevel_init.S
 create mode 100644 arch/mips/mach-mtmips/mt7628/mt7628.h
 create mode 100644 arch/mips/mach-mtmips/mt7628/serial.c
 delete mode 100644 arch/mips/mach-mtmips/mt76xx.h
 create mode 100644 arch/mips/mach-mtmips/spl.c
 create mode 100644 board/mediatek/mt7628/Kconfig
 create mode 100644 board/mediatek/mt7628/MAINTAINERS
 create mode 100644 board/mediatek/mt7628/Makefile
 create mode 100644 board/mediatek/mt7628/board.c
 create mode 100644 common/spl/spl_legacy.c
 delete mode 100644 configs/gardena-smart-gateway-mt7688-ram_defconfig
 delete mode 100644 configs/linkit-smart-7688-ram_defconfig
 create mode 100644 configs/mt7628_rfb_defconfig
 create mode 100644 drivers/sysreset/sysreset_resetctl.c
 create mode 100644 include/configs/mt7628.h
 create mode 100644 tools/binman/etype/u_boot_lzma_img.py
 create mode 100644 tools/binman/test/156_u_boot_lzma_img.dts
Signature · 1 line
2.26.2
#1 lore raw

PATCH v7 1/26 mips: add support to restore exception vector base before booting linux

From: Weijie Gao <[email protected]>

In U-Boot the exception vector base will be moved to top of memory, to be used to display register dump when exception occurs.

But some old linux kernel does not honor the base set in CP0_EBASE. A modified exception vector base will cause kernel crash.

This patch adds an option to enable reset exception vector base to its previous value, or a user configured value before booting linux kernel.

---
Changes since v3: none

 arch/mips/Kconfig                   | 30 +++++++++++++++++++++++++++++
 arch/mips/include/asm/u-boot-mips.h |  2 ++
 arch/mips/lib/bootm.c               |  3 +++
 arch/mips/lib/traps.c               | 19 ++++++++++++++++++
 4 files changed, 54 insertions(+)
arch/mips/Kconfig +30 -0
index a3ae603044..5e20feeefb 100644
@@ -287,6 +287,36 @@ config MIPS_RELOCATION_TABLE_SIZE
 
 	  If unsure, leave at the default value.
 
+config RESTORE_EXCEPTION_VECTOR_BASE
+	bool "Restore exception vector base before booting linux kernel"
+	default n
+	help
+	  In U-Boot the exception vector base will be moved to top of memory,
+	  to be used to display register dump when exception occurs.
+	  But some old linux kernel does not honor the base set in CP0_EBASE.
+	  A modified exception vector base will cause kernel crash.
+
+	  This option will restore the exception vector base to its previous
+	  value.
+
+	  If unsure, say N.
+
+config OVERRIDE_EXCEPTION_VECTOR_BASE
+	bool "Override the exception vector base to be restored"
+	depends on RESTORE_EXCEPTION_VECTOR_BASE
+	default n
+	help
+	  Enable this option if you want to use a different exception vector
+	  base rather than the previously saved one.
+
+config NEW_EXCEPTION_VECTOR_BASE
+	hex "New exception vector base"
+	depends on OVERRIDE_EXCEPTION_VECTOR_BASE
+	range 0x80000000 0xbffff000
+	default 0x80000000
+	help
+	  The exception vector base to be restored before booting linux kernel
+
 endmenu
 
 menu "OS boot interface"
arch/mips/include/asm/u-boot-mips.h +2 -0
index 88438b9576..8b37cc4029 100644
@@ -9,4 +9,6 @@ void except_vec_ejtag_debug(void);
 
 int arch_misc_init(void);
 
+void trap_restore(void);
+
 #endif /* _U_BOOT_MIPS_H_ */
arch/mips/lib/bootm.c +3 -0
index 8c0d7672f2..f1db6d23b8 100644
@@ -294,6 +294,9 @@ static void boot_jump_linux(bootm_headers_t *images)
 	bootstage_report();
 #endif
 
+	if (CONFIG_IS_ENABLED(RESTORE_EXCEPTION_VECTOR_BASE))
+		trap_restore();
+
 	if (images->ft_len)
 		kernel(-2, (ulong)images->ft_addr, 0, 0);
 	else
arch/mips/lib/traps.c +19 -0
index b8568c00fe..8fff7541e3 100644
@@ -20,6 +20,8 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+static unsigned long saved_ebase;
+
 static void show_regs(const struct pt_regs *regs)
 {
 	const int field = 2 * sizeof(unsigned long);
@@ -102,7 +104,24 @@ void trap_init(ulong reloc_addr)
 	set_handler(0x180, &except_vec3_generic, 0x80);
 	set_handler(0x280, &except_vec_ejtag_debug, 0x80);
 
+	saved_ebase = read_c0_ebase() & 0xfffff000;
+
 	write_c0_ebase(ebase);
 	clear_c0_status(ST0_BEV);
 	execution_hazard_barrier();
 }
+
+void trap_restore(void)
+{
+	set_c0_status(ST0_BEV);
+	execution_hazard_barrier();
+
+#ifdef CONFIG_OVERRIDE_EXCEPTION_VECTOR_BASE
+	write_c0_ebase(CONFIG_NEW_EXCEPTION_VECTOR_BASE & 0xfffff000);
+#else
+	write_c0_ebase(saved_ebase);
+#endif
+
+	clear_c0_status(ST0_BEV);
+	execution_hazard_barrier();
+}
Signature · 1 line
2.26.2
#2 lore raw

PATCH v7 2/26 mips: mtmips: add predefined i-cache/d-cache size and linesize

In reply to Stefan Roese

From: Weijie Gao <[email protected]>

Both mt7620 and mt7628 has the same cache configuration. There is no need to use CONFIG_SYS_CACHE_SIZE_AUTO to probe it at runtime.

Add them into Kconfig to reduce some code size.

---
Changes since v3: none

 arch/mips/mach-mtmips/Kconfig | 12 ++++++++++++
 1 file changed, 12 insertions(+)
arch/mips/mach-mtmips/Kconfig +12 -0
index c8dcf19c0d..8e10719b27 100644
@@ -7,6 +7,18 @@ config SYS_MALLOC_F_LEN
 config SYS_SOC
 	default "mt7628" if SOC_MT7628
 
+config SYS_DCACHE_SIZE
+	default 32768
+
+config SYS_DCACHE_LINE_SIZE
+	default 32
+
+config SYS_ICACHE_SIZE
+	default 65536
+
+config SYS_ICACHE_LINE_SIZE
+	default 32
+
 choice
 	prompt "MediaTek MIPS SoC select"
 
Signature · 1 line
2.26.2
#3 lore raw

PATCH v7 3/26 mips: add an option to support initialize SRAM for initial stack

In reply to Stefan Roese

From: Weijie Gao <[email protected]>

Currently CONFIG_MIPS_INIT_STACK_IN_SRAM assumes the memory space for the initial stack can be used directly. However on some platform the SRAM needs initialization, e.g. lock cache.

This patch adds an option to allow a new function mips_sram_init() being called before setup_stack_gd.

---
Changes since v3: none

 arch/mips/Kconfig     | 9 +++++++++
 arch/mips/cpu/start.S | 7 +++++++
 2 files changed, 16 insertions(+)
arch/mips/Kconfig +9 -0
index 5e20feeefb..bf30a56101 100644
@@ -419,6 +419,15 @@ config MIPS_INIT_STACK_IN_SRAM
 	  lowlevel_init. Thus lowlevel_init does not need to be implemented
 	  in assembler.
 
+config MIPS_SRAM_INIT
+	bool
+	default n
+	depends on MIPS_INIT_STACK_IN_SRAM
+	help
+	  Select this if the SRAM for initial stack needs to be initialized
+	  before it can be used. If enabled, a function mips_sram_init() will
+	  be called just before setup_stack_gd.
+
 config SYS_DCACHE_SIZE
 	int
 	default 0
arch/mips/cpu/start.S +7 -0
index 1d21b2324a..f9805fa000 100644
@@ -216,6 +216,13 @@ wr_done:
 #endif
 
 #ifdef CONFIG_MIPS_INIT_STACK_IN_SRAM
+#ifdef CONFIG_MIPS_SRAM_INIT
+	/* Initialize the SRAM first */
+	PTR_LA	t9, mips_sram_init
+	jalr	t9
+	 nop
+#endif
+
 	/* Set up initial stack and global data */
 	setup_stack_gd
 
Signature · 1 line
2.26.2
#4 lore raw

PATCH v7 4/26 mips: start.S: avoid overwriting outside gd when clearing global data in stack

In reply to Stefan Roese

From: Weijie Gao <[email protected]>

When setting up initial stack, global data will also be put in the stack, and being cleared.

The assembler instructions for clearing gd is as follows:

	move	t0, k0
1:
	PTR_S	zero, 0(t0)
	blt	t0, t1, 1b
	 PTR_ADDIU t0, PTRSIZE

t0 is the start address of gd, t1 is the end address of gd (t0 + GD_SIZE).

[PTR_ADDIU t0, PTRSIZE] is in the delay slot of [blt t0, t1, 1b], so it will be executed before the branch operation.

However the comparison for the BLT instruction is done before executing the delay slot. This means when the last word just before k1 is cleared, the loop will continue to run once. This will clear an extra word at k1, which is outside the global data.

Global data is placed at the top of the stack. If the initial stack is a SRAM or locked cache, the area outside them may be inaccessible. A write operation performed in this area may cause an exception.

To solve this, [PTR_ADDIU t0, PTRSIZE] should be placed before the BLT instruction.

---
Changes since v3: none

 arch/mips/cpu/start.S | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/mips/cpu/start.S +2 -1
index f9805fa000..dd93df9e4a 100644
@@ -71,8 +71,9 @@
 	move	t0, k0
 1:
 	PTR_S	zero, 0(t0)
+	PTR_ADDIU t0, PTRSIZE
 	blt	t0, t1, 1b
-	 PTR_ADDIU t0, PTRSIZE
+	 nop
 
 #if CONFIG_VAL(SYS_MALLOC_F_LEN)
 	PTR_S	sp, GD_MALLOC_BASE(k0)	# gd->malloc_base offset
Signature · 1 line
2.26.2
#5 lore raw

PATCH v7 5/26 sysreset: add reset controller based reboot driver

In reply to Stefan Roese

From: Weijie Gao <[email protected]>

Some chips provide their sysreset function in reset controller, which is normally a bit written to 1 to perform the sysreset.

This patch adds a new sysreset driver to take advantage of it.

---
Changes since v3: none

 drivers/sysreset/Kconfig             |  6 ++++
 drivers/sysreset/Makefile            |  1 +
 drivers/sysreset/sysreset_resetctl.c | 48 ++++++++++++++++++++++++++++
 3 files changed, 55 insertions(+)
 create mode 100644 drivers/sysreset/sysreset_resetctl.c
drivers/sysreset/Kconfig +6 -0
index f09e138bb8..4be7433404 100644
@@ -101,6 +101,12 @@ config SYSRESET_WATCHDOG
 	help
 	  Reboot support for generic watchdog reset.
 
+config SYSRESET_RESETCTL
+	bool "Enable support for reset controller reboot driver"
+	select DM_RESET
+	help
+	  Reboot support using generic reset controller.
+
 config SYSRESET_X86
 	bool "Enable support for x86 processor reboot driver"
 	depends on X86
drivers/sysreset/Makefile +1 -0
index 51af68fad3..3ed4bab9e3 100644
@@ -16,5 +16,6 @@ obj-$(CONFIG_SYSRESET_SOCFPGA_S10) += sysreset_socfpga_s10.o
 obj-$(CONFIG_SYSRESET_TI_SCI) += sysreset-ti-sci.o
 obj-$(CONFIG_SYSRESET_SYSCON) += sysreset_syscon.o
 obj-$(CONFIG_SYSRESET_WATCHDOG) += sysreset_watchdog.o
+obj-$(CONFIG_SYSRESET_RESETCTL) += sysreset_resetctl.o
 obj-$(CONFIG_$(SPL_TPL_)SYSRESET_X86) += sysreset_x86.o
 obj-$(CONFIG_TARGET_XTFPGA) += sysreset_xtfpga.o
drivers/sysreset/sysreset_resetctl.c new file +48 -0

48 lines not on this page · raw message

Signature · 1 line
2.26.2
#6 lore raw

PATCH v7 6/26 mips: mtmips: make use of sysreset-resetctrl for mt7628 soc

In reply to Stefan Roese

From: Weijie Gao <[email protected]>

This patch replaces sysreset-syscon with sysreset-resetctrl for mt7628 soc.

---
Changes since v3: none

 arch/mips/dts/mt7628a.dtsi                         | 10 +++++-----
 arch/mips/mach-mtmips/Kconfig                      |  1 +
 configs/gardena-smart-gateway-mt7688-ram_defconfig |  1 -
 configs/gardena-smart-gateway-mt7688_defconfig     |  1 -
 configs/linkit-smart-7688-ram_defconfig            |  1 -
 configs/linkit-smart-7688_defconfig                |  1 -
 6 files changed, 6 insertions(+), 9 deletions(-)
arch/mips/dts/mt7628a.dtsi +5 -5
index 76a80c8952..409695b5c7 100644
@@ -46,11 +46,11 @@
 			reg = <0x0 0x100>;
 		};
 
-		syscon-reboot {
-			compatible = "syscon-reboot";
-			regmap = <&sysc>;
-			offset = <0x34>;
-			mask = <0x1>;
+		reboot: resetctl-reboot {
+			compatible = "resetctl-reboot";
+
+			resets = <&rstctrl MT7628_SYS_RST>;
+			reset-names = "sysreset";
 		};
 
 		clkctrl: clkctrl at 0x2c {
arch/mips/mach-mtmips/Kconfig +1 -0
index 8e10719b27..8cb76c4560 100644
@@ -27,6 +27,7 @@ config SOC_MT7628
 	select MIPS_L1_CACHE_SHIFT_5
 	select PINCTRL_MT7628
 	select MTK_SERIAL
+	select SYSRESET_RESETCTL
 	help
 	  This supports MediaTek MT7628/MT7688.
 
configs/gardena-smart-gateway-mt7688-ram_defconfig +0 -1
index dbc94b4106..5e10a4051e 100644
@@ -68,7 +68,6 @@ CONFIG_MT7628_ETH=y
 CONFIG_PHY=y
 CONFIG_SPI=y
 CONFIG_MT7621_SPI=y
-CONFIG_SYSRESET_SYSCON=y
 CONFIG_WDT=y
 CONFIG_WDT_MT7621=y
 CONFIG_LZMA=y
configs/gardena-smart-gateway-mt7688_defconfig +0 -1
index 23d8ddb128..7a496fe5b3 100644
@@ -71,7 +71,6 @@ CONFIG_MT7628_ETH=y
 CONFIG_PHY=y
 CONFIG_SPI=y
 CONFIG_MT7621_SPI=y
-CONFIG_SYSRESET_SYSCON=y
 CONFIG_WDT=y
 CONFIG_WDT_MT7621=y
 CONFIG_LZMA=y
configs/linkit-smart-7688-ram_defconfig +0 -1
index d1691abfda..7f29617ddc 100644
@@ -53,7 +53,6 @@ CONFIG_PHY=y
 CONFIG_MT76X8_USB_PHY=y
 CONFIG_SPI=y
 CONFIG_MT7621_SPI=y
-CONFIG_SYSRESET_SYSCON=y
 CONFIG_USB=y
 CONFIG_DM_USB=y
 CONFIG_USB_EHCI_HCD=y
configs/linkit-smart-7688_defconfig +0 -1
index a567c0c507..484c338348 100644
@@ -57,7 +57,6 @@ CONFIG_PHY=y
 CONFIG_MT76X8_USB_PHY=y
 CONFIG_SPI=y
 CONFIG_MT7621_SPI=y
-CONFIG_SYSRESET_SYSCON=y
 CONFIG_USB=y
 CONFIG_DM_USB=y
 CONFIG_USB_EHCI_HCD=y
Signature · 1 line
2.26.2
#7 lore raw

PATCH v7 7/26 configs: enable CONFIG_RESTORE_EXCEPTION_VECTOR_BASE for all mtmips boards

In reply to Stefan Roese

From: Weijie Gao <[email protected]>

This patch enables CONFIG_RESTORE_EXCEPTION_VECTOR_BASE for all mtmips boards.

---
Changes since v3: none

 configs/gardena-smart-gateway-mt7688-ram_defconfig | 1 +
 configs/gardena-smart-gateway-mt7688_defconfig     | 1 +
 configs/linkit-smart-7688-ram_defconfig            | 1 +
 configs/linkit-smart-7688_defconfig                | 1 +
 4 files changed, 4 insertions(+)
configs/gardena-smart-gateway-mt7688-ram_defconfig +1 -0
index 5e10a4051e..48b7a43633 100644
@@ -8,6 +8,7 @@ CONFIG_NR_DRAM_BANKS=1
 CONFIG_SYS_BOOTCOUNT_SINGLEWORD=y
 CONFIG_ENV_OFFSET_REDUND=0xB0000
 CONFIG_ARCH_MTMIPS=y
+CONFIG_RESTORE_EXCEPTION_VECTOR_BASE=y
 # CONFIG_MIPS_BOOT_ENV_LEGACY is not set
 CONFIG_MIPS_BOOT_FDT=y
 CONFIG_ENV_VARS_UBOOT_CONFIG=y
configs/gardena-smart-gateway-mt7688_defconfig +1 -0
index 7a496fe5b3..7f040f5762 100644
@@ -11,6 +11,7 @@ CONFIG_ARCH_MTMIPS=y
 CONFIG_BOOT_ROM=y
 CONFIG_ONBOARD_DDR2_SIZE_1024MBIT=y
 CONFIG_ONBOARD_DDR2_CHIP_WIDTH_16BIT=y
+CONFIG_RESTORE_EXCEPTION_VECTOR_BASE=y
 # CONFIG_MIPS_BOOT_ENV_LEGACY is not set
 CONFIG_MIPS_BOOT_FDT=y
 CONFIG_ENV_VARS_UBOOT_CONFIG=y
configs/linkit-smart-7688-ram_defconfig +1 -0
index 7f29617ddc..1db94db41f 100644
@@ -6,6 +6,7 @@ CONFIG_ENV_OFFSET=0x80000
 CONFIG_NR_DRAM_BANKS=1
 CONFIG_ARCH_MTMIPS=y
 CONFIG_BOARD_LINKIT_SMART_7688=y
+CONFIG_RESTORE_EXCEPTION_VECTOR_BASE=y
 # CONFIG_MIPS_BOOT_ENV_LEGACY is not set
 CONFIG_MIPS_BOOT_FDT=y
 CONFIG_FIT=y
configs/linkit-smart-7688_defconfig +1 -0
index 484c338348..7993976443 100644
@@ -9,6 +9,7 @@ CONFIG_BOARD_LINKIT_SMART_7688=y
 CONFIG_BOOT_ROM=y
 CONFIG_ONBOARD_DDR2_SIZE_1024MBIT=y
 CONFIG_ONBOARD_DDR2_CHIP_WIDTH_16BIT=y
+CONFIG_RESTORE_EXCEPTION_VECTOR_BASE=y
 # CONFIG_MIPS_BOOT_ENV_LEGACY is not set
 CONFIG_MIPS_BOOT_FDT=y
 CONFIG_FIT=y
Signature · 1 line
2.26.2
#8 lore raw

PATCH v7 8/26 mips: add a mtmips-specific field to architecture-specific global data

In reply to Stefan Roese

From: Weijie Gao <[email protected]>

SoCs of mtmips can use different CPU frequencies depending on the HW/SW configurations. For example mt7628 uses 580MHz clock if the input xtal frequency is 40MHz, and 575MHz clock if the xtal is 25MHz. Upon cold boot the CPU uses the xtal frequency directly.

So hardcoding the timer frequency (half of the CPU frequency) in CONFIG_SYS_MIPS_TIMER_FREQ is not a good idea for this case.

This patch adds a mtmips-specific field timer_freq to arch_global_data. This field will be used later in mtmips-specific get_tbclk() to provide accurate timer frequency in different boot stage.

---
Changes since v3: none

 arch/mips/include/asm/global_data.h | 3 +++
 1 file changed, 3 insertions(+)
arch/mips/include/asm/global_data.h +3 -0
index 7b4ad083ba..4c30fab871 100644
@@ -27,6 +27,9 @@ struct arch_global_data {
 #ifdef CONFIG_MIPS_L2_CACHE
 	unsigned short l2_line_size;
 #endif
+#ifdef CONFIG_ARCH_MTMIPS
+	unsigned long timer_freq;
+#endif
 };
 
 #include <asm-generic/global_data.h>
Signature · 1 line
2.26.2
#9 lore raw

PATCH v7 9/26 mips: add a option to support not reserving malloc space on initial stack

In reply to Stefan Roese

From: Weijie Gao <[email protected]>

The initial stack on some platforms is too small to hold a large malloc space. This patch adds a option to allow these platforms not reserving the malloc space on initial stack. These platforms should set the malloc base after DRAM is usable.

---
Changes since v3: none

 arch/mips/Kconfig     | 18 ++++++++++++++++++
 arch/mips/cpu/start.S |  6 ++++--
 2 files changed, 22 insertions(+), 2 deletions(-)
arch/mips/Kconfig +18 -0
index bf30a56101..5f82caf8be 100644
@@ -317,6 +317,24 @@ config NEW_EXCEPTION_VECTOR_BASE
 	help
 	  The exception vector base to be restored before booting linux kernel
 
+config INIT_STACK_WITHOUT_MALLOC_F
+	bool "Do not reserve malloc space on initial stack"
+	default n
+	help
+	  Enable this option if you don't want to reserve malloc space on
+	  initial stack. This is useful if the initial stack can't hold large
+	  malloc space. Platform should set the malloc_base later when DRAM is
+	  ready to use.
+
+config SPL_INIT_STACK_WITHOUT_MALLOC_F
+	bool "Do not reserve malloc space on initial stack in SPL"
+	default n
+	help
+	  Enable this option if you don't want to reserve malloc space on
+	  initial stack. This is useful if the initial stack can't hold large
+	  malloc space. Platform should set the malloc_base later when DRAM is
+	  ready to use.
+
 endmenu
 
 menu "OS boot interface"
arch/mips/cpu/start.S +4 -2
index dd93df9e4a..6de9a2f362 100644
@@ -59,7 +59,8 @@
 		sp, sp, GD_SIZE		# reserve space for gd
 	and	sp, sp, t0		# force 16 byte alignment
 	move	k0, sp			# save gd pointer
-#if CONFIG_VAL(SYS_MALLOC_F_LEN)
+#if CONFIG_VAL(SYS_MALLOC_F_LEN) && \
+    !CONFIG_IS_ENABLED(INIT_STACK_WITHOUT_MALLOC_F)
 	li	t2, CONFIG_VAL(SYS_MALLOC_F_LEN)
 	PTR_SUBU \
 		sp, sp, t2		# reserve space for early malloc
@@ -75,7 +76,8 @@
 	blt	t0, t1, 1b
 	 nop
 
-#if CONFIG_VAL(SYS_MALLOC_F_LEN)
+#if CONFIG_VAL(SYS_MALLOC_F_LEN) && \
+    !CONFIG_IS_ENABLED(INIT_STACK_WITHOUT_MALLOC_F)
 	PTR_S	sp, GD_MALLOC_BASE(k0)	# gd->malloc_base offset
 #endif
 	.endm
Signature · 1 line
2.26.2
#10 lore raw

PATCH v7 10/26 mips: mtmips: rewrite lowlevel codes of mt7628

In reply to Stefan Roese

From: Weijie Gao <[email protected]>

This patch rewrites the mtmips architecture with the following changes:

1. Move MT7628 soc parts into a subfolder.
2. Lock parts of D-Cache as temporary stack.
3. Reimplement DDR initialization in C language.
4. Reimplement DDR calibration in a clear logic.
5. Add full support for auto size detection for DDR1 and DDR2.
6. Use accurate CPU clock depending on the input xtal frequency for timer and delay functions.

Note:

print_cpuinfo() has incompatible parts with MT7620 so it's moved into mt7628 subfolder.

---
Changes since v3: none

 arch/mips/mach-mtmips/Kconfig                 |  69 +---
 arch/mips/mach-mtmips/Makefile                |   7 +-
 arch/mips/mach-mtmips/cpu.c                   |  58 +---
 arch/mips/mach-mtmips/ddr_cal.c               | 211 +++++++++++
 arch/mips/mach-mtmips/ddr_calibrate.c         | 309 -----------------
 arch/mips/mach-mtmips/ddr_init.c              | 194 +++++++++++
 arch/mips/mach-mtmips/include/mach/ddr.h      |  52 +++
 arch/mips/mach-mtmips/include/mach/mc.h       | 180 ++++++++++
 arch/mips/mach-mtmips/lowlevel_init.S         | 328 ------------------
 arch/mips/mach-mtmips/mt7628/Makefile         |   5 +
 arch/mips/mach-mtmips/mt7628/ddr.c            | 173 +++++++++
 arch/mips/mach-mtmips/mt7628/init.c           | 109 ++++++
 arch/mips/mach-mtmips/mt7628/lowlevel_init.S  | 161 +++++++++
 arch/mips/mach-mtmips/mt7628/mt7628.h         | 104 ++++++
 arch/mips/mach-mtmips/mt76xx.h                |  32 --
 .../gardena-smart-gateway-mt7688_defconfig    |   2 -
 configs/linkit-smart-7688_defconfig           |   2 -
 17 files changed, 1201 insertions(+), 795 deletions(-)
 create mode 100644 arch/mips/mach-mtmips/ddr_cal.c
 delete mode 100644 arch/mips/mach-mtmips/ddr_calibrate.c
 create mode 100644 arch/mips/mach-mtmips/ddr_init.c
 create mode 100644 arch/mips/mach-mtmips/include/mach/ddr.h
 create mode 100644 arch/mips/mach-mtmips/include/mach/mc.h
 delete mode 100644 arch/mips/mach-mtmips/lowlevel_init.S
 create mode 100644 arch/mips/mach-mtmips/mt7628/Makefile
 create mode 100644 arch/mips/mach-mtmips/mt7628/ddr.c
 create mode 100644 arch/mips/mach-mtmips/mt7628/init.c
 create mode 100644 arch/mips/mach-mtmips/mt7628/lowlevel_init.S
 create mode 100644 arch/mips/mach-mtmips/mt7628/mt7628.h
 delete mode 100644 arch/mips/mach-mtmips/mt76xx.h
arch/mips/mach-mtmips/Kconfig +6 -63
index 8cb76c4560..3f25de8b85 100644
@@ -19,12 +19,18 @@ config SYS_ICACHE_SIZE
 config SYS_ICACHE_LINE_SIZE
 	default 32
 
+config SYS_TEXT_BASE
+	default 0x9c000000
+
 choice
 	prompt "MediaTek MIPS SoC select"
 
 config SOC_MT7628
 	bool "MT7628"
 	select MIPS_L1_CACHE_SHIFT_5
+	select MIPS_INIT_STACK_IN_SRAM
+	select MIPS_SRAM_INIT
+	select SYS_MIPS_CACHE_INIT_RAM_LOAD
 	select PINCTRL_MT7628
 	select MTK_SERIAL
 	select SYSRESET_RESETCTL
@@ -79,69 +85,6 @@ config BOOT_ROM
 
 endchoice
 
-choice
-	prompt "DDR2 size"
-
-config ONBOARD_DDR2_SIZE_256MBIT
-	bool "256MBit (32MByte) total size"
-	depends on BOOT_ROM
-	help
-	  Use 256MBit (32MByte) of DDR total size
-
-config ONBOARD_DDR2_SIZE_512MBIT
-	bool "512MBit (64MByte) total size"
-	depends on BOOT_ROM
-	help
-	  Use 512MBit (64MByte) of DDR total size
-
-config ONBOARD_DDR2_SIZE_1024MBIT
-	bool "1024MBit (128MByte) total size"
-	depends on BOOT_ROM
-	help
-	  Use 1024MBit (128MByte) of DDR total size
-
-config ONBOARD_DDR2_SIZE_2048MBIT
-	bool "2048MBit (256MByte) total size"
-	depends on BOOT_ROM
-	help
-	  Use 2048MBit (256MByte) of DDR total size
-
-endchoice
-
-choice
-	prompt "DDR2 chip width"
-
-config ONBOARD_DDR2_CHIP_WIDTH_8BIT
-	bool "8bit DDR chip width"
-	depends on BOOT_ROM
-	help
-	  Use DDR chips with 8bit width
-
-config ONBOARD_DDR2_CHIP_WIDTH_16BIT
-	bool "16bit DDR chip width"
-	depends on BOOT_ROM
-	help
-	  Use DDR chips with 16bit width
-
-endchoice
-
-choice
-	prompt "DDR2 bus width"
-
-config ONBOARD_DDR2_BUS_WIDTH_16BIT
-	bool "16bit DDR bus width"
-	depends on BOOT_ROM
-	help
-	  Use 16bit DDR bus width
-
-config ONBOARD_DDR2_BUS_WIDTH_32BIT
-	bool "32bit DDR bus width"
-	depends on BOOT_ROM
-	help
-	  Use 32bit DDR bus width
-
-endchoice
-
 config SUPPORTS_BOOT_RAM
 	bool
 
arch/mips/mach-mtmips/Makefile +3 -4
index 1f3e65e8a5..72f0369030 100644
@@ -1,8 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0+
 
 obj-y += cpu.o
+obj-y += ddr_init.o
+obj-y += ddr_cal.o
 
-ifndef CONFIG_SKIP_LOWLEVEL_INIT
-obj-y += ddr_calibrate.o
-obj-y += lowlevel_init.o
-endif
+obj-$(CONFIG_SOC_MT7628) += mt7628/
arch/mips/mach-mtmips/cpu.c +3 -55

72 lines not on this page · raw message

arch/mips/mach-mtmips/ddr_cal.c new file +211 -0

211 lines not on this page · raw message

arch/mips/mach-mtmips/ddr_calibrate.c deleted +0 -309

309 lines not on this page · raw message

arch/mips/mach-mtmips/ddr_init.c new file +194 -0

194 lines not on this page · raw message

arch/mips/mach-mtmips/include/mach/ddr.h new file +52 -0

52 lines not on this page · raw message

arch/mips/mach-mtmips/include/mach/mc.h new file +180 -0

180 lines not on this page · raw message

arch/mips/mach-mtmips/lowlevel_init.S deleted +0 -328

328 lines not on this page · raw message

arch/mips/mach-mtmips/mt7628/Makefile new file +5 -0
new file mode 100644
index 0000000000..db62e90d77
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-y += lowlevel_init.o
+obj-y += init.o
+obj-y += ddr.o
arch/mips/mach-mtmips/mt7628/ddr.c new file +173 -0

173 lines not on this page · raw message

arch/mips/mach-mtmips/mt7628/init.c new file +109 -0

109 lines not on this page · raw message

arch/mips/mach-mtmips/mt7628/lowlevel_init.S new file +161 -0

161 lines not on this page · raw message

arch/mips/mach-mtmips/mt7628/mt7628.h new file +104 -0

104 lines not on this page · raw message

arch/mips/mach-mtmips/mt76xx.h deleted +0 -32
deleted file mode 100644
index 17473ea8f1..0000000000
@@ -1,32 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ */
-/*
- * Copyright (C) 2018 Stefan Roese <[email protected]>
- */
-
-#ifndef __MT76XX_H
-#define __MT76XX_H
-
-#define MT76XX_SYSCTL_BASE	0x10000000
-
-#define MT76XX_CHIPID_OFFS	0x00
-#define MT76XX_CHIP_REV_ID_OFFS	0x0c
-#define MT76XX_SYSCFG0_OFFS	0x10
-
-#define MT76XX_MEMCTRL_BASE	(MT76XX_SYSCTL_BASE + 0x0300)
-#define MT76XX_RGCTRL_BASE	(MT76XX_SYSCTL_BASE + 0x1000)
-
-#define MT76XX_ROM_STATUS_REG	(MT76XX_SYSCTL_BASE + 0x0028)
-#define MT76XX_CLKCFG0_REG	(MT76XX_SYSCTL_BASE + 0x002c)
-#define MT76XX_DYN_CFG0_REG	(MT76XX_SYSCTL_BASE + 0x0440)
-
-#define DDR_CFG1_REG		(MT76XX_MEMCTRL_BASE + 0x44)
-#define DDR_CFG2_REG		(MT76XX_MEMCTRL_BASE + 0x48)
-#define DDR_CFG3_REG		(MT76XX_MEMCTRL_BASE + 0x4c)
-#define DDR_CFG4_REG		(MT76XX_MEMCTRL_BASE + 0x50)
-
-#ifndef __ASSEMBLY__
-/* Prototypes */
-void ddr_calibrate(void);
-#endif
-
-#endif
configs/gardena-smart-gateway-mt7688_defconfig +0 -2
index 7f040f5762..0209af0fc9 100644
@@ -9,8 +9,6 @@ CONFIG_SYS_BOOTCOUNT_SINGLEWORD=y
 CONFIG_ENV_OFFSET_REDUND=0xB0000
 CONFIG_ARCH_MTMIPS=y
 CONFIG_BOOT_ROM=y
-CONFIG_ONBOARD_DDR2_SIZE_1024MBIT=y
-CONFIG_ONBOARD_DDR2_CHIP_WIDTH_16BIT=y
 CONFIG_RESTORE_EXCEPTION_VECTOR_BASE=y
 # CONFIG_MIPS_BOOT_ENV_LEGACY is not set
 CONFIG_MIPS_BOOT_FDT=y
configs/linkit-smart-7688_defconfig +0 -2
index 7993976443..34066dd293 100644
@@ -7,8 +7,6 @@ CONFIG_NR_DRAM_BANKS=1
 CONFIG_ARCH_MTMIPS=y
 CONFIG_BOARD_LINKIT_SMART_7688=y
 CONFIG_BOOT_ROM=y
-CONFIG_ONBOARD_DDR2_SIZE_1024MBIT=y
-CONFIG_ONBOARD_DDR2_CHIP_WIDTH_16BIT=y
 CONFIG_RESTORE_EXCEPTION_VECTOR_BASE=y
 # CONFIG_MIPS_BOOT_ENV_LEGACY is not set
 CONFIG_MIPS_BOOT_FDT=y
Signature · 1 line
2.26.2
#11 lore raw

PATCH v7 11/26 dts: mtmips: add alternative pinmux node for uart2

In reply to Stefan Roese

From: Weijie Gao <[email protected]>

This patch adds a new pinmux for UART2, which shares the pins with SPIS.

---
Changes since v3: none

 arch/mips/dts/mt7628a.dtsi | 5 +++++
 1 file changed, 5 insertions(+)
arch/mips/dts/mt7628a.dtsi +5 -0
index 409695b5c7..2200135a77 100644
@@ -110,6 +110,11 @@
 				function = "uart2";
 			};
 
+			uart2_pwm_pins: uart2_pwm_pins {
+				groups = "spis";
+				function = "pwm_uart2";
+			};
+
 			i2c_pins: i2c_pins {
 				groups = "i2c";
 				function = "i2c";
Signature · 1 line
2.26.2
#12 lore raw

PATCH v7 12/26 mips: enable support for appending dtb to spl binary

In reply to Stefan Roese

From: Weijie Gao <[email protected]>

If CONFIG_SPL_OF_CONTROL is enabled for SPL and CONFIG_OF_SEPARATE is also enabled, the dtb will be appended to the u-boot-spl.bin.

When calling dm_init_and_scan() in SPL, fdtdec_setup() will try to locate dtb at the end of u-boot-spl.bin, by referencing to _image_binary_end.

However _image_binary_end is currently missing in u-boot-spl.lds. This patch adds _image_binary_end to u-boot-spl.lds to make sure linking u-boot-spl will not fail.

---
Changes since v3: none

 arch/mips/cpu/u-boot-spl.lds | 2 ++
 1 file changed, 2 insertions(+)
arch/mips/cpu/u-boot-spl.lds +2 -0
index d08d6222c4..e467491639 100644
@@ -37,6 +37,8 @@ SECTIONS
 	. = ALIGN(4);
 	__image_copy_end = .;
 
+	_image_binary_end = .;
+
 	.bss (NOLOAD) : {
 		__bss_start = .;
 		*(.bss*)
Signature · 1 line
2.26.2
#13 lore raw

PATCH v7 13/26 mips: add an option to enable u_boot_list section for SPL loaders in u-boot-spl.lds

In reply to Stefan Roese

From: Weijie Gao <[email protected]>

u_boot_list is not only used by DM, but also by some SPL image load methods such as spl_nor.c.

This patch adds an option CONFIG_SPL_LOADER_SUPPORT in conjunction with CONFIG_SPL_DM surrounding the u_boot_list section to make sure SPL image loaders can be correctly built into u-boot SPL without DM enabled.

---
Changes since v3: none

 arch/mips/Kconfig            | 6 ++++++
 arch/mips/cpu/u-boot-spl.lds | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)
arch/mips/Kconfig +6 -0
index 5f82caf8be..7b9d0072eb 100644
@@ -335,6 +335,12 @@ config SPL_INIT_STACK_WITHOUT_MALLOC_F
 	  malloc space. Platform should set the malloc_base later when DRAM is
 	  ready to use.
 
+config SPL_LOADER_SUPPORT
+	bool
+	default n
+	help
+	  Enable this option if you want to use SPL loaders without DM enabled.
+
 endmenu
 
 menu "OS boot interface"
arch/mips/cpu/u-boot-spl.lds +1 -1
index e467491639..28ea4f2a48 100644
@@ -27,7 +27,7 @@ SECTIONS
 		*(SORT_BY_ALIGNMENT(.sdata*))
 	} > .spl_mem
 
-#ifdef CONFIG_SPL_DM
+#if defined(CONFIG_SPL_DM) || defined(CONFIG_SPL_LOADER_SUPPORT)
 	. = ALIGN(4);
 	.u_boot_list : {
 		KEEP(*(SORT(.u_boot_list*)));
Signature · 1 line
2.26.2
#14 lore raw

PATCH v7 14/26 lib: enable lzma decompression support for SPL build

In reply to Stefan Roese

From: Weijie Gao <[email protected]>

This patch enables LZMA decompression support for SPL build

---
Changes since v3: none

 lib/Kconfig  | 5 +++++
 lib/Makefile | 1 +
 2 files changed, 6 insertions(+)
lib/Kconfig +5 -0
index 452f390c80..a441cd162a 100644
@@ -429,6 +429,11 @@ config SPL_LZ4
 	  fast compression and decompression speed. It belongs to the LZ77
 	  family of byte-oriented compression schemes.
 
+config SPL_LZMA
+	bool "Enable LZMA decompression support for SPL build"
+	help
+	  This enables support for LZMA compression altorithm for SPL boot.
+
 config SPL_LZO
 	bool "Enable LZO decompression support in SPL"
 	help
lib/Makefile +1 -0
index 5f88d92850..283b00ffe6 100644
@@ -67,6 +67,7 @@ obj-$(CONFIG_$(SPL_)ZLIB) += zlib/
 obj-$(CONFIG_$(SPL_)ZSTD) += zstd/
 obj-$(CONFIG_$(SPL_)GZIP) += gunzip.o
 obj-$(CONFIG_$(SPL_)LZO) += lzo/
+obj-$(CONFIG_$(SPL_)LZMA) += lzma/
 obj-$(CONFIG_$(SPL_)LZ4) += lz4_wrapper.o
 
 obj-$(CONFIG_LIBAVB) += libavb/
Signature · 1 line
2.26.2
#15 lore raw

PATCH v7 15/26 Makefile: add support to generate LZMA compressed u-boot image

In reply to Stefan Roese

From: Weijie Gao <[email protected]>

This patch adds support for generating LZMA compressed u-boot image. The compressed image can be used for SPL to reduce the size of the u-boot binary.

---
Changes since v3: none

 Makefile | 13 +++++++++++++
 1 file changed, 13 insertions(+)
Makefile +13 -0
index 26307fd4a6..ffc1e28bd0 100644
@@ -1000,6 +1000,9 @@ append = cat $(filter-out $< $(PHONY), $^) >> $@
 quiet_cmd_pad_cat = CAT     $@
 cmd_pad_cat = $(cmd_objcopy) && $(append) || rm -f $@
 
+quiet_cmd_lzma = LZMA    $@
+cmd_lzma = lzma -c -z -k -9 $< > $@
+
 cfg: u-boot.cfg
 
 quiet_cmd_cfgcheck = CFGCHK  $2
@@ -1382,6 +1385,16 @@ else
 UBOOT_BIN := u-boot.bin
 endif
 
+MKIMAGEFLAGS_u-boot-lzma.img = -A $(ARCH) -T standalone -C lzma -O u-boot \
+	-a $(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_UBOOT_START) \
+	-n "U-Boot $(UBOOTRELEASE) for $(BOARD) board"
+
+u-boot.bin.lzma: u-boot.bin FORCE
+	$(call if_changed,lzma)
+
+u-boot-lzma.img: u-boot.bin.lzma FORCE
+	$(call if_changed,mkimage)
+
 u-boot-dtb.img u-boot.img u-boot.kwb u-boot.pbl u-boot-ivt.img: \
 		$(if $(CONFIG_SPL_LOAD_FIT),u-boot-nodtb.bin \
 			$(if $(CONFIG_OF_SEPARATE)$(CONFIG_OF_EMBED)$(CONFIG_OF_HOSTFILE),dts/dt.dtb) \
Signature · 1 line
2.26.2
#16 lore raw

PATCH v7 16/26 tools: binman: add etype file for u-boot-lzma-img

In reply to Stefan Roese

From: Weijie Gao <[email protected]>

This patch adds etype u-boot-lzma-img for binman. README.entries is also updated.

---
Changes since v3: none

 tools/binman/README.entries               | 15 ++++++++++++
 tools/binman/etype/u_boot_lzma_img.py     | 28 +++++++++++++++++++++++
 tools/binman/ftest.py                     |  7 ++++++
 tools/binman/test/156_u_boot_lzma_img.dts | 11 +++++++++
 4 files changed, 61 insertions(+)
 create mode 100644 tools/binman/etype/u_boot_lzma_img.py
 create mode 100644 tools/binman/test/156_u_boot_lzma_img.dts
tools/binman/README.entries +15 -0
index 6a816bba6b..0aea9b8f6d 100644
@@ -747,6 +747,21 @@ applications.
 
 
 
+Entry: u-boot-lzma-img: U-Boot legacy image with contents compressed by LZMA
+----------------------------------------------------------------------------
+
+Properties / Entry arguments:
+    - filename: Filename of u-boot-lzma.img (default 'u-boot-lzma.img')
+
+This is the U-Boot binary as a packaged image, in legacy format. It has a
+header which allows it to be loaded at the correct address for execution.
+Its contents are compressed by LZMA.
+
+You should use FIT (Flat Image Tree) instead of the legacy image for new
+applications.
+
+
+
 Entry: u-boot-nodtb: U-Boot flat binary without device tree appended
 --------------------------------------------------------------------
 
tools/binman/etype/u_boot_lzma_img.py new file +28 -0
new file mode 100644
index 0000000000..966d6a46da
@@ -0,0 +1,28 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2020 MediaTek Inc. All Rights Reserved.
+# Author: Weijie Gao <[email protected]>
+#
+# Entry-type module for U-Boot legacy image with contents compressed by LZMA
+#
+
+from entry import Entry
+from blob import Entry_blob
+
+class Entry_u_boot_lzma_img(Entry_blob):
+    """U-Boot legacy image with contents compressed by LZMA
+
+    Properties / Entry arguments:
+        - filename: Filename of u-boot-lzma.img (default 'u-boot-lzma.img')
+
+    This is the U-Boot binary as a packaged image, in legacy format. It has a
+    header which allows it to be loaded at the correct address for execution.
+    Its contents are compressed by LZMA.
+
+    You should use FIT (Flat Image Tree) instead of the legacy image for new
+    applications.
+    """
+    def __init__(self, section, etype, node):
+        Entry_blob.__init__(self, section, etype, node)
+
+    def GetDefaultFilename(self):
+        return 'u-boot-lzma.img'
tools/binman/ftest.py +7 -0
index 872b855444..0ff7487b96 100644
@@ -39,6 +39,7 @@ import tout
 # Contents of test files, corresponding to different entry types
 U_BOOT_DATA           = b'1234'
 U_BOOT_IMG_DATA       = b'img'
+U_BOOT_LZMA_IMG_DATA  = b'lzma-img'
 U_BOOT_SPL_DATA       = b'56780123456789abcdefghi'
 U_BOOT_TPL_DATA       = b'tpl9876543210fedcbazyw'
 BLOB_DATA             = b'89'
@@ -115,6 +116,7 @@ class TestFunctional(unittest.TestCase):
         # Create some test files
         TestFunctional._MakeInputFile('u-boot.bin', U_BOOT_DATA)
         TestFunctional._MakeInputFile('u-boot.img', U_BOOT_IMG_DATA)
+        TestFunctional._MakeInputFile('u-boot-lzma.img', U_BOOT_LZMA_IMG_DATA)
         TestFunctional._MakeInputFile('spl/u-boot-spl.bin', U_BOOT_SPL_DATA)
         TestFunctional._MakeInputFile('tpl/u-boot-tpl.bin', U_BOOT_TPL_DATA)
         TestFunctional._MakeInputFile('blobfile', BLOB_DATA)
@@ -1078,6 +1080,11 @@ class TestFunctional(unittest.TestCase):
         data = self._DoReadFile('036_u_boot_img.dts')
         self.assertEqual(U_BOOT_IMG_DATA, data)
 
+    def testUBootLzmaImg(self):
+        """Test that u-boot-lzma.img can be put in a file"""
+        data = self._DoReadFile('156_u_boot_lzma_img.dts')
+        self.assertEqual(U_BOOT_LZMA_IMG_DATA, data)
+
     def testNoMicrocode(self):
         """Test that a missing microcode region is detected"""
         with self.assertRaises(ValueError) as e:
tools/binman/test/156_u_boot_lzma_img.dts new file +11 -0
new file mode 100644
index 0000000000..f49d014216
@@ -0,0 +1,11 @@
+/dts-v1/;
+
+/ {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	binman {
+		u-boot-lzma-img {
+		};
+	};
+};
Signature · 1 line
2.26.2
#17 lore raw

PATCH v7 17/26 spl: Extract legacy image handling into separate file

In reply to Stefan Roese

This patch moves the legacy image handling into a separate file, which will be extended with other legacy image features later.

No function change intended.

Cc Daniel Schwierzeck <[email protected]>
Cc Weijie Gao <[email protected]>
Cc Simon Goldschmidt <[email protected]>

---
Changes in v7:
- None

Changes in v6:
- New patch

 common/spl/Makefile     |  1 +
 common/spl/spl.c        | 56 +++++++++--------------------------------
 common/spl/spl_legacy.c | 54 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 67 insertions(+), 44 deletions(-)
 create mode 100644 common/spl/spl_legacy.c
common/spl/Makefile +1 -0
index eaa57f5ce5..c576a78126 100644
@@ -10,6 +10,7 @@ ifdef CONFIG_SPL_BUILD
 obj-$(CONFIG_$(SPL_TPL_)FRAMEWORK) += spl.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTROM_SUPPORT) += spl_bootrom.o
 obj-$(CONFIG_$(SPL_TPL_)LOAD_FIT) += spl_fit.o
+obj-$(CONFIG_$(SPL_TPL_)LEGACY_IMAGE_SUPPORT) += spl_legacy.o
 obj-$(CONFIG_$(SPL_TPL_)NOR_SUPPORT) += spl_nor.o
 obj-$(CONFIG_$(SPL_TPL_)XIP_SUPPORT) += spl_xip.o
 obj-$(CONFIG_$(SPL_TPL_)YMODEM_SUPPORT) += spl_ymodem.o
common/spl/spl.c +12 -44

69 lines not on this page · raw message

common/spl/spl_legacy.c new file +54 -0

54 lines not on this page · raw message

Signature · 1 line
2.26.2
#18 lore raw

PATCH v7 17/26 spl: Extract legacy image handling into separate file

Am 21.04.20 um 09:28 schrieb Stefan Roese:

Quoted 13 lines

This patch moves the legacy image handling into a separate file, which will be extended with other legacy image features later.

No function change intended.

Cc Daniel Schwierzeck <[email protected]>
Cc Weijie Gao <[email protected]>
Cc Simon Goldschmidt <[email protected]>

---
Changes in v7:
- None

Quoted 9 lines

Changes in v6:
- New patch

 common/spl/Makefile     |  1 +
 common/spl/spl.c        | 56 +++++++++--------------------------------
 common/spl/spl_legacy.c | 54 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 67 insertions(+), 44 deletions(-)
 create mode 100644 common/spl/spl_legacy.c
Signature · 1 line
- Daniel
#19 lore raw

PATCH v7 18/26 spl: spl_legacy: Use IS_ENABLED() to remove #ifdef

In reply to Stefan Roese

Use IS_ENABLED() instead of #ifdef CONFIG_ to remove one #ifdef.

No functional change intended.

Cc Daniel Schwierzeck <[email protected]>
Cc Weijie Gao <[email protected]>
Cc Simon Goldschmidt <[email protected]>

---
Changes in v7:
- None

Changes in v6:
- New patch

 common/spl/spl_legacy.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
common/spl/spl_legacy.c +2 -3
index 33f3587e3b..772135193e 100644
@@ -11,13 +11,12 @@ int spl_parse_legacy_header(struct spl_image_info *spl_image,
 {
 	u32 header_size = sizeof(struct image_header);
 
-#ifdef CONFIG_SPL_LEGACY_IMAGE_CRC_CHECK
 	/* check uImage header CRC */
-	if (!image_check_hcrc(header)) {
+	if (IS_ENABLED(CONFIG_SPL_LEGACY_IMAGE_CRC_CHECK) &&
+	    !image_check_hcrc(header)) {
 		puts("SPL: Image header CRC check failed!\n");
 		return -EINVAL;
 	}
-#endif
 
 	if (spl_image->flags & SPL_COPY_PAYLOAD_ONLY) {
 		/*
Signature · 1 line
2.26.2
#20 lore raw

PATCH v7 18/26 spl: spl_legacy: Use IS_ENABLED() to remove #ifdef

Am 21.04.20 um 09:28 schrieb Stefan Roese:

Quoted 12 lines

Use IS_ENABLED() instead of #ifdef CONFIG_ to remove one #ifdef.

No functional change intended.

Cc Daniel Schwierzeck <[email protected]>
Cc Weijie Gao <[email protected]>
Cc Simon Goldschmidt <[email protected]>

---
Changes in v7:
- None

Quoted 6 lines

Changes in v6:
- New patch

 common/spl/spl_legacy.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
Signature · 1 line
- Daniel
#21 lore raw

PATCH v7 19/26 spl: spl_nor: Move legacy image loading into spl_legacy.c

In reply to Stefan Roese

Move the legacy image loading into spl_legacy.c. This makes it easier to extend the legacy image handling with new features that other SPL loaders might use (e.g. spl_spi.c etc).

No functional change intended.

Cc Weijie Gao <[email protected]>
Cc Daniel Schwierzeck <[email protected]>
Cc Simon Goldschmidt <[email protected]>

---
Changes in v7:
- Don't include "ret" usage cleanup in this patch

Changes in v6:
- New patch

 common/spl/spl_legacy.c | 20 ++++++++++++++++++++
 common/spl/spl_nor.c    | 15 +++++++--------
 include/spl.h           | 13 +++++++++++++
 3 files changed, 40 insertions(+), 8 deletions(-)
common/spl/spl_legacy.c +20 -0
index 772135193e..7f00fc8885 100644
@@ -51,3 +51,23 @@ int spl_parse_legacy_header(struct spl_image_info *spl_image,
 
 	return 0;
 }
+
+int spl_load_legacy_img(struct spl_image_info *spl_image,
+			struct spl_load_info *load, ulong header)
+{
+	struct image_header hdr;
+	int ret;
+
+	/* Read header into local struct */
+	load->read(load, header, sizeof(hdr), &hdr);
+
+	ret = spl_parse_image_header(spl_image, &hdr);
+	if (ret)
+		return ret;
+
+	/* Read image */
+	load->read(load, header + sizeof(hdr), spl_image->size,
+		   (void *)(unsigned long)spl_image->load_addr);
+
+	return 0;
+}
common/spl/spl_nor.c +7 -8
index b1e79b9ded..217ae71c35 100644
@@ -107,14 +107,13 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,
 					      spl_nor_get_uboot_base());
 	}
 
-	ret = spl_parse_image_header(spl_image,
-			(const struct image_header *)spl_nor_get_uboot_base());
-	if (ret)
-		return ret;
-
-	memcpy((void *)(unsigned long)spl_image->load_addr,
-	       (void *)(spl_nor_get_uboot_base() + sizeof(struct image_header)),
-	       spl_image->size);
+	/* Legacy image handling */
+	if (IS_ENABLED(CONFIG_SPL_LEGACY_IMAGE_SUPPORT)) {
+		load.bl_len = 1;
+		load.read = spl_nor_load_read;
+		return spl_load_legacy_img(spl_image, &load,
+					   spl_nor_get_uboot_base());
+	}
 
 	return 0;
 }
include/spl.h +13 -0
index 5d8d14dbf5..a6bb9ba755 100644
@@ -223,6 +223,19 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
 #define SPL_COPY_PAYLOAD_ONLY	1
 #define SPL_FIT_FOUND		2
 
+/**
+ * spl_load_legacy_img() - Loads a legacy image from a device.
+ * @spl_image:	Image description to set up
+ * @load:	Structure containing the information required to load data.
+ * @header:	Pointer to image header (including appended image)
+ *
+ * Reads an legacy image from the device. Loads u-boot image to
+ * specified load address.
+ * Returns 0 on success.
+ */
+int spl_load_legacy_img(struct spl_image_info *spl_image,
+			struct spl_load_info *load, ulong header);
+
 /**
  * spl_load_imx_container() - Loads a imx container image from a device.
  * @spl_image:	Image description to set up
Signature · 1 line
2.26.2
#22 lore raw

PATCH v7 19/26 spl: spl_nor: Move legacy image loading into spl_legacy.c

Am 21.04.20 um 09:28 schrieb Stefan Roese:

Quoted 14 lines

Move the legacy image loading into spl_legacy.c. This makes it easier to extend the legacy image handling with new features that other SPL loaders might use (e.g. spl_spi.c etc).

No functional change intended.

Cc Weijie Gao <[email protected]>
Cc Daniel Schwierzeck <[email protected]>
Cc Simon Goldschmidt <[email protected]>

---
Changes in v7:
- Don't include "ret" usage cleanup in this patch

Quoted 8 lines

Changes in v6:
- New patch

 common/spl/spl_legacy.c | 20 ++++++++++++++++++++
 common/spl/spl_nor.c    | 15 +++++++--------
 include/spl.h           | 13 +++++++++++++
 3 files changed, 40 insertions(+), 8 deletions(-)
Signature · 1 line
- Daniel
#23 lore raw

PATCH v7 20/26 spl: spl_nor: Remove unused variable 'ret' warning

In reply to Stefan Roese

With the if statement now for the legacy image handling, the compiler now generates this compile time warning:

common/spl/spl_nor.c:27:6: warning: unused variable 'ret' [-Wunused-variable]

This patch removes this warning by changing the 'ret' variable handling.

Cc Daniel Schwierzeck <[email protected]>
Cc Weijie Gao <[email protected]>
Cc Simon Goldschmidt <[email protected]>

---
Changes in v7:
- New patch

 common/spl/spl_nor.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
common/spl/spl_nor.c +6 -6
index 217ae71c35..3f03ffe6a3 100644
@@ -24,7 +24,6 @@ unsigned long __weak spl_nor_get_uboot_base(void)
 static int spl_nor_load_image(struct spl_image_info *spl_image,
 			      struct spl_boot_device *bootdev)
 {
-	int ret;
 	__maybe_unused const struct image_header *header;
 	__maybe_unused struct spl_load_info load;
 
@@ -43,6 +42,8 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,
 		header = (const struct image_header *)CONFIG_SYS_OS_BASE;
 #ifdef CONFIG_SPL_LOAD_FIT
 		if (image_get_magic(header) == FDT_MAGIC) {
+			int ret;
+
 			debug("Found FIT\n");
 			load.bl_len = 1;
 			load.read = spl_nor_load_read;
@@ -61,6 +62,7 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,
 #endif
 		if (image_get_os(header) == IH_OS_LINUX) {
 			/* happy - was a Linux */
+			int ret;
 
 			ret = spl_parse_image_header(spl_image, header);
 			if (ret)
@@ -93,11 +95,9 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,
 		debug("Found FIT format U-Boot\n");
 		load.bl_len = 1;
 		load.read = spl_nor_load_read;
-		ret = spl_load_simple_fit(spl_image, &load,
-					  spl_nor_get_uboot_base(),
-					  (void *)header);
-
-		return ret;
+		return spl_load_simple_fit(spl_image, &load,
+					   spl_nor_get_uboot_base(),
+					   (void *)header);
 	}
 #endif
 	if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
Signature · 1 line
2.26.2
#24 lore raw

PATCH v7 20/26 spl: spl_nor: Remove unused variable 'ret' warning

Am 21.04.20 um 09:28 schrieb Stefan Roese:

Quoted 11 lines

With the if statement now for the legacy image handling, the compiler now generates this compile time warning:

common/spl/spl_nor.c:27:6: warning: unused variable 'ret' [-Wunused-variable]

This patch removes this warning by changing the 'ret' variable handling.

Cc Daniel Schwierzeck <[email protected]>
Cc Weijie Gao <[email protected]>
Cc Simon Goldschmidt <[email protected]>
Quoted 7 lines

---
Changes in v7:
- New patch

 common/spl/spl_nor.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
Signature · 1 line
- Daniel
#25 lore raw

PATCH v7 21/26 spl: spl_legacy: Add lzma decompression support for legacy image

In reply to Stefan Roese

From: Weijie Gao <[email protected]>

This patch adds support for decompressing LZMA compressed u-boot payload in legacy uImage format.

Using this patch together with u-boot-lzma.img may be useful for some platforms as they can reduce the size and load time of u-boot payload.

Cc Daniel Schwierzeck <[email protected]>
Cc Simon Goldschmidt <[email protected]>

---
Changes in v7:
- Add spl_image_get_comp() to enable the compiler to optimize the switch/case statement away due to Dead Code Elimination as suggested by Daniel

Changes in v6:
- New patch

 common/spl/spl_legacy.c | 62 +++++++++++++++++++++++++++++++++++++++--
 1 file changed, 60 insertions(+), 2 deletions(-)
common/spl/spl_legacy.c +60 -2
index 7f00fc8885..29d3ec7073 100644
@@ -4,8 +4,15 @@
  */
 
 #include <common.h>
+#include <malloc.h>
 #include <spl.h>
 
+#include <lzma/LzmaTypes.h>
+#include <lzma/LzmaDec.h>
+#include <lzma/LzmaTools.h>
+
+#define LZMA_LEN	(1 << 20)
+
 int spl_parse_legacy_header(struct spl_image_info *spl_image,
 			    const struct image_header *header)
 {
@@ -52,10 +59,27 @@ int spl_parse_legacy_header(struct spl_image_info *spl_image,
 	return 0;
 }
 
+/*
+ * This function is added explicitly to avoid code size increase, when
+ * no compression method is enabled. The compiler will optimize the
+ * following switch/case statement in spl_load_legacy_img() away due to
+ * Dead Code Elimination.
+ */
+static inline int spl_image_get_comp(const struct image_header *hdr)
+{
+	if (IS_ENABLED(CONFIG_SPL_LZMA))
+		return image_get_comp(hdr);
+
+	return IH_COMP_NONE;
+}
+
 int spl_load_legacy_img(struct spl_image_info *spl_image,
 			struct spl_load_info *load, ulong header)
 {
+	__maybe_unused SizeT lzma_len;
+	__maybe_unused void *src;
 	struct image_header hdr;
+	ulong dataptr;
 	int ret;
 
 	/* Read header into local struct */
@@ -65,9 +89,43 @@ int spl_load_legacy_img(struct spl_image_info *spl_image,
 	if (ret)
 		return ret;
 
+	dataptr = header + sizeof(hdr);
+
 	/* Read image */
-	load->read(load, header + sizeof(hdr), spl_image->size,
-		   (void *)(unsigned long)spl_image->load_addr);
+	switch (spl_image_get_comp(&hdr)) {
+	case IH_COMP_NONE:
+		load->read(load, dataptr, spl_image->size,
+			   (void *)(unsigned long)spl_image->load_addr);
+		break;
+
+	case IH_COMP_LZMA:
+		lzma_len = LZMA_LEN;
+
+		debug("LZMA: Decompressing %08lx to %08lx\n",
+		      dataptr, spl_image->load_addr);
+		src = malloc(spl_image->size);
+		if (!src) {
+			printf("Unable to allocate %d bytes for LZMA\n",
+			       spl_image->size);
+			return -ENOMEM;
+		}
+
+		load->read(load, dataptr, spl_image->size, src);
+		ret = lzmaBuffToBuffDecompress((void *)spl_image->load_addr,
+					       &lzma_len, src, spl_image->size);
+		if (ret) {
+			printf("LZMA decompression error: %d\n", ret);
+			return ret;
+		}
+
+		spl_image->size = lzma_len;
+		break;
+
+	default:
+		debug("Compression method %s is not supported\n",
+		      genimg_get_comp_short_name(image_get_comp(&hdr)));
+		return -EINVAL;
+	}
 
 	return 0;
 }
Signature · 1 line
2.26.2
#26 lore raw

PATCH v7 22/26 mips: spl: Flush cache before jumping to U-Boot proper

In reply to Stefan Roese

This patch adds a MIPS specific jump_to_image_no_args() implementation, which flushes the U-Boot proper image loaded from the boot device in SPL before jumping to it.

It has been noticed on MT76x8, that this cache flush is needed. Other MIPS platforms might need it as well.

Cc Weijie Gao <[email protected]>
Cc Daniel Schwierzeck <[email protected]>
Cc Simon Goldschmidt <[email protected]>

---
Changes in v7:
- Moved to MIPS specific file as suggested by Daniel

Changes in v6:
- New patch

arch/mips/lib/Makefile | 1 +

 arch/mips/lib/spl.c    | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+)
 create mode 100644 arch/mips/lib/spl.c
arch/mips/lib/Makefile +1 -0
index 24a72d9c97..9ee1fcb5c7 100644
@@ -12,5 +12,6 @@ obj-y	+= traps.o
 
 obj-$(CONFIG_CMD_BOOTM) += bootm.o
 obj-$(CONFIG_CMD_GO) += boot.o
+obj-$(CONFIG_SPL_BUILD) += spl.o
 
 lib-$(CONFIG_USE_PRIVATE_LIBGCC) += ashldi3.o ashrdi3.o lshrdi3.o
arch/mips/lib/spl.c new file +21 -0
new file mode 100644
index 0000000000..7ba3e53f6d
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2020 Stefan Roese <[email protected]>
+ */
+
+#include <common.h>
+#include <cpu_func.h>
+#include <spl.h>
+
+void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
+{
+	typedef void __noreturn (*image_entry_noargs_t)(void);
+	image_entry_noargs_t image_entry =
+		(image_entry_noargs_t)spl_image->entry_point;
+
+	/* Flush cache before jumping to application */
+	flush_cache((unsigned long)spl_image->load_addr, spl_image->size);
+
+	debug("image entry point: 0x%lx\n", spl_image->entry_point);
+	image_entry();
+}
Signature · 1 line
2.26.2
#27 lore raw

PATCH v7 22/26 mips: spl: Flush cache before jumping to U-Boot proper

Am 21.04.20 um 09:28 schrieb Stefan Roese:

Quoted 15 lines

This patch adds a MIPS specific jump_to_image_no_args() implementation, which flushes the U-Boot proper image loaded from the boot device in SPL before jumping to it.

It has been noticed on MT76x8, that this cache flush is needed. Other MIPS platforms might need it as well.

Cc Weijie Gao <[email protected]>
Cc Daniel Schwierzeck <[email protected]>
Cc Simon Goldschmidt <[email protected]>

---
Changes in v7:
- Moved to MIPS specific file as suggested by Daniel

Quoted 8 lines

Changes in v6:
- New patch

arch/mips/lib/Makefile | 1 +

 arch/mips/lib/spl.c    | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+)
 create mode 100644 arch/mips/lib/spl.c
Signature · 1 line
- Daniel
#28 lore raw

PATCH v7 23/26 mips: mtmips: add SPL support

In reply to Stefan Roese

From: Weijie Gao <[email protected]>

This patch adds SPL support for mtmips platform. The lowlevel architecture is split into SPL and the rest parts are built into a memory loadable u-boot image. Optional SPL_DM and OF_CONTROL are also supported.

The increment of size is very small (< 10 KiB) if SPL_DM and OF_CONTROL are not enabled and the memory bootable u-boot (u-boot.img) is generated automatically so there is not need to add a separate config for it.

A lzma compressed payload (u-boot-lzma.img) is also generated and it will be combined with u-boot-spl.bin to form the unified ROM bootable binary u-boot-mtmips.bin.

A spl loader is added to support uncompress the payload.

---
Changes since v3: generate output file using u-boot-with-spl.bin

 Makefile                                    |  6 +++
 arch/mips/Kconfig                           |  3 ++
 arch/mips/dts/mt7628-u-boot.dtsi            | 56 +++++++++++++++++++++
 arch/mips/dts/mt7628a.dtsi                  |  2 +-
 arch/mips/mach-mtmips/Kconfig               | 26 ++++++++++
 arch/mips/mach-mtmips/Makefile              |  1 +
 arch/mips/mach-mtmips/include/mach/serial.h | 13 +++++
 arch/mips/mach-mtmips/mt7628/Makefile       |  1 +
 arch/mips/mach-mtmips/mt7628/serial.c       | 34 +++++++++++++
 arch/mips/mach-mtmips/spl.c                 | 44 ++++++++++++++++
 10 files changed, 185 insertions(+), 1 deletion(-)
 create mode 100644 arch/mips/dts/mt7628-u-boot.dtsi
 create mode 100644 arch/mips/mach-mtmips/include/mach/serial.h
 create mode 100644 arch/mips/mach-mtmips/mt7628/serial.c
 create mode 100644 arch/mips/mach-mtmips/spl.c
Makefile +6 -0
index ffc1e28bd0..1e619bfc8b 100644
@@ -938,6 +938,12 @@ endif
 
 ALL-$(CONFIG_ARCH_MEDIATEK) += u-boot-mtk.bin
 
+ifeq ($(CONFIG_SPL),y)
+ALL-$(CONFIG_ARCH_MTMIPS) += u-boot-with-spl.bin
+else
+ALL-$(CONFIG_ARCH_MTMIPS) += u-boot.bin
+endif
+
 # Add optional build target if defined in board/cpu/soc headers
 ifneq ($(CONFIG_BUILD_TARGET),)
 ALL-y += $(CONFIG_BUILD_TARGET:"%"=%)
arch/mips/Kconfig +3 -0
index 7b9d0072eb..4c1eea1ccc 100644
@@ -98,6 +98,9 @@ config ARCH_MTMIPS
 	select SUPPORTS_CPU_MIPS32_R2
 	select SUPPORTS_LITTLE_ENDIAN
 	select SYSRESET
+	select SUPPORT_SPL
+	select SPL_LZMA
+	select BINMAN
 
 config ARCH_JZ47XX
 	bool "Support Ingenic JZ47xx"
arch/mips/dts/mt7628-u-boot.dtsi new file +56 -0

56 lines not on this page · raw message

arch/mips/dts/mt7628a.dtsi +1 -1
index 2200135a77..6baa63add3 100644
@@ -33,7 +33,7 @@
 		#clock-cells = <0>;
 	};
 
-	palmbus at 10000000 {
+	palmbus: palmbus at 10000000 {
 		compatible = "palmbus", "simple-bus";
 		reg = <0x10000000 0x200000>;
 		ranges = <0x0 0x10000000 0x1FFFFF>;
arch/mips/mach-mtmips/Kconfig +26 -0
index 3f25de8b85..81cec53e72 100644
@@ -20,8 +20,18 @@ config SYS_ICACHE_LINE_SIZE
 	default 32
 
 config SYS_TEXT_BASE
+	default 0x9c000000 if !SPL
+	default 0x80200000 if SPL
+
+config SPL_TEXT_BASE
 	default 0x9c000000
 
+config SPL_LOADER_SUPPORT
+	default y
+
+config SPL_PAYLOAD
+	default "u-boot-lzma.img"
+
 choice
 	prompt "MediaTek MIPS SoC select"
 
@@ -34,6 +44,14 @@ config SOC_MT7628
 	select PINCTRL_MT7628
 	select MTK_SERIAL
 	select SYSRESET_RESETCTL
+	select SPL_SEPARATE_BSS if SPL
+	select SPL_INIT_STACK_WITHOUT_MALLOC_F if SPL
+	select SPL_OF_CONTROL if SPL_DM
+	select SPL_SIMPLE_BUS if SPL_DM
+	select SPL_DM_SERIAL if SPL_DM
+	select SPL_CLK if SPL_DM && SPL_SERIAL_SUPPORT
+	select SPL_SYSRESET if SPL_DM
+	select SPL_OF_LIBFDT if SPL_OF_CONTROL
 	help
 	  This supports MediaTek MT7628/MT7688.
 
@@ -88,6 +106,14 @@ endchoice
 config SUPPORTS_BOOT_RAM
 	bool
 
+config SPL_UART2_SPIS_PINMUX
+	bool "Use alternative pinmux for UART2 in SPL stage"
+	depends on SPL_SERIAL_SUPPORT
+	default n
+	help
+	  Select this if the UART2 of your board is connected to GPIO 16/17
+	  (shared with SPIS) rather than the usual GPIO 20/21.
+
 source "board/gardena/smart-gateway-mt7688/Kconfig"
 source "board/seeed/linkit-smart-7688/Kconfig"
 
arch/mips/mach-mtmips/Makefile +1 -0
index 72f0369030..a7e6a66304 100644
@@ -3,5 +3,6 @@
 obj-y += cpu.o
 obj-y += ddr_init.o
 obj-y += ddr_cal.o
+obj-$(CONFIG_SPL_BUILD) += spl.o
 
 obj-$(CONFIG_SOC_MT7628) += mt7628/
arch/mips/mach-mtmips/include/mach/serial.h new file +13 -0
new file mode 100644
index 0000000000..bfa246b428
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 MediaTek Inc.
+ *
+ * Author:  Weijie Gao <[email protected]>
+ */
+
+#ifndef _MTMIPS_SERIAL_H_
+#define _MTMIPS_SERIAL_H_
+
+void mtmips_spl_serial_init(void);
+
+#endif /* _MTMIPS_SERIAL_H_ */
arch/mips/mach-mtmips/mt7628/Makefile +1 -0
index db62e90d77..7e139d5adf 100644
@@ -3,3 +3,4 @@
 obj-y += lowlevel_init.o
 obj-y += init.o
 obj-y += ddr.o
+obj-$(CONFIG_SPL_BUILD) += serial.o
arch/mips/mach-mtmips/mt7628/serial.c new file +34 -0
new file mode 100644
index 0000000000..a7d324792d
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 MediaTek Inc.
+ *
+ * Author:  Weijie Gao <[email protected]>
+ */
+
+#include <common.h>
+#include <asm/io.h>
+#include "mt7628.h"
+
+void mtmips_spl_serial_init(void)
+{
+#ifdef CONFIG_SPL_SERIAL_SUPPORT
+	void __iomem *base = ioremap_nocache(SYSCTL_BASE, SYSCTL_SIZE);
+
+#if CONFIG_CONS_INDEX == 1
+	clrbits_32(base + SYSCTL_GPIO_MODE1_REG, UART0_MODE_M);
+#elif CONFIG_CONS_INDEX == 2
+	clrbits_32(base + SYSCTL_GPIO_MODE1_REG, UART1_MODE_M);
+#elif CONFIG_CONS_INDEX == 3
+	setbits_32(base + SYSCTL_AGPIO_CFG_REG, EPHY_GPIO_AIO_EN_M);
+#ifdef CONFIG_SPL_UART2_SPIS_PINMUX
+	setbits_32(base + SYSCTL_GPIO_MODE1_REG, SPIS_MODE_M);
+	clrsetbits_32(base + SYSCTL_GPIO_MODE1_REG, UART2_MODE_M,
+		      1 << UART2_MODE_S);
+#else
+	clrbits_32(base + SYSCTL_GPIO_MODE1_REG, UART2_MODE_M);
+	clrsetbits_32(base + SYSCTL_GPIO_MODE1_REG, SPIS_MODE_M,
+		      1 << SPIS_MODE_S);
+#endif /* CONFIG_SPL_UART2_SPIS_PINMUX */
+#endif /* CONFIG_CONS_INDEX */
+#endif /* CONFIG_SPL_SERIAL_SUPPORT */
+}
arch/mips/mach-mtmips/spl.c new file +44 -0

44 lines not on this page · raw message

Signature · 1 line
2.26.2
#29 lore raw

PATCH v7 23/26 mips: mtmips: add SPL support

Am 21.04.20 um 09:28 schrieb Stefan Roese:

Quoted 149 lines

From: Weijie Gao <[email protected]>

This patch adds SPL support for mtmips platform. The lowlevel architecture is split into SPL and the rest parts are built into a memory loadable u-boot image. Optional SPL_DM and OF_CONTROL are also supported.

The increment of size is very small (< 10 KiB) if SPL_DM and OF_CONTROL are not enabled and the memory bootable u-boot (u-boot.img) is generated automatically so there is not need to add a separate config for it.

A lzma compressed payload (u-boot-lzma.img) is also generated and it will be combined with u-boot-spl.bin to form the unified ROM bootable binary u-boot-mtmips.bin.

A spl loader is added to support uncompress the payload.

---
Changes since v3: generate output file using u-boot-with-spl.bin

 Makefile                                    |  6 +++
 arch/mips/Kconfig                           |  3 ++
 arch/mips/dts/mt7628-u-boot.dtsi            | 56 +++++++++++++++++++++
 arch/mips/dts/mt7628a.dtsi                  |  2 +-
 arch/mips/mach-mtmips/Kconfig               | 26 ++++++++++
 arch/mips/mach-mtmips/Makefile              |  1 +
 arch/mips/mach-mtmips/include/mach/serial.h | 13 +++++
 arch/mips/mach-mtmips/mt7628/Makefile       |  1 +
 arch/mips/mach-mtmips/mt7628/serial.c       | 34 +++++++++++++
 arch/mips/mach-mtmips/spl.c                 | 44 ++++++++++++++++
 10 files changed, 185 insertions(+), 1 deletion(-)
 create mode 100644 arch/mips/dts/mt7628-u-boot.dtsi
 create mode 100644 arch/mips/mach-mtmips/include/mach/serial.h
 create mode 100644 arch/mips/mach-mtmips/mt7628/serial.c
 create mode 100644 arch/mips/mach-mtmips/spl.c
Makefile +6 -0
index ffc1e28bd0..1e619bfc8b 100644
@@ -938,6 +938,12 @@ endif
 
 ALL-$(CONFIG_ARCH_MEDIATEK) += u-boot-mtk.bin
 
+ifeq ($(CONFIG_SPL),y)
+ALL-$(CONFIG_ARCH_MTMIPS) += u-boot-with-spl.bin
+else
+ALL-$(CONFIG_ARCH_MTMIPS) += u-boot.bin
+endif
+
 # Add optional build target if defined in board/cpu/soc headers
 ifneq ($(CONFIG_BUILD_TARGET),)
 ALL-y += $(CONFIG_BUILD_TARGET:"%"=%)
arch/mips/Kconfig +3 -0
index 7b9d0072eb..4c1eea1ccc 100644
@@ -98,6 +98,9 @@ config ARCH_MTMIPS
 	select SUPPORTS_CPU_MIPS32_R2
 	select SUPPORTS_LITTLE_ENDIAN
 	select SYSRESET
+	select SUPPORT_SPL
+	select SPL_LZMA
+	select BINMAN
 
 config ARCH_JZ47XX
 	bool "Support Ingenic JZ47xx"
arch/mips/dts/mt7628-u-boot.dtsi new file +56 -0
new file mode 100644
index 0000000000..9149187762
@@ -0,0 +1,56 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 MediaTek Inc.
+ *
+ * Author: Weijie Gao <[email protected]>
+ */
+
+/ {
+	binman {
+		filename = "u-boot-mips.bin";
+		pad-byte = <0xff>;
+
+#ifdef CONFIG_SPL
+		u-boot-spl {
+		};
+
+		u-boot-lzma-img {
+		};
+#else
+		u-boot {
+		};
+#endif
+	};
+};
+
+&palmbus {
+	u-boot,dm-pre-reloc;
+};
+
+&reboot {
+	u-boot,dm-pre-reloc;
+};
+
+&clkctrl {
+	u-boot,dm-pre-reloc;
+};
+
+&rstctrl {
+	u-boot,dm-pre-reloc;
+};
+
+&pinctrl {
+	u-boot,dm-pre-reloc;
+};
+
+&uart0 {
+	u-boot,dm-pre-reloc;
+};
+
+&uart1 {
+	u-boot,dm-pre-reloc;
+};
+
+&uart2 {
+	u-boot,dm-pre-reloc;
+};
arch/mips/dts/mt7628a.dtsi +1 -1
index 2200135a77..6baa63add3 100644
@@ -33,7 +33,7 @@
 		#clock-cells = <0>;
 	};
 
-	palmbus at 10000000 {
+	palmbus: palmbus at 10000000 {
 		compatible = "palmbus", "simple-bus";
 		reg = <0x10000000 0x200000>;
 		ranges = <0x0 0x10000000 0x1FFFFF>;
arch/mips/mach-mtmips/Kconfig +0 -0
index 3f25de8b85..81cec53e72 100644
@@ -20,8 +20,18 @@ config SYS_ICACHE_LINE_SIZE
 	default 32

arch/mips/mach-mtmips/Kconfig config SYS_ICACHE_LINE_SIZE · line 30

Quoted 10 lines
arch/mips/mach-mtmips/Kconfig +6 -0
 
 config SYS_TEXT_BASE
+	default 0x9c000000 if !SPL
+	default 0x80200000 if SPL
+
+config SPL_TEXT_BASE
 	default 0x9c000000
 
+config SPL_LOADER_SUPPORT
+	default y

on my request this was introduced as generic MIPS symbol with patch 13/26. So maybe it's a left-over and should be removed. Either "config ARCH_MTMIPS" or "config SOC_MT7628" should select this symbol.

Quoted 167 lines
arch/mips/mach-mtmips/Kconfig +20 -0
+
+config SPL_PAYLOAD
+	default "u-boot-lzma.img"
+
 choice
 	prompt "MediaTek MIPS SoC select"
 
@@ -34,6 +44,14 @@ config SOC_MT7628
 	select PINCTRL_MT7628
 	select MTK_SERIAL
 	select SYSRESET_RESETCTL
+	select SPL_SEPARATE_BSS if SPL
+	select SPL_INIT_STACK_WITHOUT_MALLOC_F if SPL
+	select SPL_OF_CONTROL if SPL_DM
+	select SPL_SIMPLE_BUS if SPL_DM
+	select SPL_DM_SERIAL if SPL_DM
+	select SPL_CLK if SPL_DM && SPL_SERIAL_SUPPORT
+	select SPL_SYSRESET if SPL_DM
+	select SPL_OF_LIBFDT if SPL_OF_CONTROL
 	help
 	  This supports MediaTek MT7628/MT7688.
 
@@ -88,6 +106,14 @@ endchoice
 config SUPPORTS_BOOT_RAM
 	bool
 
+config SPL_UART2_SPIS_PINMUX
+	bool "Use alternative pinmux for UART2 in SPL stage"
+	depends on SPL_SERIAL_SUPPORT
+	default n
+	help
+	  Select this if the UART2 of your board is connected to GPIO 16/17
+	  (shared with SPIS) rather than the usual GPIO 20/21.
+
 source "board/gardena/smart-gateway-mt7688/Kconfig"
 source "board/seeed/linkit-smart-7688/Kconfig"
 
arch/mips/mach-mtmips/Makefile +1 -0
index 72f0369030..a7e6a66304 100644
@@ -3,5 +3,6 @@
 obj-y += cpu.o
 obj-y += ddr_init.o
 obj-y += ddr_cal.o
+obj-$(CONFIG_SPL_BUILD) += spl.o
 
 obj-$(CONFIG_SOC_MT7628) += mt7628/
arch/mips/mach-mtmips/include/mach/serial.h new file +13 -0
new file mode 100644
index 0000000000..bfa246b428
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 MediaTek Inc.
+ *
+ * Author:  Weijie Gao <[email protected]>
+ */
+
+#ifndef _MTMIPS_SERIAL_H_
+#define _MTMIPS_SERIAL_H_
+
+void mtmips_spl_serial_init(void);
+
+#endif /* _MTMIPS_SERIAL_H_ */
arch/mips/mach-mtmips/mt7628/Makefile +1 -0
index db62e90d77..7e139d5adf 100644
@@ -3,3 +3,4 @@
 obj-y += lowlevel_init.o
 obj-y += init.o
 obj-y += ddr.o
+obj-$(CONFIG_SPL_BUILD) += serial.o
arch/mips/mach-mtmips/mt7628/serial.c new file +34 -0
new file mode 100644
index 0000000000..a7d324792d
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 MediaTek Inc.
+ *
+ * Author:  Weijie Gao <[email protected]>
+ */
+
+#include <common.h>
+#include <asm/io.h>
+#include "mt7628.h"
+
+void mtmips_spl_serial_init(void)
+{
+#ifdef CONFIG_SPL_SERIAL_SUPPORT
+	void __iomem *base = ioremap_nocache(SYSCTL_BASE, SYSCTL_SIZE);
+
+#if CONFIG_CONS_INDEX == 1
+	clrbits_32(base + SYSCTL_GPIO_MODE1_REG, UART0_MODE_M);
+#elif CONFIG_CONS_INDEX == 2
+	clrbits_32(base + SYSCTL_GPIO_MODE1_REG, UART1_MODE_M);
+#elif CONFIG_CONS_INDEX == 3
+	setbits_32(base + SYSCTL_AGPIO_CFG_REG, EPHY_GPIO_AIO_EN_M);
+#ifdef CONFIG_SPL_UART2_SPIS_PINMUX
+	setbits_32(base + SYSCTL_GPIO_MODE1_REG, SPIS_MODE_M);
+	clrsetbits_32(base + SYSCTL_GPIO_MODE1_REG, UART2_MODE_M,
+		      1 << UART2_MODE_S);
+#else
+	clrbits_32(base + SYSCTL_GPIO_MODE1_REG, UART2_MODE_M);
+	clrsetbits_32(base + SYSCTL_GPIO_MODE1_REG, SPIS_MODE_M,
+		      1 << SPIS_MODE_S);
+#endif /* CONFIG_SPL_UART2_SPIS_PINMUX */
+#endif /* CONFIG_CONS_INDEX */
+#endif /* CONFIG_SPL_SERIAL_SUPPORT */
+}
arch/mips/mach-mtmips/spl.c new file +44 -0
new file mode 100644
index 0000000000..2a24af70c3
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 MediaTek Inc. All Rights Reserved.
+ *
+ * Author: Weijie Gao <[email protected]>
+ */
+
+#include <common.h>
+#include <fdt.h>
+#include <spl.h>
+#include <asm/sections.h>
+#include <linux/sizes.h>
+#include <mach/serial.h>
+
+void __noreturn board_init_f(ulong dummy)
+{
+	spl_init();
+
+#ifdef CONFIG_SPL_SERIAL_SUPPORT
+	/*
+	 * mtmips_spl_serial_init() is useful if debug uart is enabled,
+	 * or DM based serial is not enabled.
+	 */
+	mtmips_spl_serial_init();
+	preloader_console_init();
+#endif
+
+	board_init_r(NULL, 0);
+}
+
+void board_boot_order(u32 *spl_boot_list)
+{
+	spl_boot_list[0] = BOOT_DEVICE_NOR;
+}
+
+unsigned long spl_nor_get_uboot_base(void)
+{
+	void *uboot_base = __image_copy_end;
+
+	if (fdt_magic(uboot_base) == FDT_MAGIC)
+		return (unsigned long)uboot_base + fdt_totalsize(uboot_base);
+
+	return (unsigned long)uboot_base;
+}
Signature · 1 line
- Daniel
#30 lore raw

PATCH v7 23/26 mips: mtmips: add SPL support

Hi Daniel,

Quoted 160 lines · Daniel Schwierzeck

Am 21.04.20 um 09:28 schrieb Stefan Roese:

Quoted 157 lines

From: Weijie Gao <[email protected]>

This patch adds SPL support for mtmips platform. The lowlevel architecture is split into SPL and the rest parts are built into a memory loadable u-boot image. Optional SPL_DM and OF_CONTROL are also supported.

The increment of size is very small (< 10 KiB) if SPL_DM and OF_CONTROL are not enabled and the memory bootable u-boot (u-boot.img) is generated automatically so there is not need to add a separate config for it.

A lzma compressed payload (u-boot-lzma.img) is also generated and it will be combined with u-boot-spl.bin to form the unified ROM bootable binary u-boot-mtmips.bin.

A spl loader is added to support uncompress the payload.

---
Changes since v3: generate output file using u-boot-with-spl.bin

  Makefile                                    |  6 +++
  arch/mips/Kconfig                           |  3 ++
  arch/mips/dts/mt7628-u-boot.dtsi            | 56 +++++++++++++++++++++
  arch/mips/dts/mt7628a.dtsi                  |  2 +-
  arch/mips/mach-mtmips/Kconfig               | 26 ++++++++++
  arch/mips/mach-mtmips/Makefile              |  1 +
  arch/mips/mach-mtmips/include/mach/serial.h | 13 +++++
  arch/mips/mach-mtmips/mt7628/Makefile       |  1 +
  arch/mips/mach-mtmips/mt7628/serial.c       | 34 +++++++++++++
  arch/mips/mach-mtmips/spl.c                 | 44 ++++++++++++++++
  10 files changed, 185 insertions(+), 1 deletion(-)

create mode 100644 arch/mips/dts/mt7628-u-boot.dtsi create mode 100644 arch/mips/mach-mtmips/include/mach/serial.h create mode 100644 arch/mips/mach-mtmips/mt7628/serial.c create mode 100644 arch/mips/mach-mtmips/spl.c

Makefile +6 -0
index ffc1e28bd0..1e619bfc8b 100644
@@ -938,6 +938,12 @@ endif
 
  ALL-$(CONFIG_ARCH_MEDIATEK) += u-boot-mtk.bin
 
+ifeq ($(CONFIG_SPL),y)
+ALL-$(CONFIG_ARCH_MTMIPS) += u-boot-with-spl.bin
+else
+ALL-$(CONFIG_ARCH_MTMIPS) += u-boot.bin
+endif
+
  # Add optional build target if defined in board/cpu/soc headers
  ifneq ($(CONFIG_BUILD_TARGET),)
  ALL-y += $(CONFIG_BUILD_TARGET:"%"=%)
arch/mips/Kconfig +3 -0
index 7b9d0072eb..4c1eea1ccc 100644
@@ -98,6 +98,9 @@ config ARCH_MTMIPS
  	select SUPPORTS_CPU_MIPS32_R2
  	select SUPPORTS_LITTLE_ENDIAN
  	select SYSRESET
+	select SUPPORT_SPL
+	select SPL_LZMA
+	select BINMAN
 
  config ARCH_JZ47XX
  	bool "Support Ingenic JZ47xx"
arch/mips/dts/mt7628-u-boot.dtsi new file +56 -0
new file mode 100644
index 0000000000..9149187762
@@ -0,0 +1,56 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 MediaTek Inc.
+ *
+ * Author: Weijie Gao <[email protected]>
+ */
+
+/ {
+	binman {
+		filename = "u-boot-mips.bin";
+		pad-byte = <0xff>;
+
+#ifdef CONFIG_SPL
+		u-boot-spl {
+		};
+
+		u-boot-lzma-img {
+		};
+#else
+		u-boot {
+		};
+#endif
+	};
+};
+
+&palmbus {
+	u-boot,dm-pre-reloc;
+};
+
+&reboot {
+	u-boot,dm-pre-reloc;
+};
+
+&clkctrl {
+	u-boot,dm-pre-reloc;
+};
+
+&rstctrl {
+	u-boot,dm-pre-reloc;
+};
+
+&pinctrl {
+	u-boot,dm-pre-reloc;
+};
+
+&uart0 {
+	u-boot,dm-pre-reloc;
+};
+
+&uart1 {
+	u-boot,dm-pre-reloc;
+};
+
+&uart2 {
+	u-boot,dm-pre-reloc;
+};
arch/mips/dts/mt7628a.dtsi +1 -1
index 2200135a77..6baa63add3 100644
@@ -33,7 +33,7 @@
  		#clock-cells = <0>;
  	};
 
-	palmbus at 10000000 {
+	palmbus: palmbus at 10000000 {
  		compatible = "palmbus", "simple-bus";
  		reg = <0x10000000 0x200000>;
  		ranges = <0x0 0x10000000 0x1FFFFF>;
arch/mips/mach-mtmips/Kconfig +4 -0
index 3f25de8b85..81cec53e72 100644
@@ -20,8 +20,18 @@ config SYS_ICACHE_LINE_SIZE
  	default 32
 
  config SYS_TEXT_BASE
+	default 0x9c000000 if !SPL
+	default 0x80200000 if SPL
+
+config SPL_TEXT_BASE
  	default 0x9c000000
 
Quoted 6 lines

arch/mips/mach-mtmips/Kconfig config SYS_ICACHE_LINE_SIZE · line 30

Quoted 2 lines
arch/mips/mach-mtmips/Kconfig +2 -0
+config SPL_LOADER_SUPPORT
+	default y

on my request this was introduced as generic MIPS symbol with patch 13/26. So maybe it's a left-over and should be removed. Either "config ARCH_MTMIPS" or "config SOC_MT7628" should select this symbol.

Thanks for spotting. Would it be okay to fix this up with an incremental patch once this series is in mainline, to not "pollute" the list more? If no other changes are required of course.

Thanks,
Stefan

#31 lore raw

PATCH v7 23/26 mips: mtmips: add SPL support

Am 21.04.20 um 13:34 schrieb Stefan Roese:

Quoted 169 lines

Hi Daniel,

Quoted 157 lines · Daniel Schwierzeck

Am 21.04.20 um 09:28 schrieb Stefan Roese:

Quoted 154 lines

From: Weijie Gao <[email protected]>

This patch adds SPL support for mtmips platform. The lowlevel architecture
is split into SPL and the rest parts are built into a memory loadable u-boot image. Optional SPL_DM and OF_CONTROL are also supported.

The increment of size is very small (< 10 KiB) if SPL_DM and OF_CONTROL are
not enabled and the memory bootable u-boot (u-boot.img) is generated automatically so there is not need to add a separate config for it.

A lzma compressed payload (u-boot-lzma.img) is also generated and it will
be combined with u-boot-spl.bin to form the unified ROM bootable binary u-boot-mtmips.bin.

A spl loader is added to support uncompress the payload.

---
Changes since v3: generate output file using u-boot-with-spl.bin

? Makefile??????????????????????????????????? |? 6 +++
? arch/mips/Kconfig?????????????????????????? |? 3 ++
? arch/mips/dts/mt7628-u-boot.dtsi??????????? | 56 +++++++++++++++++++++
? arch/mips/dts/mt7628a.dtsi????????????????? |? 2 +-
? arch/mips/mach-mtmips/Kconfig?????????????? | 26 ++++++++++
? arch/mips/mach-mtmips/Makefile????????????? |? 1 +
? arch/mips/mach-mtmips/include/mach/serial.h | 13 +++++
? arch/mips/mach-mtmips/mt7628/Makefile?????? |? 1 +
? arch/mips/mach-mtmips/mt7628/serial.c?????? | 34 +++++++++++++
? arch/mips/mach-mtmips/spl.c???????????????? | 44 ++++++++++++++++

? 10 files changed, 185 insertions(+), 1 deletion(-)
? create mode 100644 arch/mips/dts/mt7628-u-boot.dtsi ? create mode 100644 arch/mips/mach-mtmips/include/mach/serial.h ? create mode 100644 arch/mips/mach-mtmips/mt7628/serial.c ? create mode 100644 arch/mips/mach-mtmips/spl.c

Makefile +0 -0
index ffc1e28bd0..1e619bfc8b 100644
@@ -938,6 +938,12 @@ endif

? ? ALL-$(CONFIG_ARCH_MEDIATEK) += u-boot-mtk.bin
? +ifeq ($(CONFIG_SPL),y)

Makefile +5 -0
+ALL-$(CONFIG_ARCH_MTMIPS) += u-boot-with-spl.bin
+else
+ALL-$(CONFIG_ARCH_MTMIPS) += u-boot.bin
+endif
+

? # Add optional build target if defined in board/cpu/soc headers ? ifneq ($(CONFIG_BUILD_TARGET),)
? ALL-y += $(CONFIG_BUILD_TARGET:"%"=%)

arch/mips/Kconfig +0 -0
index 7b9d0072eb..4c1eea1ccc 100644
@@ -98,6 +98,9 @@ config ARCH_MTMIPS

????? select SUPPORTS_CPU_MIPS32_R2
????? select SUPPORTS_LITTLE_ENDIAN
????? select SYSRESET
+??? select SUPPORT_SPL
+??? select SPL_LZMA
+??? select BINMAN
? ? config ARCH_JZ47XX
????? bool "Support Ingenic JZ47xx"

arch/mips/dts/mt7628-u-boot.dtsi new file +56 -0
new file mode 100644
index 0000000000..9149187762
@@ -0,0 +1,56 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 MediaTek Inc.
+ *
+ * Author: Weijie Gao <[email protected]>
+ */
+
+/ {
+??? binman {
+??????? filename = "u-boot-mips.bin";
+??????? pad-byte = <0xff>;
+
+#ifdef CONFIG_SPL
+??????? u-boot-spl {
+??????? };
+
+??????? u-boot-lzma-img {
+??????? };
+#else
+??????? u-boot {
+??????? };
+#endif
+??? };
+};
+
+&palmbus {
+??? u-boot,dm-pre-reloc;
+};
+
+&reboot {
+??? u-boot,dm-pre-reloc;
+};
+
+&clkctrl {
+??? u-boot,dm-pre-reloc;
+};
+
+&rstctrl {
+??? u-boot,dm-pre-reloc;
+};
+
+&pinctrl {
+??? u-boot,dm-pre-reloc;
+};
+
+&uart0 {
+??? u-boot,dm-pre-reloc;
+};
+
+&uart1 {
+??? u-boot,dm-pre-reloc;
+};
+
+&uart2 {
+??? u-boot,dm-pre-reloc;
+};
arch/mips/dts/mt7628a.dtsi +1 -0
index 2200135a77..6baa63add3 100644
@@ -33,7 +33,7 @@
 ????????? #clock-cells = <0>;
 ????? };
 ? -??? palmbus at 10000000 {
+??? palmbus: palmbus at 10000000 {
 ????????? compatible = "palmbus", "simple-bus";
 ????????? reg = <0x10000000 0x200000>;
 ????????? ranges = <0x0 0x10000000 0x1FFFFF>;
arch/mips/mach-mtmips/Kconfig +0 -0
index 3f25de8b85..81cec53e72 100644
@@ -20,8 +20,18 @@ config SYS_ICACHE_LINE_SIZE

????? default 32
? ? config SYS_TEXT_BASE
+??? default 0x9c000000 if !SPL
+??? default 0x80200000 if SPL
+

Quoted 8 lines
Quoted 4 lines

+config SPL_TEXT_BASE
????? default 0x9c000000
? +config SPL_LOADER_SUPPORT
+??? default y

on my request this was introduced as generic MIPS symbol with patch 13/26. So maybe it's a left-over and should be removed. Either "config ARCH_MTMIPS" or "config SOC_MT7628" should select this symbol.

Quoted 6 lines

Thanks for spotting. Would it be okay to fix this up with an incremental patch once this series is in mainline, to not "pollute" the list more? If no other changes are required of course.

Thanks,
Stefan

I could fix it when applying, but I'm not sure about ARCH_MTMIPS or SOC_MT7628

Signature · 1 line
- Daniel
#32 lore raw

PATCH v7 23/26 mips: mtmips: add SPL support

On 21.04.20 13:57, Daniel Schwierzeck wrote:

<snip>

Quoted 20 lines
Quoted 20 lines
Quoted 7 lines
Quoted 7 lines

+++ b/arch/mips/mach-mtmips/Kconfig

(quoted diff) +3 -0
@@ -20,8 +20,18 @@ config SYS_ICACHE_LINE_SIZE
 ????? default 32
 ? ? config SYS_TEXT_BASE
+??? default 0x9c000000 if !SPL
+??? default 0x80200000 if SPL
+
Quoted 8 lines

Review config SYS_ICACHE_LINE_SIZE · line 28

Quoted 4 lines
(quoted diff) +2 -0
+config SPL_TEXT_BASE
 ????? default 0x9c000000
 ? +config SPL_LOADER_SUPPORT
+??? default y

on my request this was introduced as generic MIPS symbol with patch 13/26. So maybe it's a left-over and should be removed. Either "config ARCH_MTMIPS" or "config SOC_MT7628" should select this symbol.

Thanks for spotting. Would it be okay to fix this up with an incremental patch once this series is in mainline, to not "pollute" the list more? If no other changes are required of course.

Quoted 5 lines
Quoted 2 lines

Thanks,
Stefan

I could fix it when applying, but I'm not sure about ARCH_MTMIPS or SOC_MT7628

That would be most welcome. Please go with "SOC_MT7628".

Thanks,
Stefan

#33 lore raw

PATCH v7 24/26 mips: mtmips: enable SPL for all boards

In reply to Stefan Roese

From: Weijie Gao <[email protected]>

This patch enables SPL for all mtmips boards. And also remove defconfig files which are intend to build ram bootable u-boot files.

SPL_DM and OF_CONTROL are enabled for both boards.

---
Changes since v3: add CONFIG_SPL_PAD_TO=0 to make sure no padding added

 arch/mips/mach-mtmips/Kconfig                 | 26 -------
 board/gardena/smart-gateway-mt7688/board.c    |  2 +
 ...gardena-smart-gateway-mt7688-ram_defconfig | 74 -------------------
 .../gardena-smart-gateway-mt7688_defconfig    | 10 ++-
 configs/linkit-smart-7688-ram_defconfig       | 65 ----------------
 configs/linkit-smart-7688_defconfig           | 10 ++-
 .../configs/gardena-smart-gateway-mt7688.h    | 21 +++++-
 include/configs/linkit-smart-7688.h           | 22 +++++-
 8 files changed, 59 insertions(+), 171 deletions(-)
 delete mode 100644 configs/gardena-smart-gateway-mt7688-ram_defconfig
 delete mode 100644 configs/linkit-smart-7688-ram_defconfig
arch/mips/mach-mtmips/Kconfig +0 -26
index 81cec53e72..ad28ef3a8c 100644
@@ -64,7 +64,6 @@ config BOARD_GARDENA_SMART_GATEWAY_MT7688
 	bool "GARDENA smart Gateway"
 	depends on SOC_MT7628
 	select BOARD_LATE_INIT
-	select SUPPORTS_BOOT_RAM
 	help
 	  GARDENA smart Gateway boards have a MT7688 SoC with 128 MiB of RAM
 	  and 8 MiB of flash (SPI NOR) and additional SPI NAND storage.
@@ -72,7 +71,6 @@ config BOARD_GARDENA_SMART_GATEWAY_MT7688
 config BOARD_LINKIT_SMART_7688
 	bool "LinkIt Smart 7688"
 	depends on SOC_MT7628
-	select SUPPORTS_BOOT_RAM
 	help
 	  Seeed LinkIt Smart 7688 boards have a MT7688 SoC with 128 MiB of RAM
 	  and 32 MiB of flash (SPI).
@@ -82,30 +80,6 @@ config BOARD_LINKIT_SMART_7688
 
 endchoice
 
-choice
-	prompt "Boot mode"
-
-config BOOT_RAM
-	bool "RAM boot"
-	depends on SUPPORTS_BOOT_RAM
-	help
-	  This builds an image that is linked to a RAM address. It can be used
-	  for booting from CFE via TFTP using an ELF image, but it can also be
-	  booted from RAM by other bootloaders using a BIN image.
-
-config BOOT_ROM
-	bool "ROM boot"
-	depends on SUPPORTS_BOOT_RAM
-	help
-	  This builds an image that is linked to a ROM address. It can be
-	  used as main bootloader image which is programmed onto the onboard
-	  flash storage (SPI NOR).
-
-endchoice
-
-config SUPPORTS_BOOT_RAM
-	bool
-
 config SPL_UART2_SPIS_PINMUX
 	bool "Use alternative pinmux for UART2 in SPL stage"
 	depends on SPL_SERIAL_SUPPORT
board/gardena/smart-gateway-mt7688/board.c +2 -0
index 48cf3091e9..776afa43a6 100644
@@ -295,8 +295,10 @@ err_free:
 	return ret;
 }
 
+#ifndef CONFIG_SPL_BUILD
 U_BOOT_CMD(
 	fd_write,	1,	0,	do_fd_write,
 	"Write test factory-data values to SPI NOR",
 	"\n"
 );
+#endif
configs/gardena-smart-gateway-mt7688-ram_defconfig deleted +0 -74

74 lines not on this page · raw message

configs/gardena-smart-gateway-mt7688_defconfig +8 -2
index 0209af0fc9..e01fc937c1 100644
@@ -1,14 +1,17 @@
 CONFIG_MIPS=y
-CONFIG_SYS_TEXT_BASE=0x9c000000
+CONFIG_SPL_LIBCOMMON_SUPPORT=y
+CONFIG_SPL_LIBGENERIC_SUPPORT=y
 CONFIG_ENV_SIZE=0x10000
 CONFIG_ENV_SECT_SIZE=0x10000
 CONFIG_ENV_OFFSET=0xA0000
 CONFIG_SYS_BOOTCOUNT_ADDR=0xb000006c
+CONFIG_SPL_SERIAL_SUPPORT=y
+CONFIG_SPL_SYS_MALLOC_F_LEN=0x20000
 CONFIG_NR_DRAM_BANKS=1
+CONFIG_SPL=y
 CONFIG_SYS_BOOTCOUNT_SINGLEWORD=y
 CONFIG_ENV_OFFSET_REDUND=0xB0000
 CONFIG_ARCH_MTMIPS=y
-CONFIG_BOOT_ROM=y
 CONFIG_RESTORE_EXCEPTION_VECTOR_BASE=y
 # CONFIG_MIPS_BOOT_ENV_LEGACY is not set
 CONFIG_MIPS_BOOT_FDT=y
@@ -23,6 +26,8 @@ CONFIG_USE_PREBOOT=y
 CONFIG_SYS_CONSOLE_INFO_QUIET=y
 CONFIG_VERSION_VARIABLE=y
 CONFIG_BOARD_EARLY_INIT_F=y
+CONFIG_SPL_SYS_MALLOC_SIMPLE=y
+CONFIG_SPL_NOR_SUPPORT=y
 CONFIG_HUSH_PARSER=y
 CONFIG_CMD_LICENSE=y
 # CONFIG_CMD_ELF is not set
@@ -49,6 +54,7 @@ CONFIG_ENV_IS_IN_SPI_FLASH=y
 CONFIG_SYS_REDUNDAND_ENVIRONMENT=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_NET_RANDOM_ETHADDR=y
+CONFIG_SPL_DM=y
 # CONFIG_DM_DEVICE_REMOVE is not set
 CONFIG_HAVE_BLOCK_DEVICE=y
 CONFIG_BOOTCOUNT_LIMIT=y
configs/linkit-smart-7688-ram_defconfig deleted +0 -65

65 lines not on this page · raw message

configs/linkit-smart-7688_defconfig +8 -2
index 34066dd293..642755ec65 100644
@@ -1,12 +1,15 @@
 CONFIG_MIPS=y
-CONFIG_SYS_TEXT_BASE=0x9c000000
+CONFIG_SPL_LIBCOMMON_SUPPORT=y
+CONFIG_SPL_LIBGENERIC_SUPPORT=y
 CONFIG_ENV_SIZE=0x4000
 CONFIG_ENV_SECT_SIZE=0x10000
 CONFIG_ENV_OFFSET=0x80000
+CONFIG_SPL_SERIAL_SUPPORT=y
+CONFIG_SPL_SYS_MALLOC_F_LEN=0x20000
 CONFIG_NR_DRAM_BANKS=1
+CONFIG_SPL=y
 CONFIG_ARCH_MTMIPS=y
 CONFIG_BOARD_LINKIT_SMART_7688=y
-CONFIG_BOOT_ROM=y
 CONFIG_RESTORE_EXCEPTION_VECTOR_BASE=y
 # CONFIG_MIPS_BOOT_ENV_LEGACY is not set
 CONFIG_MIPS_BOOT_FDT=y
@@ -16,6 +19,8 @@ CONFIG_LEGACY_IMAGE_FORMAT=y
 CONFIG_OF_STDOUT_VIA_ALIAS=y
 CONFIG_SYS_CONSOLE_INFO_QUIET=y
 CONFIG_BOARD_EARLY_INIT_F=y
+CONFIG_SPL_SYS_MALLOC_SIMPLE=y
+CONFIG_SPL_NOR_SUPPORT=y
 CONFIG_HUSH_PARSER=y
 CONFIG_CMD_LICENSE=y
 # CONFIG_CMD_ELF is not set
@@ -39,6 +44,7 @@ CONFIG_DEFAULT_DEVICE_TREE="linkit-smart-7688"
 CONFIG_ENV_IS_IN_SPI_FLASH=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_NET_RANDOM_ETHADDR=y
+CONFIG_SPL_DM=y
 # CONFIG_DM_DEVICE_REMOVE is not set
 CONFIG_BLK=y
 CONFIG_LED=y
include/configs/gardena-smart-gateway-mt7688.h +20 -1
index 59c60743d2..6412efcbf8 100644
@@ -16,10 +16,29 @@
 
 #define CONFIG_SYS_INIT_SP_OFFSET	0x400000
 
-#ifdef CONFIG_BOOT_RAM
+/* SPL */
+#if defined(CONFIG_SPL) && !defined(CONFIG_SPL_BUILD)
 #define CONFIG_SKIP_LOWLEVEL_INIT
 #endif
 
+#define CONFIG_SYS_UBOOT_START		CONFIG_SYS_TEXT_BASE
+#define CONFIG_SPL_BSS_START_ADDR	0x80010000
+#define CONFIG_SPL_BSS_MAX_SIZE		0x10000
+#define CONFIG_SPL_MAX_SIZE		0x10000
+#define CONFIG_SPL_PAD_TO		0
+
+/* Dummy value */
+#define CONFIG_SYS_UBOOT_BASE		0
+
+/* Serial SPL */
+#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_SERIAL_SUPPORT)
+#define CONFIG_SYS_NS16550_MEM32
+#define CONFIG_SYS_NS16550_CLK		40000000
+#define CONFIG_SYS_NS16550_REG_SIZE	-4
+#define CONFIG_SYS_NS16550_COM1		0xb0000c00
+#define CONFIG_CONS_INDEX		1
+#endif
+
 /* UART */
 #define CONFIG_SYS_BAUDRATE_TABLE	{ 9600, 19200, 38400, 57600, 115200, \
 					  230400, 460800, 921600 }
include/configs/linkit-smart-7688.h +21 -1
index ca5b693e4c..4276e95dee 100644
@@ -16,10 +16,30 @@
 
 #define CONFIG_SYS_INIT_SP_OFFSET	0x400000
 
-#ifdef CONFIG_BOOT_RAM
+/* SPL */
+#if defined(CONFIG_SPL) && !defined(CONFIG_SPL_BUILD)
 #define CONFIG_SKIP_LOWLEVEL_INIT
 #endif
 
+#define CONFIG_SYS_UBOOT_START		CONFIG_SYS_TEXT_BASE
+#define CONFIG_SPL_BSS_START_ADDR	0x80010000
+#define CONFIG_SPL_BSS_MAX_SIZE		0x10000
+#define CONFIG_SPL_MAX_SIZE		0x10000
+#define CONFIG_SPL_PAD_TO		0
+
+/* Dummy value */
+#define CONFIG_SYS_UBOOT_BASE		0
+
+/* Serial SPL */
+#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_SERIAL_SUPPORT)
+#define CONFIG_SYS_NS16550_MEM32
+#define CONFIG_SYS_NS16550_CLK		40000000
+#define CONFIG_SYS_NS16550_REG_SIZE	-4
+#define CONFIG_SYS_NS16550_COM3		0xb0000e00
+#define CONFIG_CONS_INDEX		3
+
+#endif
+
 /* UART */
 #define CONFIG_SYS_BAUDRATE_TABLE	{ 9600, 19200, 38400, 57600, 115200, \
 					  230400, 460800, 921600 }
Signature · 1 line
2.26.2
#34 lore raw

PATCH v7 25/26 mips: mtmips: add support for mt7628-rfb

In reply to Stefan Roese

From: Weijie Gao <[email protected]>

This patch adds support for mt7628 reference board. SPL_DM and DT are not enabled for SPL to save about 17KiB for u-boot-spl.bin.

---
Changes since v3: add CONFIG_SPL_PAD_TO=0 to make sure no padding added

 arch/mips/dts/Makefile                |  1 +
 arch/mips/dts/mediatek,mt7628-rfb.dts | 67 +++++++++++++++++++++++++++
 arch/mips/mach-mtmips/Kconfig         |  9 ++++
 board/mediatek/mt7628/Kconfig         | 12 +++++
 board/mediatek/mt7628/MAINTAINERS     |  7 +++
 board/mediatek/mt7628/Makefile        |  3 ++
 board/mediatek/mt7628/board.c         |  8 ++++
 configs/mt7628_rfb_defconfig          | 46 ++++++++++++++++++
 include/configs/mt7628.h              | 56 ++++++++++++++++++++++
 9 files changed, 209 insertions(+)
 create mode 100644 arch/mips/dts/mediatek,mt7628-rfb.dts
 create mode 100644 board/mediatek/mt7628/Kconfig
 create mode 100644 board/mediatek/mt7628/MAINTAINERS
 create mode 100644 board/mediatek/mt7628/Makefile
 create mode 100644 board/mediatek/mt7628/board.c
 create mode 100644 configs/mt7628_rfb_defconfig
 create mode 100644 include/configs/mt7628.h
arch/mips/dts/Makefile +1 -0
index c9d75596f2..cbd0c8bc8b 100644
@@ -17,6 +17,7 @@ dtb-$(CONFIG_BOARD_COMTREND_CT5361) += comtrend,ct-5361.dtb
 dtb-$(CONFIG_BOARD_COMTREND_VR3032U) += comtrend,vr-3032u.dtb
 dtb-$(CONFIG_BOARD_COMTREND_WAP5813N) += comtrend,wap-5813n.dtb
 dtb-$(CONFIG_BOARD_HUAWEI_HG556A) += huawei,hg556a.dtb
+dtb-$(CONFIG_BOARD_MT7628_RFB) += mediatek,mt7628-rfb.dtb
 dtb-$(CONFIG_BOARD_NETGEAR_CG3100D) += netgear,cg3100d.dtb
 dtb-$(CONFIG_BOARD_NETGEAR_DGND3700V2) += netgear,dgnd3700v2.dtb
 dtb-$(CONFIG_BOARD_SAGEM_FAST1704) += sagem,f at st1704.dtb
arch/mips/dts/mediatek,mt7628-rfb.dts new file +67 -0

67 lines not on this page · raw message

arch/mips/mach-mtmips/Kconfig +9 -0
index ad28ef3a8c..5931081556 100644
@@ -78,6 +78,14 @@ config BOARD_LINKIT_SMART_7688
 	  ethernet ports, 1 USB port, 1 UART, GPIO buttons and LEDs, and
 	  a MT7688 (PCIe).
 
+config BOARD_MT7628_RFB
+	bool "MediaTek MT7628 RFB"
+	depends on SOC_MT7628
+	help
+	  The reference design of MT7628. The board has 128 MiB DDR2, 8 MiB
+	  SPI-NOR flash, 1 built-in switch with 5 ports, 1 UART, 1 USB host,
+	  1 SDXC, 1 PCIe socket and JTAG pins.
+
 endchoice
 
 config SPL_UART2_SPIS_PINMUX
@@ -89,6 +97,7 @@ config SPL_UART2_SPIS_PINMUX
 	  (shared with SPIS) rather than the usual GPIO 20/21.
 
 source "board/gardena/smart-gateway-mt7688/Kconfig"
+source "board/mediatek/mt7628/Kconfig"
 source "board/seeed/linkit-smart-7688/Kconfig"
 
 endmenu
board/mediatek/mt7628/Kconfig new file +12 -0
new file mode 100644
index 0000000000..d6b6f9d632
@@ -0,0 +1,12 @@
+if BOARD_MT7628_RFB
+
+config SYS_BOARD
+	default "mt7628"
+
+config SYS_VENDOR
+	default "mediatek"
+
+config SYS_CONFIG_NAME
+	default "mt7628"
+
+endif
board/mediatek/mt7628/MAINTAINERS new file +7 -0
new file mode 100644
index 0000000000..032fd0e2f7
@@ -0,0 +1,7 @@
+MT7628_RFB BOARD
+M:	Weijie Gao <[email protected]>
+S:	Maintained
+F:	board/mediatek/mt7628
+F:	include/configs/mt7628.h
+F:	configs/mt7628_rfb_defconfig
+F:	arch/mips/dts/mediatek,mt7628-rfb.dts
board/mediatek/mt7628/Makefile new file +3 -0
new file mode 100644
index 0000000000..db129c5aba
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-y += board.o
board/mediatek/mt7628/board.c new file +8 -0
new file mode 100644
index 0000000000..f837a06fbb
@@ -0,0 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 MediaTek Inc. All Rights Reserved.
+ *
+ * Author: Weijie Gao <[email protected]>
+ */
+
+#include <common.h>
configs/mt7628_rfb_defconfig new file +46 -0

46 lines not on this page · raw message

include/configs/mt7628.h new file +56 -0

56 lines not on this page · raw message

Signature · 1 line
2.26.2
#35 lore raw

PATCH v7 26/26 mips: mtmips: Increase CONFIG_SPL_SYS_MALLOC_F_LEN

In reply to Stefan Roese

Since SPL now uses malloc to allocate the buffer for the compressed image before decompression to the destination address, we need to configure a big enough malloc space in SPL. 256k seems to be big enough even for the GARDENA board.

Cc Daniel Schwierzeck <[email protected]>
Cc Weijie Gao <[email protected]>

---
Changes in v7:
- None

Changes in v6:
- New patch

 configs/gardena-smart-gateway-mt7688_defconfig | 4 ++--
 configs/linkit-smart-7688_defconfig            | 2 +-
 configs/mt7628_rfb_defconfig                   | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
configs/gardena-smart-gateway-mt7688_defconfig +2 -2
index e01fc937c1..0aeba1e2e2 100644
@@ -4,9 +4,9 @@ CONFIG_SPL_LIBGENERIC_SUPPORT=y
 CONFIG_ENV_SIZE=0x10000
 CONFIG_ENV_SECT_SIZE=0x10000
 CONFIG_ENV_OFFSET=0xA0000
-CONFIG_SYS_BOOTCOUNT_ADDR=0xb000006c
 CONFIG_SPL_SERIAL_SUPPORT=y
-CONFIG_SPL_SYS_MALLOC_F_LEN=0x20000
+CONFIG_SYS_BOOTCOUNT_ADDR=0xb000006c
+CONFIG_SPL_SYS_MALLOC_F_LEN=0x40000
 CONFIG_NR_DRAM_BANKS=1
 CONFIG_SPL=y
 CONFIG_SYS_BOOTCOUNT_SINGLEWORD=y
configs/linkit-smart-7688_defconfig +1 -1
index 642755ec65..8e13cee58d 100644
@@ -5,7 +5,7 @@ CONFIG_ENV_SIZE=0x4000
 CONFIG_ENV_SECT_SIZE=0x10000
 CONFIG_ENV_OFFSET=0x80000
 CONFIG_SPL_SERIAL_SUPPORT=y
-CONFIG_SPL_SYS_MALLOC_F_LEN=0x20000
+CONFIG_SPL_SYS_MALLOC_F_LEN=0x40000
 CONFIG_NR_DRAM_BANKS=1
 CONFIG_SPL=y
 CONFIG_ARCH_MTMIPS=y
configs/mt7628_rfb_defconfig +1 -1
index eb73dbb490..ce3e0263d1 100644
@@ -5,7 +5,7 @@ CONFIG_ENV_SIZE=0x1000
 CONFIG_ENV_SECT_SIZE=0x10000
 CONFIG_ENV_OFFSET=0x30000
 CONFIG_SPL_SERIAL_SUPPORT=y
-CONFIG_SPL_SYS_MALLOC_F_LEN=0x20000
+CONFIG_SPL_SYS_MALLOC_F_LEN=0x40000
 CONFIG_NR_DRAM_BANKS=1
 CONFIG_SPL=y
 CONFIG_ARCH_MTMIPS=y
Signature · 1 line
2.26.2
#36 lore raw

v7 cover Refactor the architecture parts of mt7628

In reply to Stefan Roese

Am 21.04.20 um 09:28 schrieb Stefan Roese:

Quoted 160 lines

This patch series are divided into two parts:

The main part is to rewrite the whole architecture code of mt7628:
* Lock parts of the d-cache for initial stack so the rest of the code can be reimplemented in C.
* Memory controller & DDR initialization have been fully written to support detecting DDR size automatically.
* DDR calibration has also been reimplemented with a clear logic.
* Implemented a new sysreset driver to take advantage of the reset controller so we can drop the use of syscon-based sysreset to reduce size.

The second part is to add SPL support for mt7628:
* With SPL enabled we can build the ROM-bootable and RAM-bootable binary simultaneously, and we can drop RAM boot related configs and defconfig files.
* Generate compressed u-boot.bin image for SPL to reduce size of final combined binary.
* Enable DM support for SPL for a more flexible device probing.
* Add a demo board (mt7628_rfb) aims at router application.

Changes since v2:
* Dropped a patch which removes unused parts of mt7628a.dtsi
* Move lzma decompression support to common spl_nor.c
* Move u-boot,dm-pre-reloc to u-boot-mt7628.dtsi

Changes since v3:
* Rebased on newest master branch
* Add a test for binman etype u-boot-lzma-img to make sure binman passes 100% code coverage
* Use u-boot-with-spl.bin for SPL-enabled output file
* Remove unused code from spl_nor loader.

Changes since v5:
* Rebased on newest master branch
* Made lzma decompressing support for legacy U-Boot images more generic, so that it can be easily integrated into other devices loaders as well

Changes since v6:
* Add spl_image_get_comp() to enable the compiler to optimize the switch/case statement away due to Dead Code Elimination as suggested by Daniel
* Moved cache flush to MIPS specific file as suggested by Daniel

Stefan Roese (6):
spl: Extract legacy image handling into separate file
spl: spl_legacy: Use IS_ENABLED() to remove #ifdef
spl: spl_nor: Move legacy image loading into spl_legacy.c
spl: spl_nor: Remove unused variable 'ret' warning
mips: spl: Flush cache before jumping to U-Boot proper
mips: mtmips: Increase CONFIG_SPL_SYS_MALLOC_F_LEN

Weijie Gao (20):
mips: add support to restore exception vector base before booting
linux
mips: mtmips: add predefined i-cache/d-cache size and linesize
mips: add an option to support initialize SRAM for initial stack
mips: start.S: avoid overwriting outside gd when clearing global data
in stack
sysreset: add reset controller based reboot driver
mips: mtmips: make use of sysreset-resetctrl for mt7628 soc
configs: enable CONFIG_RESTORE_EXCEPTION_VECTOR_BASE for all mtmips
boards
mips: add a mtmips-specific field to architecture-specific global data
mips: add a option to support not reserving malloc space on initial
stack
mips: mtmips: rewrite lowlevel codes of mt7628
dts: mtmips: add alternative pinmux node for uart2
mips: enable support for appending dtb to spl binary
mips: add an option to enable u_boot_list section for SPL loaders in
u-boot-spl.lds
lib: enable lzma decompression support for SPL build
Makefile: add support to generate LZMA compressed u-boot image
tools: binman: add etype file for u-boot-lzma-img
spl: spl_legacy: Add lzma decompression support for legacy image
mips: mtmips: add SPL support
mips: mtmips: enable SPL for all boards
mips: mtmips: add support for mt7628-rfb

 Makefile                                      |  19 +
 arch/mips/Kconfig                             |  66 ++++
 arch/mips/cpu/start.S                         |  16 +-
 arch/mips/cpu/u-boot-spl.lds                  |   4 +-
 arch/mips/dts/Makefile                        |   1 +
 arch/mips/dts/mediatek,mt7628-rfb.dts         |  67 ++++
 arch/mips/dts/mt7628-u-boot.dtsi              |  56 +++
 arch/mips/dts/mt7628a.dtsi                    |  17 +-
 arch/mips/include/asm/global_data.h           |   3 +
 arch/mips/include/asm/u-boot-mips.h           |   2 +
 arch/mips/lib/Makefile                        |   1 +
 arch/mips/lib/bootm.c                         |   3 +
 arch/mips/lib/spl.c                           |  21 ++
 arch/mips/lib/traps.c                         |  19 +
 arch/mips/mach-mtmips/Kconfig                 | 135 +++----
 arch/mips/mach-mtmips/Makefile                |   8 +-
 arch/mips/mach-mtmips/cpu.c                   |  58 +---
 arch/mips/mach-mtmips/ddr_cal.c               | 211 +++++++++++
 arch/mips/mach-mtmips/ddr_calibrate.c         | 309 -----------------
 arch/mips/mach-mtmips/ddr_init.c              | 194 +++++++++++
 arch/mips/mach-mtmips/include/mach/ddr.h      |  52 +++
 arch/mips/mach-mtmips/include/mach/mc.h       | 180 ++++++++++
 arch/mips/mach-mtmips/include/mach/serial.h   |  13 +
 arch/mips/mach-mtmips/lowlevel_init.S         | 328 ------------------
 arch/mips/mach-mtmips/mt7628/Makefile         |   6 +
 arch/mips/mach-mtmips/mt7628/ddr.c            | 173 +++++++++
 arch/mips/mach-mtmips/mt7628/init.c           | 109 ++++++
 arch/mips/mach-mtmips/mt7628/lowlevel_init.S  | 161 +++++++++
 arch/mips/mach-mtmips/mt7628/mt7628.h         | 104 ++++++
 arch/mips/mach-mtmips/mt7628/serial.c         |  34 ++
 arch/mips/mach-mtmips/mt76xx.h                |  32 --
 arch/mips/mach-mtmips/spl.c                   |  44 +++
 board/gardena/smart-gateway-mt7688/board.c    |   2 +
 board/mediatek/mt7628/Kconfig                 |  12 +
 board/mediatek/mt7628/MAINTAINERS             |   7 +
 board/mediatek/mt7628/Makefile                |   3 +
 board/mediatek/mt7628/board.c                 |   8 +
 common/spl/Makefile                           |   1 +
 common/spl/spl.c                              |  56 +--
 common/spl/spl_legacy.c                       | 131 +++++++
 common/spl/spl_nor.c                          |  27 +-
 ...gardena-smart-gateway-mt7688-ram_defconfig |  74 ----
 .../gardena-smart-gateway-mt7688_defconfig    |  14 +-
 configs/linkit-smart-7688-ram_defconfig       |  65 ----
 configs/linkit-smart-7688_defconfig           |  14 +-
 configs/mt7628_rfb_defconfig                  |  46 +++
 drivers/sysreset/Kconfig                      |   6 +
 drivers/sysreset/Makefile                     |   1 +
 drivers/sysreset/sysreset_resetctl.c          |  48 +++
 .../configs/gardena-smart-gateway-mt7688.h    |  21 +-
 include/configs/linkit-smart-7688.h           |  22 +-
 include/configs/mt7628.h                      |  56 +++
 include/spl.h                                 |  13 +
 lib/Kconfig                                   |   5 +
 lib/Makefile                                  |   1 +
 tools/binman/README.entries                   |  15 +
 tools/binman/etype/u_boot_lzma_img.py         |  28 ++
 tools/binman/ftest.py                         |   7 +
 tools/binman/test/156_u_boot_lzma_img.dts     |  11 +
 59 files changed, 2108 insertions(+), 1032 deletions(-)
 create mode 100644 arch/mips/dts/mediatek,mt7628-rfb.dts
 create mode 100644 arch/mips/dts/mt7628-u-boot.dtsi
 create mode 100644 arch/mips/lib/spl.c
 create mode 100644 arch/mips/mach-mtmips/ddr_cal.c
 delete mode 100644 arch/mips/mach-mtmips/ddr_calibrate.c
 create mode 100644 arch/mips/mach-mtmips/ddr_init.c
 create mode 100644 arch/mips/mach-mtmips/include/mach/ddr.h
 create mode 100644 arch/mips/mach-mtmips/include/mach/mc.h
 create mode 100644 arch/mips/mach-mtmips/include/mach/serial.h
 delete mode 100644 arch/mips/mach-mtmips/lowlevel_init.S
 create mode 100644 arch/mips/mach-mtmips/mt7628/Makefile
 create mode 100644 arch/mips/mach-mtmips/mt7628/ddr.c
 create mode 100644 arch/mips/mach-mtmips/mt7628/init.c
 create mode 100644 arch/mips/mach-mtmips/mt7628/lowlevel_init.S
 create mode 100644 arch/mips/mach-mtmips/mt7628/mt7628.h
 create mode 100644 arch/mips/mach-mtmips/mt7628/serial.c
 delete mode 100644 arch/mips/mach-mtmips/mt76xx.h
 create mode 100644 arch/mips/mach-mtmips/spl.c
 create mode 100644 board/mediatek/mt7628/Kconfig
 create mode 100644 board/mediatek/mt7628/MAINTAINERS
 create mode 100644 board/mediatek/mt7628/Makefile
 create mode 100644 board/mediatek/mt7628/board.c
Quoted 9 lines
 create mode 100644 common/spl/spl_legacy.c
 delete mode 100644 configs/gardena-smart-gateway-mt7688-ram_defconfig
 delete mode 100644 configs/linkit-smart-7688-ram_defconfig
 create mode 100644 configs/mt7628_rfb_defconfig
 create mode 100644 drivers/sysreset/sysreset_resetctl.c
 create mode 100644 include/configs/mt7628.h
 create mode 100644 tools/binman/etype/u_boot_lzma_img.py
 create mode 100644 tools/binman/test/156_u_boot_lzma_img.dts

series applied to u-boot-mips/next with some reordering of patches and some minor fixups. The binman patch was left out because binman wasn't used anymore since v4.

Signature · 1 line
- Daniel