Skip to contentSkip to conversation

Refactor the architecture parts of mt7628

PATCH Superseded Stefan Roese 3 participants 35 messages Apr 8, 2020 – Apr 10, 2020

Subsystems (5)

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v6 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

Stefan Roese (4):
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
mips: mtmips: Increase CONFIG_SPL_SYS_MALLOC_F_LEN

Weijie Gao (22):
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_nor: Copy image header to local struct
spl: spl_legacy: Add lzma decompression support for legacy image
spl: spl_legacy: Add cache flush after reading U-Boot 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/bootm.c                         |   3 +
 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                       | 116 +++++++
 common/spl/spl_nor.c                          |  31 +-
 ...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                                 |  14 +
 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 +
 57 files changed, 2077 insertions(+), 1031 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/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.0
#1 lore raw

PATCH v6 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.0
#2 lore raw

PATCH v6 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.0
#3 lore raw

PATCH v6 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.0
#4 lore raw

PATCH v6 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.0
#5 lore raw

PATCH v6 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.0
#6 lore raw

PATCH v6 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.0
#7 lore raw

PATCH v6 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.0
#8 lore raw

PATCH v6 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.0
#9 lore raw

PATCH v6 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.0
#10 lore raw

PATCH v6 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.0
#11 lore raw

PATCH v6 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.0
#12 lore raw

PATCH v6 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.0
#13 lore raw

PATCH v6 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.0
#14 lore raw

PATCH v6 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 ab6aff710d..5f52f14686 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 15259d0473..fa497a366d 100644
@@ -66,6 +66,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.0
#15 lore raw

PATCH v6 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 8de5ff6d94..9e01b70e4b 100644
@@ -954,6 +954,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
@@ -1336,6 +1339,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.0
#16 lore raw

PATCH v6 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.0
#17 lore raw

PATCH v6 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 Weijie Gao <[email protected]>
Cc Simon Goldschmidt <[email protected]>

---
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.0
#18 lore raw

PATCH v6 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 Weijie Gao <[email protected]>
Cc Simon Goldschmidt <[email protected]>

---
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.0
#19 lore raw

PATCH v6 19/26 spl: spl_nor: Copy image header to local struct

In reply to Stefan Roese

From: Weijie Gao <[email protected]>

The image header may be unaligned causing a crash, e.g. on the MT76x8 platform. This patch copies the header to a local struct to fix this potential issue.

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

---
Changes in v6:
- New patch

 common/spl/spl_nor.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
common/spl/spl_nor.c +7 -2
index b1e79b9ded..cb8e06fe1f 100644
@@ -27,6 +27,8 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,
 	int ret;
 	__maybe_unused const struct image_header *header;
 	__maybe_unused struct spl_load_info load;
+	struct image_header hdr;
+	uintptr_t dataptr;
 
 	/*
 	 * Loading of the payload to SDRAM is done with skipping of
@@ -112,9 +114,12 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,
 	if (ret)
 		return ret;
 
+	/* Payload image may not be aligned, so copy it for safety */
+	memcpy(&hdr, (void *)spl_nor_get_uboot_base(), sizeof(hdr));
+	dataptr = spl_nor_get_uboot_base() + sizeof(struct image_header);
+
 	memcpy((void *)(unsigned long)spl_image->load_addr,
-	       (void *)(spl_nor_get_uboot_base() + sizeof(struct image_header)),
-	       spl_image->size);
+	       (void *)dataptr, spl_image->size);
 
 	return 0;
 }
Signature · 1 line
2.26.0
#20 lore raw

PATCH v6 19/26 spl: spl_nor: Copy image header to local struct

Quoted 11 lines · Stefan Roese

From: Weijie Gao <[email protected]>

The image header may be unaligned causing a crash, e.g. on the MT76x8 platform. This patch copies the header to a local struct to fix this potential issue.

Cc Weijie Gao <[email protected]>
Cc Simon Goldschmidt <[email protected]>
Quoted 38 lines

---
Changes in v6:
- New patch

 common/spl/spl_nor.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
common/spl/spl_nor.c +7 -3
index b1e79b9ded..cb8e06fe1f 100644
@@ -27,6 +27,8 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,
        int ret;
        __maybe_unused const struct image_header *header;
        __maybe_unused struct spl_load_info load;
+       struct image_header hdr;
+       uintptr_t dataptr;
 
        /*
         * Loading of the payload to SDRAM is done with skipping of
@@ -112,9 +114,12 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,
        if (ret)
                return ret;
 
+       /* Payload image may not be aligned, so copy it for safety */
+       memcpy(&hdr, (void *)spl_nor_get_uboot_base(), sizeof(hdr));
+       dataptr = spl_nor_get_uboot_base() + sizeof(struct image_header);
+
        memcpy((void *)(unsigned long)spl_image->load_addr,
-              (void *)(spl_nor_get_uboot_base() + sizeof(struct image_header)),
-              spl_image->size);
+              (void *)dataptr, spl_image->size);
 
        return 0;
 }
--

2.26.0

#21 lore raw

PATCH v6 20/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 indended.

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

---
Changes in v6:
- New patch

 common/spl/spl_legacy.c | 17 +++++++++++++++++
 common/spl/spl_nor.c    | 34 +++++++++++++++++-----------------
 include/spl.h           | 14 ++++++++++++++
 3 files changed, 48 insertions(+), 17 deletions(-)
common/spl/spl_legacy.c +17 -0
index 772135193e..d0fc4b111e 100644
@@ -51,3 +51,20 @@ int spl_parse_legacy_header(struct spl_image_info *spl_image,
 
 	return 0;
 }
+
+int spl_load_legacy_img(struct spl_image_info *spl_image,
+			const struct image_header *header,
+			uintptr_t dataptr, struct spl_load_info *info)
+{
+	int ret;
+
+	ret = spl_parse_image_header(spl_image, header);
+	if (ret)
+		return ret;
+
+	dataptr = (uintptr_t)header + sizeof(struct image_header);
+	info->read(info, dataptr, spl_image->size,
+		   (void *)(unsigned long)spl_image->load_addr);
+
+	return 0;
+}
common/spl/spl_nor.c +17 -17
index cb8e06fe1f..d55165b772 100644
@@ -24,11 +24,8 @@ 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;
-	struct image_header hdr;
-	uintptr_t dataptr;
 
 	/*
 	 * Loading of the payload to SDRAM is done with skipping of
@@ -45,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;
@@ -63,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)
@@ -95,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)) {
@@ -109,17 +107,19 @@ 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;
+	if (IS_ENABLED(CONFIG_SPL_LEGACY_IMAGE_SUPPORT)) {
+		struct image_header hdr;
+		uintptr_t dataptr;
 
-	/* Payload image may not be aligned, so copy it for safety */
-	memcpy(&hdr, (void *)spl_nor_get_uboot_base(), sizeof(hdr));
-	dataptr = spl_nor_get_uboot_base() + sizeof(struct image_header);
+		/* Payload image may not be aligned, so copy it for safety */
+		memcpy(&hdr, (void *)spl_nor_get_uboot_base(), sizeof(hdr));
+		dataptr = spl_nor_get_uboot_base() + sizeof(hdr);
 
-	memcpy((void *)(unsigned long)spl_image->load_addr,
-	       (void *)dataptr, spl_image->size);
+		/* Legacy image handling */
+		load.bl_len = 1;
+		load.read = spl_nor_load_read;
+		return spl_load_legacy_img(spl_image, &hdr, dataptr, &load);
+	}
 
 	return 0;
 }
include/spl.h +14 -0
index 6087cd793c..5331591db5 100644
@@ -219,6 +219,20 @@ 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
+ * @dataptr:	Source location of the image
+ * @header:	Image header to parse
+ *
+ * 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,
+			const struct image_header *header,
+			uintptr_t dataptr, struct spl_load_info *load);
+
 /**
  * spl_load_imx_container() - Loads a imx container image from a device.
  * @spl_image:	Image description to set up
Signature · 1 line
2.26.0
#22 lore raw

PATCH v6 20/26 spl: spl_nor: Move legacy image loading into spl_legacy.c

Am 08.04.20 um 10:09 schrieb Stefan Roese:

Quoted 28 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 indended.

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

---
Changes in v6:
- New patch

 common/spl/spl_legacy.c | 17 +++++++++++++++++
 common/spl/spl_nor.c    | 34 +++++++++++++++++-----------------
 include/spl.h           | 14 ++++++++++++++
 3 files changed, 48 insertions(+), 17 deletions(-)
common/spl/spl_legacy.c +2 -0
index 772135193e..d0fc4b111e 100644
@@ -51,3 +51,20 @@ int spl_parse_legacy_header(struct spl_image_info *spl_image,
 
 	return 0;
 }
+
+int spl_load_legacy_img(struct spl_image_info *spl_image,

common/spl/spl_legacy.c int spl_parse_legacy_header(struct spl_image_info *spl_image, · line 65

Quoted 10 lines
common/spl/spl_legacy.c +10 -0
+			const struct image_header *header,
+			uintptr_t dataptr, struct spl_load_info *info)
+{
+	int ret;
+
+	ret = spl_parse_image_header(spl_image, header);
+	if (ret)
+		return ret;
+
+	dataptr = (uintptr_t)header + sizeof(struct image_header);

how should this work? You call this function with

spl_load_legacy_img(spl_image, &hdr, dataptr, &load);

so "header" points to the copy on the stack. "dataptr" already holds the address of the SPL payload. If you overwrite "dataptr" now, it will point to the stack area after the header copy.

Quoted 69 lines
common/spl/spl_legacy.c +5 -0
+	info->read(info, dataptr, spl_image->size,
+		   (void *)(unsigned long)spl_image->load_addr);
+
+	return 0;
+}
common/spl/spl_nor.c +10 -15
index cb8e06fe1f..d55165b772 100644
@@ -24,11 +24,8 @@ 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;
-	struct image_header hdr;
-	uintptr_t dataptr;
 
 	/*
 	 * Loading of the payload to SDRAM is done with skipping of
@@ -45,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;
@@ -63,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)
@@ -95,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)) {
@@ -109,17 +107,19 @@ 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;
+	if (IS_ENABLED(CONFIG_SPL_LEGACY_IMAGE_SUPPORT)) {
+		struct image_header hdr;
+		uintptr_t dataptr;
 
-	/* Payload image may not be aligned, so copy it for safety */
-	memcpy(&hdr, (void *)spl_nor_get_uboot_base(), sizeof(hdr));
-	dataptr = spl_nor_get_uboot_base() + sizeof(struct image_header);
+		/* Payload image may not be aligned, so copy it for safety */

common/spl/spl_nor.c static int spl_nor_load_image(struct spl_image_info *spl_image, · line 122

Quoted 10 lines
common/spl/spl_nor.c +7 -2
+		memcpy(&hdr, (void *)spl_nor_get_uboot_base(), sizeof(hdr));
+		dataptr = spl_nor_get_uboot_base() + sizeof(hdr);
 
-	memcpy((void *)(unsigned long)spl_image->load_addr,
-	       (void *)dataptr, spl_image->size);
+		/* Legacy image handling */
+		load.bl_len = 1;
+		load.read = spl_nor_load_read;
+		return spl_load_legacy_img(spl_image, &hdr, dataptr, &load);
+	}

I don't understand it fully. Is the purpose of the header copy to avoid unaligned access to the header in spl_parse_image_header()?

If so then the copy should be made in spl_load_legacy_img() itself.

Quoted 29 lines
common/spl/spl_nor.c +0 -0
 	return 0;
 }
include/spl.h +14 -0
index 6087cd793c..5331591db5 100644
@@ -219,6 +219,20 @@ 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
+ * @dataptr:	Source location of the image
+ * @header:	Image header to parse
+ *
+ * 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,
+			const struct image_header *header,
+			uintptr_t dataptr, struct spl_load_info *load);
+
 /**
  * spl_load_imx_container() - Loads a imx container image from a device.
  * @spl_image:	Image description to set up
Signature · 1 line
- Daniel
#23 lore raw

PATCH v6 20/26 spl: spl_nor: Move legacy image loading into spl_legacy.c

Quoted 44 lines · Daniel Schwierzeck

Am 08.04.20 um 10:09 schrieb Stefan Roese:

Quoted 28 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 indended.

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

---
Changes in v6:
- New patch

  common/spl/spl_legacy.c | 17 +++++++++++++++++
  common/spl/spl_nor.c    | 34 +++++++++++++++++-----------------
  include/spl.h           | 14 ++++++++++++++
  3 files changed, 48 insertions(+), 17 deletions(-)
common/spl/spl_legacy.c +2 -0
index 772135193e..d0fc4b111e 100644
@@ -51,3 +51,20 @@ int spl_parse_legacy_header(struct spl_image_info *spl_image,
 
  	return 0;
  }
+
+int spl_load_legacy_img(struct spl_image_info *spl_image,

common/spl/spl_legacy.c int spl_parse_legacy_header(struct spl_image_info *spl_image, · line 65

Quoted 10 lines
common/spl/spl_legacy.c +10 -0
+			const struct image_header *header,
+			uintptr_t dataptr, struct spl_load_info *info)
+{
+	int ret;
+
+	ret = spl_parse_image_header(spl_image, header);
+	if (ret)
+		return ret;
+
+	dataptr = (uintptr_t)header + sizeof(struct image_header);

how should this work? You call this function with

Quoted 5 lines

spl_load_legacy_img(spl_image, &hdr, dataptr, &load);

so "header" points to the copy on the stack. "dataptr" already holds the address of the SPL payload. If you overwrite "dataptr" now, it will point to the stack area after the header copy.

You are correct. I fat-fingered while rebasing the patches here. As you will see, this assignment will be removed in the next patch [21/26].

I'll change it in v7.

Quoted 73 lines
Quoted 73 lines
common/spl/spl_legacy.c +5 -0
+	info->read(info, dataptr, spl_image->size,
+		   (void *)(unsigned long)spl_image->load_addr);
+
+	return 0;
+}
common/spl/spl_nor.c +12 -15
index cb8e06fe1f..d55165b772 100644
@@ -24,11 +24,8 @@ 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;
-	struct image_header hdr;
-	uintptr_t dataptr;
 
  	/*
  	 * Loading of the payload to SDRAM is done with skipping of
@@ -45,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;
@@ -63,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)
@@ -95,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)) {
@@ -109,17 +107,19 @@ 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;
+	if (IS_ENABLED(CONFIG_SPL_LEGACY_IMAGE_SUPPORT)) {
+		struct image_header hdr;
+		uintptr_t dataptr;
 
-	/* Payload image may not be aligned, so copy it for safety */
-	memcpy(&hdr, (void *)spl_nor_get_uboot_base(), sizeof(hdr));
-	dataptr = spl_nor_get_uboot_base() + sizeof(struct image_header);
+		/* Payload image may not be aligned, so copy it for safety */
+		memcpy(&hdr, (void *)spl_nor_get_uboot_base(), sizeof(hdr));
+		dataptr = spl_nor_get_uboot_base() + sizeof(hdr);
 
Quoted 10 lines

common/spl/spl_nor.c static int spl_nor_load_image(struct spl_image_info *spl_image, · line 122

Quoted 7 lines
common/spl/spl_nor.c +5 -2
-	memcpy((void *)(unsigned long)spl_image->load_addr,
-	       (void *)dataptr, spl_image->size);
+		/* Legacy image handling */
+		load.bl_len = 1;
+		load.read = spl_nor_load_read;
+		return spl_load_legacy_img(spl_image, &hdr, dataptr, &load);
+	}

I don't understand it fully. Is the purpose of the header copy to avoid unaligned access to the header in spl_parse_image_header()?

Yes.

Quoted 1 line

If so then the copy should be made in spl_load_legacy_img() itself.

Thats what I had implemented in an internal version already. Not sure, why I switched to not using it in this v6? I'll re-think about it and will perhaps move it to spl_load_legacy_img() again.

Thanks,
Stefan

#24 lore raw

PATCH v6 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 Weijie Gao <[email protected]>
Cc Simon Goldschmidt <[email protected]>

---
Changes in v6:
- New patch

 common/spl/spl_legacy.c | 48 ++++++++++++++++++++++++++++++++++++++---
 1 file changed, 45 insertions(+), 3 deletions(-)
common/spl/spl_legacy.c +45 -3
index d0fc4b111e..2cd2a74a4c 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)
 {
@@ -56,15 +63,50 @@ int spl_load_legacy_img(struct spl_image_info *spl_image,
 			const struct image_header *header,
 			uintptr_t dataptr, struct spl_load_info *info)
 {
+	__maybe_unused SizeT lzma_len;
+	__maybe_unused void *src;
 	int ret;
 
 	ret = spl_parse_image_header(spl_image, header);
 	if (ret)
 		return ret;
 
-	dataptr = (uintptr_t)header + sizeof(struct image_header);
-	info->read(info, dataptr, spl_image->size,
-		   (void *)(unsigned long)spl_image->load_addr);
+	switch (image_get_comp(header)) {
+	case IH_COMP_NONE:
+		info->read(info, dataptr, spl_image->size,
+			   (void *)(unsigned long)spl_image->load_addr);
+		break;
+
+#if IS_ENABLED(CONFIG_SPL_LZMA)
+	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;
+		}
+
+		info->read(info, 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;
+#endif
+
+	default:
+		debug("Compression method %s is not supported\n",
+		      genimg_get_comp_short_name(image_get_comp(header)));
+		return -EINVAL;
+	}
 
 	return 0;
 }
Signature · 1 line
2.26.0
#25 lore raw

PATCH v6 22/26 spl: spl_legacy: Add cache flush after reading U-Boot image

In reply to Stefan Roese

From: Weijie Gao <[email protected]>

Flush the cache after reading of the U-Boot proper into SDRAM so that it can be started.

This is needed on some platforms, e.g. MT76x8.

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

---
Changes in v6:
- New patch

 common/spl/spl_legacy.c | 4 ++++
 1 file changed, 4 insertions(+)
common/spl/spl_legacy.c +4 -0
index 2cd2a74a4c..e320206098 100644
@@ -4,6 +4,7 @@
  */
 
 #include <common.h>
+#include <cpu_func.h>
 #include <malloc.h>
 #include <spl.h>
 
@@ -108,5 +109,8 @@ int spl_load_legacy_img(struct spl_image_info *spl_image,
 		return -EINVAL;
 	}
 
+	/* Flush cache of loaded U-Boot image */
+	flush_cache((unsigned long)spl_image->load_addr, spl_image->size);
+
 	return 0;
 }
Signature · 1 line
2.26.0
#26 lore raw

PATCH v6 22/26 spl: spl_legacy: Add cache flush after reading U-Boot image

Am 08.04.2020 um 10:09 schrieb Stefan Roese:

Quoted 31 lines

From: Weijie Gao <[email protected]>

Flush the cache after reading of the U-Boot proper into SDRAM so that it can be started.

This is needed on some platforms, e.g. MT76x8.

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

---
Changes in v6:
- New patch

 common/spl/spl_legacy.c | 4 ++++
 1 file changed, 4 insertions(+)
common/spl/spl_legacy.c +1 -0
index 2cd2a74a4c..e320206098 100644
@@ -4,6 +4,7 @@
  */
 
 #include <common.h>
+#include <cpu_func.h>
 #include <malloc.h>
 #include <spl.h>
 

common/spl/spl_legacy.c int spl_load_legacy_img(struct spl_image_info *spl_image, · line 114

Quoted 6 lines
common/spl/spl_legacy.c +3 -0
@@ -108,5 +109,8 @@ int spl_load_legacy_img(struct spl_image_info *spl_image,
 		return -EINVAL;
 	}
 
+	/* Flush cache of loaded U-Boot image */
+	flush_cache((unsigned long)spl_image->load_addr, spl_image->size);
+

I failed to find the mail, but haven't we discussed moving this cache flush to your arch before starting a binary?

I cannot see this being required or implemented for non-legacy images, and it still seems wrong here.

Regards,
Simon

Quoted 3 lines
common/spl/spl_legacy.c +0 -0
 	return 0;
 }
#27 lore raw

PATCH v6 22/26 spl: spl_legacy: Add cache flush after reading U-Boot image

Quoted 35 lines · Simon Goldschmidt

Am 08.04.2020 um 10:09 schrieb Stefan Roese:

Quoted 34 lines

From: Weijie Gao <[email protected]>

Flush the cache after reading of the U-Boot proper into SDRAM so that it can be started.

This is needed on some platforms, e.g. MT76x8.

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

---
Changes in v6:
- New patch

  common/spl/spl_legacy.c | 4 ++++
  1 file changed, 4 insertions(+)
common/spl/spl_legacy.c +1 -0
index 2cd2a74a4c..e320206098 100644
@@ -4,6 +4,7 @@
   */
 
  #include <common.h>
+#include <cpu_func.h>
  #include <malloc.h>
  #include <spl.h>
 
@@ -108,5 +109,8 @@ int spl_load_legacy_img(struct spl_image_info *spl_image,
  		return -EINVAL;
  	}
 
Quoted 6 lines

common/spl/spl_legacy.c int spl_load_legacy_img(struct spl_image_info *spl_image, · line 114

Quoted 3 lines
common/spl/spl_legacy.c +3 -0
+	/* Flush cache of loaded U-Boot image */
+	flush_cache((unsigned long)spl_image->load_addr, spl_image->size);
+

I failed to find the mail, but haven't we discussed moving this cache flush to your arch before starting a binary?

I don't remember such an agreement. But I don't object in general.

Quoted 2 lines

I cannot see this being required or implemented for non-legacy images, and it still seems wrong here.

Its pretty common when an OS image is loaded and booted, that the cache is flushed before running code from it.

But I can rework this to add some empty weak function (I don't see an easy better way) to do this platform specific image handling before its booted. Or do you have a better idea on how to handle this?

Thanks,
Stefan

#28 lore raw

PATCH v6 22/26 spl: spl_legacy: Add cache flush after reading U-Boot image

Am 09.04.20 um 09:43 schrieb Stefan Roese:

Quoted 49 lines · Simon Goldschmidt
Quoted 31 lines

Am 08.04.2020 um 10:09 schrieb Stefan Roese:

Quoted 30 lines

From: Weijie Gao <[email protected]>

Flush the cache after reading of the U-Boot proper into SDRAM so that it can be started.

This is needed on some platforms, e.g. MT76x8.

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

---
Changes in v6:
- New patch

? common/spl/spl_legacy.c | 4 ++++
? 1 file changed, 4 insertions(+)

common/spl/spl_legacy.c +0 -0
index 2cd2a74a4c..e320206098 100644
@@ -4,6 +4,7 @@

?? */
? ? #include <common.h>
+#include <cpu_func.h>
? #include <malloc.h>
? #include <spl.h>
? @@ -108,5 +109,8 @@ int spl_load_legacy_img(struct spl_image_info *spl_image,

Quoted 8 lines
Quoted 5 lines

????????? return -EINVAL;
????? }
? +??? /* Flush cache of loaded U-Boot image */
+??? flush_cache((unsigned long)spl_image->load_addr, spl_image->size); +

I failed to find the mail, but haven't we discussed moving this cache flush to your arch before starting a binary?

I don't remember such an agreement. But I don't object in general.

Quoted 2 lines

I cannot see this being required or implemented for non-legacy images, and it still seems wrong here.

Its pretty common when an OS image is loaded and booted, that the cache is flushed before running code from it.

Quoted 6 lines

But I can rework this to add some empty weak function (I don't see an easy better way) to do this platform specific image handling before its booted. Or do you have a better idea on how to handle this?

Thanks,
Stefan

actually all MIPS platforms with non-coherent cache need that flush before jumping to another U-Boot or OS. Thus currently random crashes can occur on all MIPS boards with generic SPL not just mtmips.

But jump_to_image_no_args() in spl.c is already declared as weak, so we should implement that unconditionally for MIPS similar to your patch for do_go_exec(). It would be great if you could prepare a patch to replace this one, thanks.

Signature · 1 line
- Daniel
#29 lore raw

PATCH v6 22/26 spl: spl_legacy: Add cache flush after reading U-Boot image

Quoted 59 lines · Daniel Schwierzeck

Am 09.04.20 um 09:43 schrieb Stefan Roese:

Quoted 49 lines · Simon Goldschmidt
Quoted 31 lines

Am 08.04.2020 um 10:09 schrieb Stefan Roese:

Quoted 30 lines

From: Weijie Gao <[email protected]>

Flush the cache after reading of the U-Boot proper into SDRAM so that it can be started.

This is needed on some platforms, e.g. MT76x8.

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

---
Changes in v6:
- New patch

 ? common/spl/spl_legacy.c | 4 ++++

? 1 file changed, 4 insertions(+)

common/spl/spl_legacy.c +1 -0
index 2cd2a74a4c..e320206098 100644
@@ -4,6 +4,7 @@
 ?? */
 ? ? #include <common.h>
+#include <cpu_func.h>
 ? #include <malloc.h>
 ? #include <spl.h>
 ? @@ -108,5 +109,8 @@ int spl_load_legacy_img(struct spl_image_info
 *spl_image,
Quoted 8 lines
Quoted 5 lines

????????? return -EINVAL;
????? }
? +??? /* Flush cache of loaded U-Boot image */
+??? flush_cache((unsigned long)spl_image->load_addr, spl_image->size); +

I failed to find the mail, but haven't we discussed moving this cache flush to your arch before starting a binary?

I don't remember such an agreement. But I don't object in general.

Quoted 2 lines

I cannot see this being required or implemented for non-legacy images, and it still seems wrong here.

Its pretty common when an OS image is loaded and booted, that the cache is flushed before running code from it.

Quoted 6 lines

But I can rework this to add some empty weak function (I don't see an easy better way) to do this platform specific image handling before its booted. Or do you have a better idea on how to handle this?

Thanks,
Stefan

Quoted 8 lines

actually all MIPS platforms with non-coherent cache need that flush before jumping to another U-Boot or OS. Thus currently random crashes can occur on all MIPS boards with generic SPL not just mtmips.

But jump_to_image_no_args() in spl.c is already declared as weak, so we should implement that unconditionally for MIPS similar to your patch for do_go_exec(). It would be great if you could prepare a patch to replace this one, thanks.

Sure, good idea. I'll drop this patch and will add the cache flush to the newly created MIPS specfic version of jump_to_image_no_args().

Thanks,
Stefan

#30 lore raw

PATCH v6 22/26 spl: spl_legacy: Add cache flush after reading U-Boot image

In reply to Stefan Roese

Am 09.04.2020 um 09:43 schrieb Stefan Roese:

Quoted 36 lines · Simon Goldschmidt
Quoted 35 lines

Am 08.04.2020 um 10:09 schrieb Stefan Roese:

Quoted 34 lines

From: Weijie Gao <[email protected]>

Flush the cache after reading of the U-Boot proper into SDRAM so that it can be started.

This is needed on some platforms, e.g. MT76x8.

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

---
Changes in v6:
- New patch

  common/spl/spl_legacy.c | 4 ++++
  1 file changed, 4 insertions(+)
common/spl/spl_legacy.c +1 -0
index 2cd2a74a4c..e320206098 100644
@@ -4,6 +4,7 @@
   */
 
  #include <common.h>
+#include <cpu_func.h>
  #include <malloc.h>
  #include <spl.h>
 
@@ -108,5 +109,8 @@ int spl_load_legacy_img(struct spl_image_info *spl_image,
  		return -EINVAL;
  	}
 
Quoted 8 lines
Quoted 6 lines

common/spl/spl_legacy.c int spl_load_legacy_img(struct spl_image_info *spl_image, · line 114

Quoted 3 lines
common/spl/spl_legacy.c +3 -0
+	/* Flush cache of loaded U-Boot image */
+	flush_cache((unsigned long)spl_image->load_addr, spl_image->size);
+

I failed to find the mail, but haven't we discussed moving this cache flush to your arch before starting a binary?

I don't remember such an agreement. But I don't object in general.

Ok, maybe I remember wrong then.

Quoted 6 lines
Quoted 3 lines

I cannot see this being required or implemented for non-legacy images, and it still seems wrong here.

Its pretty common when an OS image is loaded and booted, that the cache is flushed before running code from it.

Yes, of course. I can follow you there. I'm just curious why it's added here and only for legacy images.

Quoted 4 lines

But I can rework this to add some empty weak function (I don't see an easy better way) to do this platform specific image handling before its booted. Or do you have a better idea on how to handle this?

I don't know. And I'm not totally opposed to this patch. I just think it's a strange thing to do here. If you need it, I think it should be in a more central place. Surely, you'd need it for non-legacy images, too?

I could imagine this being added to jump_to_image_no_args(). That way, we would have the cache flush in a central place instead of stumbling accross it again in the future (e.g. for non-legacy images). OTOH, I'm not sure that would be free of side-effects...?

Regards,
Simon

Quoted 4 lines

Thanks,
Stefan

#31 lore raw

PATCH v6 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 9e01b70e4b..a703176353 100644
@@ -898,6 +898,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.0
#32 lore raw

PATCH v6 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.0
#33 lore raw

PATCH v6 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.0
#34 lore raw

PATCH v6 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.

---
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.0