Skip to contentSkip to conversation

nios2: add device tree control of U-Boot

PATCH Superseded Thomas Chou 4 participants 79 messages Sep 4, 2015 – Sep 9, 2015 NIOS2 architecture

lore
Share & tools
lore
#0 lore raw

cover nios2: add device tree control of U-Boot

These patches add device tree control of U-Boot to nios2 boards.

In case of separated device tree blob, the blob is relocated from the end of u-boot-dtb.bin image.

Thomas Chou (5):
nios2: permit device tree control of U-Boot
nios2: enable device tree control of U-Boot
nios2: revert _end symbol in link script
nios2: initialize stack earlier in startup
nios2: relocate dtb for separated device tree

 arch/Kconfig                       |   1 +
 arch/nios2/cpu/fdt.c               |  20 ++++-
 arch/nios2/cpu/start.S             |  55 +++++++------
 arch/nios2/cpu/u-boot.lds          |  16 +++-
 arch/nios2/dts/.gitignore          |   1 +
 arch/nios2/dts/3c120_devboard.dts  | 164 +++++++++++++++++++++++++++++++++++++
 arch/nios2/dts/Makefile            |  11 +++
 arch/nios2/dts/include/dt-bindings |   1 +
 configs/nios2-generic_defconfig    |   2 +
 9 files changed, 244 insertions(+), 27 deletions(-)
 create mode 100644 arch/nios2/dts/.gitignore
 create mode 100644 arch/nios2/dts/3c120_devboard.dts
 create mode 100644 arch/nios2/dts/Makefile
 create mode 120000 arch/nios2/dts/include/dt-bindings
Signature · 1 line
2.1.4
#1 lore raw

PATCH 1/5 nios2: permit device tree control of U-Boot

Enable this in the Kconfig so that nios2 boards can use device tree to configure U-Boot.

---
 arch/Kconfig | 1 +
 1 file changed, 1 insertion(+)
arch/Kconfig +1 -0
index 4f73819..207c778 100644
@@ -63,6 +63,7 @@ config NIOS2
 	bool "Nios II architecture"
 	select HAVE_GENERIC_BOARD
 	select SYS_GENERIC_BOARD
+	select SUPPORT_OF_CONTROL
 
 config OPENRISC
 	bool "OpenRISC architecture"
Signature · 1 line
2.1.4
#3 lore raw

PATCH 2/5 nios2: enable device tree control of U-Boot

In reply to Thomas Chou

This patch adds device tree control of U-Boot to nios2 boards. The example dts is taken from Linux kernel.

---
 arch/nios2/dts/.gitignore          |   1 +
 arch/nios2/dts/3c120_devboard.dts  | 164 +++++++++++++++++++++++++++++++++++++
 arch/nios2/dts/Makefile            |  11 +++
 arch/nios2/dts/include/dt-bindings |   1 +
 configs/nios2-generic_defconfig    |   2 +
 5 files changed, 179 insertions(+)
 create mode 100644 arch/nios2/dts/.gitignore
 create mode 100644 arch/nios2/dts/3c120_devboard.dts
 create mode 100644 arch/nios2/dts/Makefile
 create mode 120000 arch/nios2/dts/include/dt-bindings
arch/nios2/dts/.gitignore new file +1 -0
new file mode 100644
index 0000000..b60ed20
@@ -0,0 +1 @@
+*.dtb
arch/nios2/dts/3c120_devboard.dts new file +164 -0

164 lines not on this page · raw message

arch/nios2/dts/Makefile new file +11 -0
new file mode 100644
index 0000000..b2175a1
@@ -0,0 +1,11 @@
+dtb-y += 3c120_devboard.dtb
+
+targets += $(dtb-y)
+
+DTC_FLAGS += -R 4 -p 0x1000
+
+PHONY += dtbs
+dtbs: $(addprefix $(obj)/, $(dtb-y))
+	@:
+
+clean-files := *.dtb
arch/nios2/dts/include/dt-bindings new file +1 -0
new file mode 120000
index 0000000..0cecb3d
@@ -0,0 +1 @@
+../../../../include/dt-bindings
\ No newline at end of file
configs/nios2-generic_defconfig +2 -0
index f8d2821..09cc51e 100644
@@ -1,5 +1,6 @@
 CONFIG_NIOS2=y
 CONFIG_TARGET_NIOS2_GENERIC=y
+CONFIG_DEFAULT_DEVICE_TREE="3c120_devboard"
 CONFIG_HUSH_PARSER=y
 # CONFIG_CMD_BOOTD is not set
 # CONFIG_CMD_IMLS is not set
@@ -10,4 +11,5 @@ CONFIG_HUSH_PARSER=y
 CONFIG_CMD_DHCP=y
 # CONFIG_CMD_NFS is not set
 CONFIG_CMD_PING=y
+CONFIG_OF_CONTROL=y
 CONFIG_NET_RANDOM_ETHADDR=y
Signature · 1 line
2.1.4
#4 lore raw

PATCH 2/5 nios2: enable device tree control of U-Boot

Hi Thomas,

Quoted 4 lines · Thomas Chou

This patch adds device tree control of U-Boot to nios2 boards. The example dts is taken from Linux kernel.

Quoted 12 lines
---
 arch/nios2/dts/.gitignore          |   1 +
 arch/nios2/dts/3c120_devboard.dts  | 164 +++++++++++++++++++++++++++++++++++++
 arch/nios2/dts/Makefile            |  11 +++
 arch/nios2/dts/include/dt-bindings |   1 +
 configs/nios2-generic_defconfig    |   2 +
 5 files changed, 179 insertions(+)
 create mode 100644 arch/nios2/dts/.gitignore
 create mode 100644 arch/nios2/dts/3c120_devboard.dts
 create mode 100644 arch/nios2/dts/Makefile
 create mode 120000 arch/nios2/dts/include/dt-bindings

But I think the license header should use SPDX.

Quoted 40 lines
arch/nios2/dts/.gitignore new file +1 -0
new file mode 100644
index 0000000..b60ed20
@@ -0,0 +1 @@
+*.dtb
arch/nios2/dts/3c120_devboard.dts new file +27 -0
new file mode 100644
index 0000000..31c51f9
@@ -0,0 +1,164 @@
+/*
+ *  Copyright (C) 2013 Altera Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * This file is generated by sopc2dts.
+ */
+
+/dts-v1/;
+
+/ {
+       model = "altr,qsys_ghrd_3c120";
+       compatible = "altr,qsys_ghrd_3c120";
+       #address-cells = <1>;
+       #size-cells = <1>;
+

[snip]

arch/nios2/dts/Makefile line 5

Quoted 11 lines
arch/nios2/dts/Makefile new file +5 -0
new file mode 100644
index 0000000..b2175a1
@@ -0,0 +1,11 @@
+dtb-y += 3c120_devboard.dtb
+
+targets += $(dtb-y)
+
+DTC_FLAGS += -R 4 -p 0x1000

You can drop the -p 0x1000 part. It isn't needed.

Quoted 32 lines
arch/nios2/dts/Makefile new file +6 -0
+
+PHONY += dtbs
+dtbs: $(addprefix $(obj)/, $(dtb-y))
+       @:
+
+clean-files := *.dtb
arch/nios2/dts/include/dt-bindings new file +1 -0
new file mode 120000
index 0000000..0cecb3d
@@ -0,0 +1 @@
+../../../../include/dt-bindings
\ No newline at end of file
configs/nios2-generic_defconfig +2 -1
index f8d2821..09cc51e 100644
@@ -1,5 +1,6 @@
 CONFIG_NIOS2=y
 CONFIG_TARGET_NIOS2_GENERIC=y
+CONFIG_DEFAULT_DEVICE_TREE="3c120_devboard"
 CONFIG_HUSH_PARSER=y
 # CONFIG_CMD_BOOTD is not set
 # CONFIG_CMD_IMLS is not set
@@ -10,4 +11,5 @@ CONFIG_HUSH_PARSER=y
 CONFIG_CMD_DHCP=y
 # CONFIG_CMD_NFS is not set
 CONFIG_CMD_PING=y
+CONFIG_OF_CONTROL=y
 CONFIG_NET_RANDOM_ETHADDR=y
--
Quoted 2 lines

2.1.4

Regards,
Simon

#5 lore raw

PATCH 3/5 nios2: revert _end symbol in link script

In reply to Thomas Chou

Since commit 44c6e6591cb451ae606f8bde71dd5fb7b4002544 "rename _end to __bss_end__" , the _end was removed. But we need it now for separated device tree control, ie, CONFIG_OF_SEPARATE .

Though _end used to be the end of u-boot.bin image, we mark it up and relocate the dtb part of u-boot-dtb.bin here to be used by fdtdec_setup().

---
 arch/nios2/cpu/u-boot.lds | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
arch/nios2/cpu/u-boot.lds +13 -3
index 6e174be..2d43602 100644
@@ -50,9 +50,10 @@ SECTIONS
 	  *(.gnu.linkonce.d*)
 	}
 
-	. = ALIGN(16);
-	_gp = .;			/* Global pointer addr */
-	PROVIDE (gp = .);
+	/* gp - Since we don't use gp for small data with option "-G0",
+	 * we will use gp as global data pointer. The _gp location is
+	 * not needed.
+	 */
 
 	.sdata :
 	{
@@ -62,6 +63,9 @@ SECTIONS
 	}
 	. = ALIGN(4);
 
+	/* _edata - This is end of u-boot.bin image.
+	 * dtb will be appended here to make u-boot-dtb.bin
+         */
 	_edata = .;
 	PROVIDE (edata = .);
 
@@ -88,6 +92,12 @@ SECTIONS
 	}
 	. = ALIGN(4);
 	__bss_end = .;
+
+	/* _end - Though _end used to be the end of u-boot.bin image,
+	 * we mark it up and relocate the dtb part of u-boot-dtb.bin here
+	 * to be used by fdtdec_setup().
+	 */
+	_end = .;
 	PROVIDE (end = .);
 
 	/* DEBUG -- symbol table, string table, etc. etc.
Signature · 1 line
2.1.4
#6 lore raw

PATCH 3/5 nios2: revert _end symbol in link script

Quoted 5 lines · Thomas Chou

Since commit 44c6e6591cb451ae606f8bde71dd5fb7b4002544 "rename _end to __bss_end__" , the _end was removed. But we need it now for separated device tree control, ie, CONFIG_OF_SEPARATE .

Quoted 8 lines

Though _end used to be the end of u-boot.bin image, we mark it up and relocate the dtb part of u-boot-dtb.bin here to be used by fdtdec_setup().

---
 arch/nios2/cpu/u-boot.lds | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
#7 lore raw

PATCH 4/5 nios2: initialize stack earlier in startup

In reply to Thomas Chou

This patch reorders the startup sequence, and initializes stack earlier. So that we can call external functions after stack initialized.

We will add OF control and use separated dtb. As dtb is located at the end of u-boot-dtb.bin image, we will need to relocate it before zeroing the bss. It will be easier to handle fdt in C than ASM.

---
 arch/nios2/cpu/start.S | 45 ++++++++++++++++++++++-----------------------
 1 file changed, 22 insertions(+), 23 deletions(-)
arch/nios2/cpu/start.S +22 -23
index 6af9b4e..dde80f7 100644
@@ -68,7 +68,7 @@ _except_end:
 _cur:	movhi	r5, %hi(_cur - _start)
 	ori	r5, r5, %lo(_cur - _start)
 	sub	r4, r4, r5		/* r4 <- cur _start */
-	mov	r8, r4
+	mov	r8, r4			/* r8 <- cur _start */
 	movhi	r5, %hi(_start)
 	ori	r5, r5, %lo(_start)	/* r5 <- linked _start */
 	beq	r4, r5, 3f
@@ -82,26 +82,34 @@ _cur:	movhi	r5, %hi(_cur - _start)
 	bne	r5, r6, 2b
 3:
 
+	/* JUMP TO RELOC ADDR */
+	movhi	r4, %hi(_reloc)
+	ori	r4, r4, %lo(_reloc)
+	jmp	r4
+_reloc:
+
+	/* STACK INIT -- zero top two words for call back chain. */
+	movhi	sp, %hi(CONFIG_SYS_INIT_SP)
+	ori	sp, sp, %lo(CONFIG_SYS_INIT_SP)
+	addi	sp, sp, -8
+	stw	r0, 0(sp)
+	stw	r0, 4(sp)
+	mov	fp, sp
+
 	/* ZERO BSS/SBSS -- bss and sbss are assumed to be adjacent
 	 * and between __bss_start and __bss_end.
 	 */
-	 movhi	r5, %hi(__bss_start)
-	 ori	r5, r5, %lo(__bss_start)
-	 movhi	r6, %hi(__bss_end)
-	 ori	r6, r6, %lo(__bss_end)
-	 beq	r5, r6, 5f
+	movhi	r5, %hi(__bss_start)
+	ori	r5, r5, %lo(__bss_start)
+	movhi	r6, %hi(__bss_end)
+	ori	r6, r6, %lo(__bss_end)
+	beq	r5, r6, 5f
 
 4:	stwio	r0, 0(r5)
-	 addi	r5, r5, 4
-	 bne	r5, r6, 4b
+	addi	r5, r5, 4
+	bne	r5, r6, 4b
 5:
 
-	/* JUMP TO RELOC ADDR */
-	movhi	r4, %hi(_reloc)
-	ori	r4, r4, %lo(_reloc)
-	jmp	r4
-_reloc:
-
 	/* COPY EXCEPTION TRAMPOLINE -- copy the tramp to the
 	 * exception address. Define CONFIG_ROM_STUBS to prevent
 	 * the copy (e.g. exception in flash or in other
@@ -124,15 +132,6 @@ _reloc:
 7:
 #endif
 
-	/* STACK INIT -- zero top two words for call back chain.
-	 */
-	movhi	sp, %hi(CONFIG_SYS_INIT_SP)
-	ori	sp, sp, %lo(CONFIG_SYS_INIT_SP)
-	addi	sp, sp, -8
-	stw	r0, 0(sp)
-	stw	r0, 4(sp)
-	mov	fp, sp
-
 	/*
 	 * Call board_init_f -- never returns
 	 */
Signature · 1 line
2.1.4
#8 lore raw

PATCH 4/5 nios2: initialize stack earlier in startup

Hi Thomas,

Quoted 4 lines · Thomas Chou

This patch reorders the startup sequence, and initializes stack earlier. So that we can call external functions after stack initialized.

Quoted 8 lines

We will add OF control and use separated dtb. As dtb is located at the end of u-boot-dtb.bin image, we will need to relocate it before zeroing the bss. It will be easier to handle fdt in C than ASM.

---
 arch/nios2/cpu/start.S | 45 ++++++++++++++++++++++-----------------------
 1 file changed, 22 insertions(+), 23 deletions(-)

Instead, is it possible to move to calling board_init_f_mem()?

Regards,
Simon

#9 lore raw

PATCH 5/5 nios2: relocate dtb for separated device tree

In reply to Thomas Chou

The relocation of nios2 is different. We will need to move dtb at the end of u-boot-dtb.bin image away from BSS sections. Otherwise it will be zeroed during startup.

---
 arch/nios2/cpu/fdt.c   | 20 +++++++++++++++++++-
 arch/nios2/cpu/start.S | 10 ++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)
arch/nios2/cpu/fdt.c +19 -1
index 79f72aa..83d95ba 100644
@@ -11,9 +11,11 @@
  */
 
 #include <common.h>
+#include <libfdt.h>
+#include <asm/sections.h>
+#include <linux/ctype.h>
 
 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
-#include <libfdt.h>
 #include <fdt_support.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -36,3 +38,19 @@ void ft_cpu_setup(void *blob, bd_t *bd)
 	fdt_fixup_ethernet(blob);
 }
 #endif /* CONFIG_OF_LIBFDT && CONFIG_OF_BOARD_SETUP */
+
+#ifdef CONFIG_OF_SEPARATE
+void relocate_dtb(ulong cur_start)
+{
+	/* This will be called from start.S .
+	 * As dtb is located at the end of u-boot-dtb.bin image,
+	 * we will need to relocate it before zeroing the bss.
+	 * The dtb is moved from _edata to _end, which is markuped
+	 * to __bss_end. Here _end will be used by fdtdec_setup().
+	 */
+	void *blob = (void *)(cur_start + (ulong)_edata - (ulong)_start);
+
+	if (fdt_magic(blob) == FDT_MAGIC)
+		memmove(_end, blob, fdt_totalsize(blob));
+}
+#endif /* CONFIG_OF_SEPARATE */
arch/nios2/cpu/start.S +10 -0
index dde80f7..58e6826 100644
@@ -96,6 +96,16 @@ _reloc:
 	stw	r0, 4(sp)
 	mov	fp, sp
 
+#ifdef CONFIG_OF_SEPARATE
+	/* RELOCATE DTB -- relocate dtb in u-boot-dtb.bin image
+	 * to be used by fdtdec_setup().
+	 */
+	mov	r4, r8			/* r8 <- cur _start */
+	movhi	r2, %hi(relocate_dtb at h)
+	ori	r2, r2, %lo(relocate_dtb@h)
+	callr	r2
+#endif
+
 	/* ZERO BSS/SBSS -- bss and sbss are assumed to be adjacent
 	 * and between __bss_start and __bss_end.
 	 */
Signature · 1 line
2.1.4
#10 lore raw

PATCH 5/5 nios2: relocate dtb for separated device tree

+Marek

Hi Thomas,

Quoted 9 lines · Thomas Chou

The relocation of nios2 is different. We will need to move dtb at the end of u-boot-dtb.bin image away from BSS sections. Otherwise it will be zeroed during startup.

---
 arch/nios2/cpu/fdt.c   | 20 +++++++++++++++++++-
 arch/nios2/cpu/start.S | 10 ++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)

Can you help me understand the relocation a bit? There is already code in board_init_f() to relocate the device tree, and until board_init_r(), BSS should not be used. What is different about NIOS?

Quoted 60 lines
arch/nios2/cpu/fdt.c +19 -1
index 79f72aa..83d95ba 100644
@@ -11,9 +11,11 @@
  */
 
 #include <common.h>
+#include <libfdt.h>
+#include <asm/sections.h>
+#include <linux/ctype.h>
 
 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
-#include <libfdt.h>
 #include <fdt_support.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -36,3 +38,19 @@ void ft_cpu_setup(void *blob, bd_t *bd)
        fdt_fixup_ethernet(blob);
 }
 #endif /* CONFIG_OF_LIBFDT && CONFIG_OF_BOARD_SETUP */
+
+#ifdef CONFIG_OF_SEPARATE
+void relocate_dtb(ulong cur_start)
+{
+       /* This will be called from start.S .
+        * As dtb is located at the end of u-boot-dtb.bin image,
+        * we will need to relocate it before zeroing the bss.
+        * The dtb is moved from _edata to _end, which is markuped
+        * to __bss_end. Here _end will be used by fdtdec_setup().
+        */
+       void *blob = (void *)(cur_start + (ulong)_edata - (ulong)_start);
+
+       if (fdt_magic(blob) == FDT_MAGIC)
+               memmove(_end, blob, fdt_totalsize(blob));
+}
+#endif /* CONFIG_OF_SEPARATE */
arch/nios2/cpu/start.S +10 -1
index dde80f7..58e6826 100644
@@ -96,6 +96,16 @@ _reloc:
        stw     r0, 4(sp)
        mov     fp, sp
 
+#ifdef CONFIG_OF_SEPARATE
+       /* RELOCATE DTB -- relocate dtb in u-boot-dtb.bin image
+        * to be used by fdtdec_setup().
+        */
+       mov     r4, r8                  /* r8 <- cur _start */
+       movhi   r2, %hi(relocate_dtb at h)
+       ori     r2, r2, %lo(relocate_dtb at h)
+       callr   r2
+#endif
+
        /* ZERO BSS/SBSS -- bss and sbss are assumed to be adjacent
         * and between __bss_start and __bss_end.
         */
--
Quoted 2 lines

2.1.4

Regards,
Simon

#11 lore raw

PATCH 5/5 nios2: relocate dtb for separated device tree

Hi Simon,

Quoted 3 lines · Simon Glass

Can you help me understand the relocation a bit? There is already code in board_init_f() to relocate the device tree, and until board_init_r(), BSS should not be used. What is different about NIOS?

Thank you for the comment. I think the problem is in the current nios2 startup code start.S. The BSS is cleared before board_init_f(). I will rework the startup code to make use of the board_init code.

Best regards,
Thomas Chou

#12 lore raw

v2 cover nios2: add device tree control of U-Boot

In reply to Thomas Chou

These patches add device tree control of U-Boot to nios2 boards.

v2
use SPDX license header.
use fdt relocation in board_init_f.

Thomas Chou (8):
nios2: permit device tree control of U-Boot
nios2: move altera_pio_init to board_early_init_r
nios2: BSS should be cleared only after board_init_f
nios2: enlarge the code relocation range
nios2: remove gp assignments in link script
nios2: define _end in link script
nios2: show fdt blob address in board info command
nios2: enable device tree control of U-Boot

 arch/Kconfig                               |   1 +
 arch/nios2/cpu/start.S                     |  34 ++++---
 arch/nios2/cpu/u-boot.lds                  |  12 ++-
 arch/nios2/dts/.gitignore                  |   1 +
 arch/nios2/dts/3c120_devboard.dts          | 153 +++++++++++++++++++++++++++++
 arch/nios2/dts/Makefile                    |  11 +++
 arch/nios2/dts/include/dt-bindings         |   1 +
 board/altera/nios2-generic/nios2-generic.c |  13 ++-
 common/cmd_bdinfo.c                        |   3 +
 configs/nios2-generic_defconfig            |   2 +
 include/configs/nios2-generic.h            |   1 +
 11 files changed, 209 insertions(+), 23 deletions(-)
 create mode 100644 arch/nios2/dts/.gitignore
 create mode 100644 arch/nios2/dts/3c120_devboard.dts
 create mode 100644 arch/nios2/dts/Makefile
 create mode 120000 arch/nios2/dts/include/dt-bindings
Signature · 1 line
2.1.4
#13 lore raw

PATCH v2 1/8 nios2: permit device tree control of U-Boot

Enable this in the Kconfig so that nios2 boards can use device tree to configure U-Boot.

---
 arch/Kconfig | 1 +
 1 file changed, 1 insertion(+)
arch/Kconfig +1 -0
index 4f73819..207c778 100644
@@ -63,6 +63,7 @@ config NIOS2
 	bool "Nios II architecture"
 	select HAVE_GENERIC_BOARD
 	select SYS_GENERIC_BOARD
+	select SUPPORT_OF_CONTROL
 
 config OPENRISC
 	bool "OpenRISC architecture"
Signature · 1 line
2.1.4
#15 lore raw

PATCH v2 2/8 nios2: move altera_pio_init to board_early_init_r

In reply to Thomas Chou

As altera_pio_init() uses BSS, it should be moved to board_early_init_r().

---
 board/altera/nios2-generic/nios2-generic.c | 13 +++++++++----
 include/configs/nios2-generic.h            |  1 +
 2 files changed, 10 insertions(+), 4 deletions(-)
board/altera/nios2-generic/nios2-generic.c +9 -4
index 834cbeb..384fee9 100644
@@ -28,6 +28,15 @@ void early_flash_cmd_reset(void)
 
 int board_early_init_f(void)
 {
+#if defined(CONFIG_ENV_IS_IN_FLASH) && defined(CONFIG_ENV_ADDR) && \
+    defined(CONFIG_CFI_FLASH_MTD)
+	early_flash_cmd_reset();
+#endif
+	return 0;
+}
+
+int board_early_init_r(void)
+{
 #ifdef CONFIG_ALTERA_PIO
 #ifdef LED_PIO_BASE
 	altera_pio_init(LED_PIO_BASE, LED_PIO_WIDTH, 'o',
@@ -35,10 +44,6 @@ int board_early_init_f(void)
 			"led");
 #endif
 #endif
-#if defined(CONFIG_ENV_IS_IN_FLASH) && defined(CONFIG_ENV_ADDR) && \
-    defined(CONFIG_CFI_FLASH_MTD)
-	early_flash_cmd_reset();
-#endif
 	return 0;
 }
 
include/configs/nios2-generic.h +1 -0
index 5bb7768..293acae 100644
@@ -15,6 +15,7 @@
 #include "../board/altera/nios2-generic/custom_fpga.h" /* fpga parameters */
 #define CONFIG_BOARD_NAME "nios2-generic" /* custom board name */
 #define CONFIG_BOARD_EARLY_INIT_F	/* enable early board-spec. init */
+#define CONFIG_BOARD_EARLY_INIT_R
 #define CONFIG_DISPLAY_CPUINFO
 #define CONFIG_DISPLAY_BOARDINFO
 #define CONFIG_SYS_NIOS_SYSID_BASE	CONFIG_SYS_SYSID_BASE
Signature · 1 line
2.1.4
#16 lore raw

PATCH v2 2/8 nios2: move altera_pio_init to board_early_init_r

Quoted 4 lines · Thomas Chou

As altera_pio_init() uses BSS, it should be moved to board_early_init_r().

Shouldn't this be part of arch_cpu_init() instead ?

Best regards,
Marek Vasut

#17 lore raw

PATCH v2 2/8 nios2: move altera_pio_init to board_early_init_r

Hi Marek,

Quoted 7 lines · Marek Vasut
Quoted 4 lines · Thomas Chou

As altera_pio_init() uses BSS, it should be moved to board_early_init_r().

Shouldn't this be part of arch_cpu_init() instead ?

This is per board setup. Each board might has a different PIO configuration.

Regards,
Thomas Chou

#18 lore raw

PATCH v2 2/8 nios2: move altera_pio_init to board_early_init_r

Quoted 7 lines · Thomas Chou

Hi Marek,

Quoted 4 lines · Marek Vasut
Quoted 3 lines · Thomas Chou

As altera_pio_init() uses BSS, it should be moved to board_early_init_r().

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Shouldn't this be part of arch_cpu_init() instead ?

This is per board setup. Each board might has a different PIO configuration.

OK, I see what you're doing here now. I agree.

Best regards,
Marek Vasut

#19 lore raw

PATCH v2 3/8 nios2: BSS should be cleared only after board_init_f

In reply to Thomas Chou

As dtb in u-boot-dtb.bin overlapped the BSS section, we should delay the clearing of BSS until dtb is relocated in board_init_f().

---
 arch/nios2/cpu/start.S | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)
arch/nios2/cpu/start.S +15 -14
index 6af9b4e..971bde8 100644
@@ -82,20 +82,6 @@ _cur:	movhi	r5, %hi(_cur - _start)
 	bne	r5, r6, 2b
 3:
 
-	/* ZERO BSS/SBSS -- bss and sbss are assumed to be adjacent
-	 * and between __bss_start and __bss_end.
-	 */
-	 movhi	r5, %hi(__bss_start)
-	 ori	r5, r5, %lo(__bss_start)
-	 movhi	r6, %hi(__bss_end)
-	 ori	r6, r6, %lo(__bss_end)
-	 beq	r5, r6, 5f
-
-4:	stwio	r0, 0(r5)
-	 addi	r5, r5, 4
-	 bne	r5, r6, 4b
-5:
-
 	/* JUMP TO RELOC ADDR */
 	movhi	r4, %hi(_reloc)
 	ori	r4, r4, %lo(_reloc)
@@ -167,6 +153,21 @@ _reloc:
 relocate_code:
 	mov	sp, r4		/* Set the new sp */
 	mov	r4, r5
+
+	/* ZERO BSS/SBSS -- bss and sbss are assumed to be adjacent
+	 * and between __bss_start and __bss_end.
+	 */
+	movhi	r5, %hi(__bss_start)
+	ori	r5, r5, %lo(__bss_start)
+	movhi	r6, %hi(__bss_end)
+	ori	r6, r6, %lo(__bss_end)
+	beq	r5, r6, 5f
+
+4:	stwio	r0, 0(r5)
+	addi	r5, r5, 4
+	bne	r5, r6, 4b
+5:
+
 	movhi	r8, %hi(board_init_r at h)
 	ori	r8, r8, %lo(board_init_r at h)
 	callr	r8
Signature · 1 line
2.1.4
#21 lore raw

PATCH v2 4/8 nios2: enlarge the code relocation range

In reply to Thomas Chou

As we will use u-boot-dtb.bin, the code relocation range should be adjusted to accommodate the additional dtb. It might be overkilled to look into dtb header to find the dtb size, so we will simply use CONFIG_SYS_MONITOR_LEN.

---
 arch/nios2/cpu/start.S | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/nios2/cpu/start.S +3 -2
index 971bde8..0b16633 100644
@@ -73,8 +73,9 @@ _cur:	movhi	r5, %hi(_cur - _start)
 	ori	r5, r5, %lo(_start)	/* r5 <- linked _start */
 	beq	r4, r5, 3f
 
-	movhi	r6, %hi(_edata)
-	ori	r6, r6, %lo(_edata)
+	movhi	r6, %hi(CONFIG_SYS_MONITOR_LEN)
+	ori	r6, r6, %lo(CONFIG_SYS_MONITOR_LEN)
+	add	r6, r6, r5
 2:	ldwio	r7, 0(r4)
 	addi	r4, r4, 4
 	stwio	r7, 0(r5)
Signature · 1 line
2.1.4
#22 lore raw

PATCH v2 4/8 nios2: enlarge the code relocation range

Quoted 16 lines · Thomas Chou

As we will use u-boot-dtb.bin, the code relocation range should be adjusted to accommodate the additional dtb. It might be overkilled to look into dtb header to find the dtb size, so we will simply use CONFIG_SYS_MONITOR_LEN.

---
 arch/nios2/cpu/start.S | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/nios2/cpu/start.S +0 -0
index 971bde8..0b16633 100644
@@ -73,8 +73,9 @@ _cur:	movhi	r5, %hi(_cur - _start)
 	ori	r5, r5, %lo(_start)	/* r5 <- linked _start */

arch/nios2/cpu/start.S _cur: movhi r5, %hi(_cur - _start) · line 81

Quoted 10 lines
arch/nios2/cpu/start.S +3 -2
 	beq	r4, r5, 3f
 
-	movhi	r6, %hi(_edata)
-	ori	r6, r6, %lo(_edata)
+	movhi	r6, %hi(CONFIG_SYS_MONITOR_LEN)
+	ori	r6, r6, %lo(CONFIG_SYS_MONITOR_LEN)
+	add	r6, r6, r5
 2:	ldwio	r7, 0(r4)
 	addi	r4, r4, 4
 	stwio	r7, 0(r5)

Can't you just call relocate_code the same way arm does it in arch/arm/lib/crt0.S ?

Best regards,
Marek Vasut

#23 lore raw

PATCH v2 4/8 nios2: enlarge the code relocation range

Hi Marek,

Quoted 2 lines · Marek Vasut

Can't you just call relocate_code the same way arm does it in arch/arm/lib/crt0.S ?

We didn't include relocation records in nios2 binary image, so there is no real relocation like that of ARM.

Altera provides small boot loaders for cfi/sf along with their nios2 jtag flash programmer, which will load the image to the linked address in sdram. The relocating loop in start.S works only if such Altera boot loader is not used, ie, booting directly from cfi flash.

Best regards,
Thomas Chou

#24 lore raw

PATCH v2 4/8 nios2: enlarge the code relocation range

Quoted 1 line · Thomas Chou

Hi Marek,

Hi,

Quoted 6 lines · Marek Vasut
Quoted 2 lines

Can't you just call relocate_code the same way arm does it in arch/arm/lib/crt0.S ?

We didn't include relocation records in nios2 binary image, so there is no real relocation like that of ARM.

Can we add them instead ?

Quoted 4 lines

Altera provides small boot loaders for cfi/sf along with their nios2 jtag flash programmer, which will load the image to the linked address in sdram. The relocating loop in start.S works only if such Altera boot loader is not used, ie, booting directly from cfi flash.

Hm, Im not using the Altera loader :)

Best regards,
Marek Vasut

#25 lore raw

PATCH v2 4/8 nios2: enlarge the code relocation range

HI Marek,

Quoted 4 lines · Marek Vasut
Quoted 2 lines

We didn't include relocation records in nios2 binary image, so there is no real relocation like that of ARM.

Can we add them instead ?

I think it is possible. I recalled that we have an old flat image format with elf2flt to run nonmmu uclinux, which does a similar relocation. But I would suggest that we should keep thing simple and small in a boot loader like U-Boot.

Quoted 8 lines
Quoted 5 lines

Altera provides small boot loaders for cfi/sf along with their nios2 jtag flash programmer, which will load the image to the linked address in sdram. The relocating loop in start.S works only if such Altera boot loader is not used, ie, booting directly from cfi flash.

Hm, Im not using the Altera loader :)

Neither am I. Look like we all use custom boot copiers, and we don't need the relocation in the patch above. It doesn't make sense to copy the code twice. Right? :)

Best regards
Thomas Chou

#26 lore raw

PATCH v2 4/8 nios2: enlarge the code relocation range

Quoted 1 line · Thomas Chou

HI Marek,

Hi!

Quoted 10 lines · Marek Vasut
Quoted 4 lines
Quoted 2 lines

We didn't include relocation records in nios2 binary image, so there is no real relocation like that of ARM.

Can we add them instead ?

I think it is possible. I recalled that we have an old flat image format with elf2flt to run nonmmu uclinux, which does a similar relocation. But I would suggest that we should keep thing simple and small in a boot loader like U-Boot.

We already do it on ARM though and the reason for this is to place U-Boot at the end of the DRAM, so that most of the DRAM can be used by the user.

Quoted 10 lines
Quoted 6 lines
Quoted 4 lines

Altera provides small boot loaders for cfi/sf along with their nios2 jtag flash programmer, which will load the image to the linked address in sdram. The relocating loop in start.S works only if such Altera boot loader is not used, ie, booting directly from cfi flash.

Hm, Im not using the Altera loader :)

Neither am I. Look like we all use custom boot copiers, and we don't need the relocation in the patch above. It doesn't make sense to copy the code twice. Right? :)

In fact, I am loading U-Boot with GDB thus far, so I am only copying it once ;-) Where is the second copying coming from ?

Best regards,
Marek Vasut

#27 lore raw

PATCH v2 4/8 nios2: enlarge the code relocation range

Hi Marek,

Quoted 2 lines · Marek Vasut

We already do it on ARM though and the reason for this is to place U-Boot at the end of the DRAM, so that most of the DRAM can be used by the user.

We place U-Boot at the end of the DRAM on nios2, too. :)

I will look into the relocation on nios2 next time. But for now, I would suggest that we skip this and move on to driver model.

Quoted 2 lines

In fact, I am loading U-Boot with GDB thus far, so I am only copying it once ;-) Where is the second copying coming from ?

That was true for gdb. But when you need to try out u-boot-dtb.bin on EPCS/sf, it will be another story..

Best regards,
Thomas Chou

#28 lore raw

PATCH v2 4/8 nios2: enlarge the code relocation range

Quoted 1 line · Thomas Chou

Hi Marek,

Hi,

Quoted 8 lines · Marek Vasut
Quoted 2 lines

We already do it on ARM though and the reason for this is to place U-Boot at the end of the DRAM, so that most of the DRAM can be used by the user.

We place U-Boot at the end of the DRAM on nios2, too. :)

I will look into the relocation on nios2 next time. But for now, I would suggest that we skip this and move on to driver model.

These two things are orthogonal, so no problem :)

Quoted 5 lines
Quoted 2 lines

In fact, I am loading U-Boot with GDB thus far, so I am only copying it once ;-) Where is the second copying coming from ?

That was true for gdb. But when you need to try out u-boot-dtb.bin on EPCS/sf, it will be another story..

Why so? The EPCS is memory mapped and U-Boot starts from it, right ? So U-Boot can relocate itself to the end of DRAM , right ?

Best regards,
Marek Vasut

#29 lore raw

PATCH v2 4/8 nios2: enlarge the code relocation range

Hi Marek,

Quoted 2 lines · Marek Vasut

Why so? The EPCS is memory mapped and U-Boot starts from it, right ? So U-Boot can relocate itself to the end of DRAM , right ?

No. EPCS contains a default boot copier which I said earlier.

Please take a look at this,

https://www.altera.com/support/support-resources/design-examples/intellectual-property/embedded/nios-ii/exm-alt-boot-methods.html

Though the default EPCS boot copier works, it is not easy to update u-boot(-dtb).bin image with u-boot sf command. So I used a modified version, which copies the u-boot image from a fixed location on EPCS/sf to the end of DRAM.

Best regards,
Thomas Chou

#30 lore raw

PATCH v2 4/8 nios2: enlarge the code relocation range

Quoted 1 line · Thomas Chou

Hi Marek,

Hi,

Quoted 8 lines · Marek Vasut
Quoted 2 lines

Why so? The EPCS is memory mapped and U-Boot starts from it, right ? So U-Boot can relocate itself to the end of DRAM , right ?

No. EPCS contains a default boot copier which I said earlier.

Please take a look at this,

Quoted 7 lines

https://www.altera.com/support/support-resources/design-examples/intellectu
al-property/embedded/nios-ii/exm-alt-boot-methods.html

Though the default EPCS boot copier works, it is not easy to update u-boot(-dtb).bin image with u-boot sf command. So I used a modified version, which copies the u-boot image from a fixed location on EPCS/sf to the end of DRAM.

Uh oh, is this copying something the U-Boot SPL cannot do for us ?

Sorry, I might be a bit lost in the "official" ways because I'm too used to mainline ;-)

Best regards,
Marek Vasut

#31 lore raw

PATCH v2 4/8 nios2: enlarge the code relocation range

Hi Marek,

Quoted 1 line · Marek Vasut

Uh oh, is this copying something the U-Boot SPL cannot do for us ?

Though U-Boot SPL can do, it will need 64KB onchip memory. While the EPCS controller needs only 512B onchip memory. So we didn't ever consider SPL for nios2.

Best regards,
Thomas Chou

#32 lore raw

PATCH v2 4/8 nios2: enlarge the code relocation range

Quoted 1 line · Thomas Chou

Hi Marek,

Hi!

Quoted 6 lines · Marek Vasut
Quoted 1 line

Uh oh, is this copying something the U-Boot SPL cannot do for us ?

Though U-Boot SPL can do, it will need 64KB onchip memory. While the EPCS controller needs only 512B onchip memory. So we didn't ever consider SPL for nios2.

Where did that 64KB figure come from ? :O

I assume the simple loader is just a copy loop, huh ? And you synthesise a small RAM or ROM into the FPGA and point NIOS to boot from that, right? What about U-Boot TPL, can that cook the loader ? (yes, I'd like to be as independent of the external code as possible).

Best regards,
Marek Vasut

#33 lore raw

PATCH v2 4/8 nios2: enlarge the code relocation range

Hi Marek,

Quoted 1 line · Marek Vasut

Where did that 64KB figure come from ? :O

This is estimated from 41KB of the SPL of socfpga. The code density of nios2 is worse than ARM.

Quoted 2 lines

I assume the simple loader is just a copy loop, huh ? And you synthesise a small RAM or ROM into the FPGA and point NIOS to boot from that, right?

Right. It is hidden from the user in qsys. You will need to dig into the code to find out. The EPCS boot copier is coded in nios2 ASM.

Quoted 2 lines

What about U-Boot TPL, can that cook the loader ? (yes, I'd like to be as independent of the external code as possible).

I'd like to be independent of the external code, too. In the past, I have my own SPI core (now the oc_tiny_spi) to control EPCS, which is actually SPI flash, and my own boot copier with/out decompression.

It is possible to add an TPL support for nios2 EPCS. If someone want to work on it.. :)

Best regards,
Thomas Chou

#34 lore raw

PATCH v2 4/8 nios2: enlarge the code relocation range

Quoted 1 line · Thomas Chou

Hi Marek,

Hi!

Quoted 11 lines · Marek Vasut
Quoted 1 line

Where did that 64KB figure come from ? :O

This is estimated from 41KB of the SPL of socfpga. The code density of nios2 is worse than ARM.

Quoted 2 lines

I assume the simple loader is just a copy loop, huh ? And you synthesise a small RAM or ROM into the FPGA and point NIOS to boot from that, right?

Right. It is hidden from the user in qsys. You will need to dig into the code to find out. The EPCS boot copier is coded in nios2 ASM.

Oh, I see.

Quoted 9 lines
Quoted 2 lines

What about U-Boot TPL, can that cook the loader ? (yes, I'd like to be as independent of the external code as possible).

I'd like to be independent of the external code, too. In the past, I have my own SPI core (now the oc_tiny_spi) to control EPCS, which is actually SPI flash, and my own boot copier with/out decompression.

It is possible to add an TPL support for nios2 EPCS. If someone want to work on it.. :)

I'll keep this in mind, thanks :)

Best regards,
Marek Vasut

#35 lore raw

PATCH v2 5/8 nios2: remove gp assignments in link script

In reply to Thomas Chou

Since we don't use gp for small data with option "-G0", we use gp as global data pointer. The _gp location is not needed.

The ALIGN(16) was for gp only. It is removed, so that we can get correct address of dtb in u-boot-dtb.bin image.

---
 arch/nios2/cpu/u-boot.lds | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
arch/nios2/cpu/u-boot.lds +4 -3
index 6e174be..951785c 100644
@@ -50,9 +50,10 @@ SECTIONS
 	  *(.gnu.linkonce.d*)
 	}
 
-	. = ALIGN(16);
-	_gp = .;			/* Global pointer addr */
-	PROVIDE (gp = .);
+	/* gp - Since we don't use gp for small data with option "-G0",
+	 * we will use gp as global data pointer. The _gp location is
+	 * not needed.
+	 */
 
 	.sdata :
 	{
Signature · 1 line
2.1.4
#36 lore raw

PATCH v2 5/8 nios2: remove gp assignments in link script

Quoted 17 lines · Thomas Chou

Since we don't use gp for small data with option "-G0", we use gp as global data pointer. The _gp location is not needed.

The ALIGN(16) was for gp only. It is removed, so that we can get correct address of dtb in u-boot-dtb.bin image.

---
 arch/nios2/cpu/u-boot.lds | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
arch/nios2/cpu/u-boot.lds +0 -0
index 6e174be..951785c 100644

arch/nios2/cpu/u-boot.lds SECTIONS · line 53

Quoted 7 lines
arch/nios2/cpu/u-boot.lds +1 -3
@@ -50,9 +50,10 @@ SECTIONS
 	  *(.gnu.linkonce.d*)
 	}
 
-	. = ALIGN(16);
-	_gp = .;			/* Global pointer addr */
-	PROVIDE (gp = .);
+	/* gp - Since we don't use gp for small data with option "-G0",

Please make the multiline comment match the kernel coding style:

/*
* foo
* bar
*/

Otherwise

arch/nios2/cpu/u-boot.lds SECTIONS · line 59

Quoted 6 lines
arch/nios2/cpu/u-boot.lds +3 -0
+	 * we will use gp as global data pointer. The _gp location is
+	 * not needed.
+	 */
 
 	.sdata :
 	{

Best regards,
Marek Vasut

#37 lore raw

PATCH v3 5/8 nios2: remove gp assignments in link script

Since we don't use gp for small data with option "-G0", we use gp as global data pointer. The _gp location is not needed.

The ALIGN(16) was for gp only. It is removed, so that we can get correct address of dtb in u-boot-dtb.bin image.

---

v3 comment coding style fix

 arch/nios2/cpu/u-boot.lds | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
arch/nios2/cpu/u-boot.lds +5 -3
index 6e174be..8b0fd1a 100644
@@ -50,9 +50,11 @@ SECTIONS
 	  *(.gnu.linkonce.d*)
 	}
 
-	. = ALIGN(16);
-	_gp = .;			/* Global pointer addr */
-	PROVIDE (gp = .);
+	/*
+	 * gp - Since we don't use gp for small data with option "-G0",
+	 * we will use gp as global data pointer. The _gp location is
+	 * not needed.
+	 */
 
 	.sdata :
 	{
Signature · 1 line
2.1.4
#38 lore raw

PATCH v2 6/8 nios2: define _end in link script

In reply to Thomas Chou

Since commit 44c6e6591cb451ae606f8bde71dd5fb7b4002544 "rename _end to __bss_end__" , the _end was removed. But we need it now for separated device tree control, ie, CONFIG_OF_SEPARATE .

The _end is used by fdtdec_setup() to find the blob.

---
 arch/nios2/cpu/u-boot.lds | 5 +++++
 1 file changed, 5 insertions(+)
arch/nios2/cpu/u-boot.lds +5 -0
index 951785c..535a974 100644
@@ -66,6 +66,11 @@ SECTIONS
 	_edata = .;
 	PROVIDE (edata = .);
 
+	/* _end - This is end of u-boot.bin image.
+	 * dtb will be appended here to make u-boot-dtb.bin
+         */
+	_end = .;
+
 	/* UNINIT DATA - Small uninitialized data is first so it's
 	 * adjacent to sdata and can be referenced via gp. The normal
 	 * bss follows. We keep it adjacent to simplify init code.
Signature · 1 line
2.1.4
#39 lore raw

PATCH v2 6/8 nios2: define _end in link script

Quoted 17 lines · Thomas Chou

Since commit 44c6e6591cb451ae606f8bde71dd5fb7b4002544 "rename _end to __bss_end__" , the _end was removed. But we need it now for separated device tree control, ie, CONFIG_OF_SEPARATE .

The _end is used by fdtdec_setup() to find the blob.

---
 arch/nios2/cpu/u-boot.lds | 5 +++++
 1 file changed, 5 insertions(+)
arch/nios2/cpu/u-boot.lds +0 -0
index 951785c..535a974 100644

arch/nios2/cpu/u-boot.lds SECTIONS · line 72

Quoted 7 lines
arch/nios2/cpu/u-boot.lds +4 -0
@@ -66,6 +66,11 @@ SECTIONS
 	_edata = .;
 	PROVIDE (edata = .);
 
+	/* _end - This is end of u-boot.bin image.
+	 * dtb will be appended here to make u-boot-dtb.bin
+         */
+	_end = .;

Same comment about the comment as in the previous patch, but otherwise:

arch/nios2/cpu/u-boot.lds SECTIONS · line 76

Quoted 3 lines
arch/nios2/cpu/u-boot.lds +0 -0
 	/* UNINIT DATA - Small uninitialized data is first so it's
 	 * adjacent to sdata and can be referenced via gp. The normal
 	 * bss follows. We keep it adjacent to simplify init code.

Best regards,
Marek Vasut

#40 lore raw

PATCH v3 6/8 nios2: define _end in link script

Since commit 44c6e6591cb451ae606f8bde71dd5fb7b4002544 "rename _end to __bss_end__" , the _end was removed. But we need it now for separated device tree control, ie, CONFIG_OF_SEPARATE .

The _end is used by fdtdec_setup() to find the blob.

---

v3 comment coding style fix

 arch/nios2/cpu/u-boot.lds | 6 ++++++
 1 file changed, 6 insertions(+)
arch/nios2/cpu/u-boot.lds +6 -0
index 8b0fd1a..9d13ecc 100644
@@ -67,6 +67,12 @@ SECTIONS
 	_edata = .;
 	PROVIDE (edata = .);
 
+	/*
+	 * _end - This is end of u-boot.bin image.
+	 * dtb will be appended here to make u-boot-dtb.bin
+         */
+	_end = .;
+
 	/* UNINIT DATA - Small uninitialized data is first so it's
 	 * adjacent to sdata and can be referenced via gp. The normal
 	 * bss follows. We keep it adjacent to simplify init code.
Signature · 1 line
2.1.4
#41 lore raw

PATCH v3 6/8 nios2: define _end in link script

Quoted 22 lines · Thomas Chou

Since commit 44c6e6591cb451ae606f8bde71dd5fb7b4002544 "rename _end to __bss_end__" , the _end was removed. But we need it now for separated device tree control, ie, CONFIG_OF_SEPARATE .

The _end is used by fdtdec_setup() to find the blob.

---

v3 comment coding style fix

 arch/nios2/cpu/u-boot.lds | 6 ++++++
 1 file changed, 6 insertions(+)
arch/nios2/cpu/u-boot.lds +0 -0
index 8b0fd1a..9d13ecc 100644

arch/nios2/cpu/u-boot.lds SECTIONS · line 73

Quoted 7 lines
arch/nios2/cpu/u-boot.lds +4 -0
@@ -67,6 +67,12 @@ SECTIONS
 	_edata = .;
 	PROVIDE (edata = .);
 
+	/*
+	 * _end - This is end of u-boot.bin image.
+	 * dtb will be appended here to make u-boot-dtb.bin
+         */

Still broken ;-)

btw. please either repost the whole series or use git send-email --in-reply-to , so I dont have to hunt down patches all over the place.

arch/nios2/cpu/u-boot.lds SECTIONS · line 78

Quoted 5 lines
arch/nios2/cpu/u-boot.lds +2 -0
+	_end = .;
+
 	/* UNINIT DATA - Small uninitialized data is first so it's
 	 * adjacent to sdata and can be referenced via gp. The normal
 	 * bss follows. We keep it adjacent to simplify init code.

Best regards,
Marek Vasut

#42 lore raw

PATCH v2 6/8 nios2: define _end in link script

In reply to Thomas Chou

Hi Thomas,

Quoted 11 lines · Thomas Chou

Since commit 44c6e6591cb451ae606f8bde71dd5fb7b4002544 "rename _end to __bss_end__" , the _end was removed. But we need it now for separated device tree control, ie, CONFIG_OF_SEPARATE .

The _end is used by fdtdec_setup() to find the blob.

---
 arch/nios2/cpu/u-boot.lds | 5 +++++
 1 file changed, 5 insertions(+)

arch/nios2/cpu/u-boot.lds SECTIONS · line 69

Quoted 10 lines
arch/nios2/cpu/u-boot.lds +1 -0
index 951785c..535a974 100644
@@ -66,6 +66,11 @@ SECTIONS
        _edata = .;
        PROVIDE (edata = .);
 
+       /* _end - This is end of u-boot.bin image.

comment style:

/*
* _end -

Quoted 10 lines
arch/nios2/cpu/u-boot.lds +4 -1
+        * dtb will be appended here to make u-boot-dtb.bin
+         */
+       _end = .;
+
        /* UNINIT DATA - Small uninitialized data is first so it's
         * adjacent to sdata and can be referenced via gp. The normal
         * bss follows. We keep it adjacent to simplify init code.
--

2.1.4

Regards,
Simon

#43 lore raw

PATCH v2 7/8 nios2: show fdt blob address in board info command

In reply to Thomas Chou

Show fdt blob address in board info command.

---
 common/cmd_bdinfo.c | 3 +++
 1 file changed, 3 insertions(+)
common/cmd_bdinfo.c +3 -0
index ed3b935..74ff229 100644
@@ -176,6 +176,9 @@ int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 #endif
 
 	printf("baudrate    = %u bps\n", gd->baudrate);
+#if defined(CONFIG_OF_CONTROL)
+	print_num("fdt_blob", (ulong)gd->fdt_blob);
+#endif
 
 	return 0;
 }
Signature · 1 line
2.1.4
#44 lore raw

PATCH v2 7/8 nios2: show fdt blob address in board info command

Quoted 14 lines · Thomas Chou

Show fdt blob address in board info command.

---
 common/cmd_bdinfo.c | 3 +++
 1 file changed, 3 insertions(+)
common/cmd_bdinfo.c +0 -0
index ed3b935..74ff229 100644
@@ -176,6 +176,9 @@ int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc,

char * const argv[]) #endif

common/cmd_bdinfo.c int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) · line 180

Quoted 3 lines
common/cmd_bdinfo.c +2 -0
 	printf("baudrate    = %u bps\n", gd->baudrate);
+#if defined(CONFIG_OF_CONTROL)
+	print_num("fdt_blob", (ulong)gd->fdt_blob);

I think this will not work on 64bit machines.

common/cmd_bdinfo.c int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) · line 184

Quoted 4 lines
common/cmd_bdinfo.c +1 -0
+#endif
 
 	return 0;
 }

Best regards,
Marek Vasut

#45 lore raw

PATCH v2 7/8 nios2: show fdt blob address in board info command

Hi Marek,

Quoted 3 lines · Marek Vasut

common/cmd_bdinfo.c int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) · line 180

Quoted 1 line
common/cmd_bdinfo.c +1 -0
+	print_num("fdt_blob", (ulong)gd->fdt_blob);

I think this will not work on 64bit machines.

I'd agree that it won't work on 64bits machines, but it is enough for a soft-core 32btis fpga processor. :)

Best regards,
Thomas Chou

#46 lore raw

PATCH v2 7/8 nios2: show fdt blob address in board info command

Quoted 1 line · Thomas Chou

Hi Marek,

Hi,

Quoted 7 lines · Marek Vasut
Quoted 3 lines

common/cmd_bdinfo.c int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) · line 180

Quoted 1 line
common/cmd_bdinfo.c +1 -0
+	print_num("fdt_blob", (ulong)gd->fdt_blob);

I think this will not work on 64bit machines.

I'd agree that it won't work on 64bits machines, but it is enough for a soft-core 32btis fpga processor. :)

That's a common code you're modifying, so it has to be done right, sorry, this patch cannot be accepted in this form.

Best regards,
Marek Vasut

#47 lore raw

PATCH v2 7/8 nios2: show fdt blob address in board info command

Hi Marek,

Quoted 2 lines · Marek Vasut

That's a common code you're modifying, so it has to be done right, sorry, this patch cannot be accepted in this form.

I understand. I will use (u64) and print_lnum().

Best regards,
Thomas Chou

#48 lore raw

PATCH v2 7/8 nios2: show fdt blob address in board info command

In reply to Marek Vasut

Hi Marek,

Quoted 1 line
Quoted 1 line
Quoted 1 line

I think this will not work on 64bit machines.

I tried 64bits with

	print_lnum("fdt_blob", (u64)gd->fdt_blob);

But got this warning,

CC common/cmd_bdinfo.o
common/cmd_bdinfo.c: In function 'do_bdinfo':
common/cmd_bdinfo.c:180:25: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]

   print_lnum("fdt_blob", (u64)gd->fdt_blob);
                          ^

include/asm-generic/global_data.h
const void *fdt_blob; /* Our device tree, NULL if none */

Actually, the print is guarded with CONFIG_NIOS2, so it is safe to use 32bits.

Or shall we invent a "print pointer address"?

Best regards,
Thomas Chou

#49 lore raw

PATCH v2 7/8 nios2: show fdt blob address in board info command

Quoted 16 lines · Thomas Chou

Hi Marek,

Quoted 1 line
Quoted 1 line
Quoted 1 line

I think this will not work on 64bit machines.

I tried 64bits with

	print_lnum("fdt_blob", (u64)gd->fdt_blob);

But got this warning,

CC common/cmd_bdinfo.o
common/cmd_bdinfo.c: In function 'do_bdinfo':
common/cmd_bdinfo.c:180:25: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]

   print_lnum("fdt_blob", (u64)gd->fdt_blob);
                          ^
Quoted 7 lines

include/asm-generic/global_data.h
const void *fdt_blob; /* Our device tree, NULL if none */

Actually, the print is guarded with CONFIG_NIOS2, so it is safe to use 32bits.

Or shall we invent a "print pointer address"?

Simon, Tom, what's your take on this ?

Best regards,
Marek Vasut

#50 lore raw

PATCH v2 7/8 nios2: show fdt blob address in board info command

Hi,

Quoted 20 lines · Marek Vasut
Quoted 19 lines · Thomas Chou

Hi Marek,

Quoted 1 line
Quoted 1 line
Quoted 1 line

I think this will not work on 64bit machines.

I tried 64bits with

      print_lnum("fdt_blob", (u64)gd->fdt_blob);

But got this warning,

CC common/cmd_bdinfo.o
common/cmd_bdinfo.c: In function 'do_bdinfo':
common/cmd_bdinfo.c:180:25: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]

   print_lnum("fdt_blob", (u64)gd->fdt_blob);
                          ^

include/asm-generic/global_data.h
const void *fdt_blob; /* Our device tree, NULL if none */

Quoted 6 lines
Quoted 4 lines

Actually, the print is guarded with CONFIG_NIOS2, so it is safe to use 32bits.

Or shall we invent a "print pointer address"?

Simon, Tom, what's your take on this ?

From what I can tell this code is not generic, and is built for NIOS only. So IMO the patch is fine and we don't need to worry about 64-bit.

Regards,
Simon

#51 lore raw

PATCH v2 7/8 nios2: show fdt blob address in board info command

Quoted 31 lines · Simon Glass

Hi,

Quoted 28 lines · Marek Vasut
Quoted 27 lines · Thomas Chou

Hi Marek,

Quoted 1 line
Quoted 1 line
Quoted 1 line

I think this will not work on 64bit machines.

I tried 64bits with

      print_lnum("fdt_blob", (u64)gd->fdt_blob);

But got this warning,

CC common/cmd_bdinfo.o

common/cmd_bdinfo.c: In function 'do_bdinfo':
common/cmd_bdinfo.c:180:25: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]

   print_lnum("fdt_blob", (u64)gd->fdt_blob);
                          ^

include/asm-generic/global_data.h

const void *fdt_blob; /* Our device tree, NULL if none */

Actually, the print is guarded with CONFIG_NIOS2, so it is safe to use 32bits.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Or shall we invent a "print pointer address"?

Simon, Tom, what's your take on this ?

From what I can tell this code is not generic, and is built for NIOS only. So IMO the patch is fine and we don't need to worry about 64-bit.

Oh my $DEITY, we have one bdinfo implementation per architecture, all in one ugly file. In that case, you're right, but this is truly horrible.

Best regards,
Marek Vasut

#54 lore raw

PATCH v2 8/8 nios2: enable device tree control of U-Boot

In reply to Thomas Chou

This patch adds device tree control of U-Boot to nios2 boards. The example dts is taken from Linux kernel.

---
 arch/nios2/dts/.gitignore          |   1 +
 arch/nios2/dts/3c120_devboard.dts  | 153 +++++++++++++++++++++++++++++++++++++
 arch/nios2/dts/Makefile            |  11 +++
 arch/nios2/dts/include/dt-bindings |   1 +
 configs/nios2-generic_defconfig    |   2 +
 5 files changed, 168 insertions(+)
 create mode 100644 arch/nios2/dts/.gitignore
 create mode 100644 arch/nios2/dts/3c120_devboard.dts
 create mode 100644 arch/nios2/dts/Makefile
 create mode 120000 arch/nios2/dts/include/dt-bindings
arch/nios2/dts/.gitignore new file +1 -0
new file mode 100644
index 0000000..b60ed20
@@ -0,0 +1 @@
+*.dtb
arch/nios2/dts/3c120_devboard.dts new file +153 -0

153 lines not on this page · raw message

arch/nios2/dts/Makefile new file +11 -0
new file mode 100644
index 0000000..b2175a1
@@ -0,0 +1,11 @@
+dtb-y += 3c120_devboard.dtb
+
+targets += $(dtb-y)
+
+DTC_FLAGS += -R 4 -p 0x1000
+
+PHONY += dtbs
+dtbs: $(addprefix $(obj)/, $(dtb-y))
+	@:
+
+clean-files := *.dtb
arch/nios2/dts/include/dt-bindings new file +1 -0
new file mode 120000
index 0000000..0cecb3d
@@ -0,0 +1 @@
+../../../../include/dt-bindings
\ No newline at end of file
configs/nios2-generic_defconfig +2 -0
index f8d2821..09cc51e 100644
@@ -1,5 +1,6 @@
 CONFIG_NIOS2=y
 CONFIG_TARGET_NIOS2_GENERIC=y
+CONFIG_DEFAULT_DEVICE_TREE="3c120_devboard"
 CONFIG_HUSH_PARSER=y
 # CONFIG_CMD_BOOTD is not set
 # CONFIG_CMD_IMLS is not set
@@ -10,4 +11,5 @@ CONFIG_HUSH_PARSER=y
 CONFIG_CMD_DHCP=y
 # CONFIG_CMD_NFS is not set
 CONFIG_CMD_PING=y
+CONFIG_OF_CONTROL=y
 CONFIG_NET_RANDOM_ETHADDR=y
Signature · 1 line
2.1.4
#55 lore raw

PATCH v2 8/8 nios2: enable device tree control of U-Boot

Quoted 5 lines · Thomas Chou

This patch adds device tree control of U-Boot to nios2 boards. The example dts is taken from Linux kernel.

Quoted 12 lines
---
 arch/nios2/dts/.gitignore          |   1 +
 arch/nios2/dts/3c120_devboard.dts  | 153
+++++++++++++++++++++++++++++++++++++ arch/nios2/dts/Makefile            |
 11 +++
 arch/nios2/dts/include/dt-bindings |   1 +
 configs/nios2-generic_defconfig    |   2 +
 5 files changed, 168 insertions(+)
 create mode 100644 arch/nios2/dts/.gitignore
 create mode 100644 arch/nios2/dts/3c120_devboard.dts
 create mode 100644 arch/nios2/dts/Makefile
 create mode 120000 arch/nios2/dts/include/dt-bindings

You might also start working on dissolving the board/altera/nios2-generic/custom_fpga.h horror file, since with DT this is no longer needed :)

Best regards,
Marek Vasut

#56 lore raw

PATCH v2 8/8 nios2: enable device tree control of U-Boot

Hi Marek,

Quoted 3 lines · Marek Vasut

You might also start working on dissolving the board/altera/nios2-generic/custom_fpga.h horror file, since with DT this is no longer needed :)

Sure thing. This is on my TODO list.

May I know that if there is any work in process on Driver Model for Altera jtaguart, uart, spi and ethernet?

Best regards,
Thomas Chou

#57 lore raw

PATCH v2 8/8 nios2: enable device tree control of U-Boot

Quoted 1 line · Thomas Chou

Hi Marek,

Hi,

Quoted 9 lines · Marek Vasut
Quoted 3 lines

You might also start working on dissolving the board/altera/nios2-generic/custom_fpga.h horror file, since with DT this is no longer needed :)

Sure thing. This is on my TODO list.

May I know that if there is any work in process on Driver Model for Altera jtaguart, uart, spi and ethernet?

There isn't any, feel free to start playing around :)

Best regards,
Marek Vasut

#58 lore raw

v2 cover nios2: add device tree control of U-Boot

In reply to Thomas Chou
Quoted 5 lines · Thomas Chou

These patches add device tree control of U-Boot to nios2 boards.

v2
use SPDX license header.
use fdt relocation in board_init_f.

Excellent, thanks :)

I can start picking the NIOS2 stuff into U-Boot as well if you want.

Best regards,
Marek Vasut

#59 lore raw

v2 cover nios2: add device tree control of U-Boot

Hi Marek,

Quoted 1 line · Marek Vasut

I can start picking the NIOS2 stuff into U-Boot as well if you want.

That's great! You are very kind and responsive. Thanks a lot. You can take over the custodianship of nios2 arch. Then I will be retired. :)

BTW, please also look over the earlier patches,

[PATCH] nios2: move command line configuration to Kconfig, Aug,28 [PATCH] nios2: enable CONFIG_NET_RANDOM_ETHADDR, Aug,29 And perhaps,
[PATCH] mmc_spi: fix big-endian support error on be_to_cpu16, Aug,31

Cheers,
Thomas Chou

#60 lore raw

v2 cover nios2: add device tree control of U-Boot

Quoted 1 line · Thomas Chou

Hi Marek,

Hi,

Quoted 7 lines · Marek Vasut
Quoted 1 line

I can start picking the NIOS2 stuff into U-Boot as well if you want.

That's great! You are very kind and responsive. Thanks a lot. You can take over the custodianship of nios2 arch. Then I will be retired. :)

BTW, please also look over the earlier patches,

Did you do the custodianing before ? Wow, looks like there's a bit of a chaos in this :)

I'll gladly leave it to you ;-)

Quoted 4 lines

[PATCH] nios2: move command line configuration to Kconfig, Aug,28 [PATCH] nios2: enable CONFIG_NET_RANDOM_ETHADDR, Aug,29 And perhaps,
[PATCH] mmc_spi: fix big-endian support error on be_to_cpu16, Aug,31

This one should be handled by Pantelis.

Best regards,
Marek Vasut

#61 lore raw

v2 cover nios2: add device tree control of U-Boot

In reply to Thomas Chou
Quoted 7 lines · Thomas Chou

Hi Marek,

Quoted 1 line · Marek Vasut

I can start picking the NIOS2 stuff into U-Boot as well if you want.

That's great! You are very kind and responsive. Thanks a lot. You can take over the custodianship of nios2 arch. Then I will be retired. :)

Added Altera socfpga U-boot owner in CC list.

Quoted 10 lines

BTW, please also look over the earlier patches,

[PATCH] nios2: move command line configuration to Kconfig, Aug,28 [PATCH] nios2: enable CONFIG_NET_RANDOM_ETHADDR, Aug,29 And perhaps,
[PATCH] mmc_spi: fix big-endian support error on be_to_cpu16, Aug,31

Cheers,
Thomas Chou

#62 lore raw

v4 cover nios2: add device tree control of U-Boot

In reply to Thomas Chou

These patches add device tree control of U-Boot to nios2 boards.

v2
use SPDX license header.
use fdt relocation in board_init_f.
v3
fix comment style.
v4
drop fdt_blob print in board info, which needs more discussion.

Thomas Chou (7):
nios2: permit device tree control of U-Boot
nios2: move altera_pio_init to board_early_init_r
nios2: BSS should be cleared only after board_init_f
nios2: enlarge the code relocation range
nios2: remove gp assignments in link script
nios2: define _end in link script
nios2: enable device tree control of U-Boot

 arch/Kconfig                               |   1 +
 arch/nios2/cpu/start.S                     |  35 ++++---
 arch/nios2/cpu/u-boot.lds                  |  14 ++-
 arch/nios2/dts/.gitignore                  |   1 +
 arch/nios2/dts/3c120_devboard.dts          | 153 +++++++++++++++++++++++++++++
 arch/nios2/dts/Makefile                    |  11 +++
 arch/nios2/dts/include/dt-bindings         |   1 +
 board/altera/nios2-generic/nios2-generic.c |  13 ++-
 configs/nios2-generic_defconfig            |   2 +
 include/configs/nios2-generic.h            |   1 +
 10 files changed, 209 insertions(+), 23 deletions(-)
 create mode 100644 arch/nios2/dts/.gitignore
 create mode 100644 arch/nios2/dts/3c120_devboard.dts
 create mode 100644 arch/nios2/dts/Makefile
 create mode 120000 arch/nios2/dts/include/dt-bindings
Signature · 1 line
2.1.4
#63 lore raw

PATCH v4 1/7 nios2: permit device tree control of U-Boot

Enable this in the Kconfig so that nios2 boards can use device tree to configure U-Boot.

---
 arch/Kconfig | 1 +
 1 file changed, 1 insertion(+)
arch/Kconfig +1 -0
index 4f73819..207c778 100644
@@ -63,6 +63,7 @@ config NIOS2
 	bool "Nios II architecture"
 	select HAVE_GENERIC_BOARD
 	select SYS_GENERIC_BOARD
+	select SUPPORT_OF_CONTROL
 
 config OPENRISC
 	bool "OpenRISC architecture"
Signature · 1 line
2.1.4
#65 lore raw

PATCH v4 2/7 nios2: move altera_pio_init to board_early_init_r

In reply to Thomas Chou

As altera_pio_init() uses BSS, it should be moved to board_early_init_r().

---
 board/altera/nios2-generic/nios2-generic.c | 13 +++++++++----
 include/configs/nios2-generic.h            |  1 +
 2 files changed, 10 insertions(+), 4 deletions(-)
board/altera/nios2-generic/nios2-generic.c +9 -4
index 834cbeb..384fee9 100644
@@ -28,6 +28,15 @@ void early_flash_cmd_reset(void)
 
 int board_early_init_f(void)
 {
+#if defined(CONFIG_ENV_IS_IN_FLASH) && defined(CONFIG_ENV_ADDR) && \
+    defined(CONFIG_CFI_FLASH_MTD)
+	early_flash_cmd_reset();
+#endif
+	return 0;
+}
+
+int board_early_init_r(void)
+{
 #ifdef CONFIG_ALTERA_PIO
 #ifdef LED_PIO_BASE
 	altera_pio_init(LED_PIO_BASE, LED_PIO_WIDTH, 'o',
@@ -35,10 +44,6 @@ int board_early_init_f(void)
 			"led");
 #endif
 #endif
-#if defined(CONFIG_ENV_IS_IN_FLASH) && defined(CONFIG_ENV_ADDR) && \
-    defined(CONFIG_CFI_FLASH_MTD)
-	early_flash_cmd_reset();
-#endif
 	return 0;
 }
 
include/configs/nios2-generic.h +1 -0
index 5bb7768..293acae 100644
@@ -15,6 +15,7 @@
 #include "../board/altera/nios2-generic/custom_fpga.h" /* fpga parameters */
 #define CONFIG_BOARD_NAME "nios2-generic" /* custom board name */
 #define CONFIG_BOARD_EARLY_INIT_F	/* enable early board-spec. init */
+#define CONFIG_BOARD_EARLY_INIT_R
 #define CONFIG_DISPLAY_CPUINFO
 #define CONFIG_DISPLAY_BOARDINFO
 #define CONFIG_SYS_NIOS_SYSID_BASE	CONFIG_SYS_SYSID_BASE
Signature · 1 line
2.1.4
#66 lore raw

PATCH v4 2/7 nios2: move altera_pio_init to board_early_init_r

Quoted 9 lines · Thomas Chou

As altera_pio_init() uses BSS, it should be moved to board_early_init_r().

---
  board/altera/nios2-generic/nios2-generic.c | 13 +++++++++----
  include/configs/nios2-generic.h            |  1 +
  2 files changed, 10 insertions(+), 4 deletions(-)

Applied to u-boot-nios.

#67 lore raw

PATCH v4 3/7 nios2: BSS should be cleared only after board_init_f

In reply to Thomas Chou

As dtb in u-boot-dtb.bin overlapped the BSS section, we should delay the clearing of BSS until dtb is relocated in board_init_f().

---
 arch/nios2/cpu/start.S | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)
arch/nios2/cpu/start.S +16 -14
index 6af9b4e..9e440c2 100644
@@ -82,20 +82,6 @@ _cur:	movhi	r5, %hi(_cur - _start)
 	bne	r5, r6, 2b
 3:
 
-	/* ZERO BSS/SBSS -- bss and sbss are assumed to be adjacent
-	 * and between __bss_start and __bss_end.
-	 */
-	 movhi	r5, %hi(__bss_start)
-	 ori	r5, r5, %lo(__bss_start)
-	 movhi	r6, %hi(__bss_end)
-	 ori	r6, r6, %lo(__bss_end)
-	 beq	r5, r6, 5f
-
-4:	stwio	r0, 0(r5)
-	 addi	r5, r5, 4
-	 bne	r5, r6, 4b
-5:
-
 	/* JUMP TO RELOC ADDR */
 	movhi	r4, %hi(_reloc)
 	ori	r4, r4, %lo(_reloc)
@@ -167,6 +153,22 @@ _reloc:
 relocate_code:
 	mov	sp, r4		/* Set the new sp */
 	mov	r4, r5
+
+	/*
+	 * ZERO BSS/SBSS -- bss and sbss are assumed to be adjacent
+	 * and between __bss_start and __bss_end.
+	 */
+	movhi	r5, %hi(__bss_start)
+	ori	r5, r5, %lo(__bss_start)
+	movhi	r6, %hi(__bss_end)
+	ori	r6, r6, %lo(__bss_end)
+	beq	r5, r6, 5f
+
+4:	stwio	r0, 0(r5)
+	addi	r5, r5, 4
+	bne	r5, r6, 4b
+5:
+
 	movhi	r8, %hi(board_init_r at h)
 	ori	r8, r8, %lo(board_init_r at h)
 	callr	r8
Signature · 1 line
2.1.4
#68 lore raw

PATCH v4 3/7 nios2: BSS should be cleared only after board_init_f

Quoted 9 lines · Thomas Chou

As dtb in u-boot-dtb.bin overlapped the BSS section, we should delay the clearing of BSS until dtb is relocated in board_init_f().

---
  arch/nios2/cpu/start.S | 30 ++++++++++++++++--------------
  1 file changed, 16 insertions(+), 14 deletions(-)

Applied to u-boot-nios.

#69 lore raw

PATCH v4 4/7 nios2: enlarge the code relocation range

In reply to Thomas Chou

As we will use u-boot-dtb.bin, the code relocation range should be adjusted to accommodate the additional dtb. It might be overkilled to look into dtb header to find the dtb size, so we will simply use CONFIG_SYS_MONITOR_LEN.

---
 arch/nios2/cpu/start.S | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/nios2/cpu/start.S +3 -2
index 9e440c2..f80b4f3 100644
@@ -73,8 +73,9 @@ _cur:	movhi	r5, %hi(_cur - _start)
 	ori	r5, r5, %lo(_start)	/* r5 <- linked _start */
 	beq	r4, r5, 3f
 
-	movhi	r6, %hi(_edata)
-	ori	r6, r6, %lo(_edata)
+	movhi	r6, %hi(CONFIG_SYS_MONITOR_LEN)
+	ori	r6, r6, %lo(CONFIG_SYS_MONITOR_LEN)
+	add	r6, r6, r5
 2:	ldwio	r7, 0(r4)
 	addi	r4, r4, 4
 	stwio	r7, 0(r5)
Signature · 1 line
2.1.4
#70 lore raw

PATCH v4 4/7 nios2: enlarge the code relocation range

Quoted 10 lines · Thomas Chou

As we will use u-boot-dtb.bin, the code relocation range should be adjusted to accommodate the additional dtb. It might be overkilled to look into dtb header to find the dtb size, so we will simply use CONFIG_SYS_MONITOR_LEN.

---
  arch/nios2/cpu/start.S | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)

Applied to u-boot-nios.

#71 lore raw

PATCH v4 5/7 nios2: remove gp assignments in link script

In reply to Thomas Chou

Since we don't use gp for small data with option "-G0", we use gp as global data pointer. The _gp location is not needed.

The ALIGN(16) was for gp only. It is removed, so that we can get correct address of dtb in u-boot-dtb.bin image.

---
 arch/nios2/cpu/u-boot.lds | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
arch/nios2/cpu/u-boot.lds +5 -3
index 6e174be..8b0fd1a 100644
@@ -50,9 +50,11 @@ SECTIONS
 	  *(.gnu.linkonce.d*)
 	}
 
-	. = ALIGN(16);
-	_gp = .;			/* Global pointer addr */
-	PROVIDE (gp = .);
+	/*
+	 * gp - Since we don't use gp for small data with option "-G0",
+	 * we will use gp as global data pointer. The _gp location is
+	 * not needed.
+	 */
 
 	.sdata :
 	{
Signature · 1 line
2.1.4
#72 lore raw

PATCH v4 5/7 nios2: remove gp assignments in link script

Quoted 7 lines · Thomas Chou

Since we don't use gp for small data with option "-G0", we use gp as global data pointer. The _gp location is not needed.

The ALIGN(16) was for gp only. It is removed, so that we can get correct address of dtb in u-boot-dtb.bin image.

Quoted 7 lines
---
  arch/nios2/cpu/u-boot.lds | 8 +++++---
  1 file changed, 5 insertions(+), 3 deletions(-)

Applied to u-boot-nios.

#73 lore raw

PATCH v4 6/7 nios2: define _end in link script

In reply to Thomas Chou

Since commit 44c6e6591cb451ae606f8bde71dd5fb7b4002544 "rename _end to __bss_end__" , the _end was removed. But we need it now for separated device tree control, ie, CONFIG_OF_SEPARATE .

The _end is used by fdtdec_setup() to find the blob.

---
 arch/nios2/cpu/u-boot.lds | 6 ++++++
 1 file changed, 6 insertions(+)
arch/nios2/cpu/u-boot.lds +6 -0
index 8b0fd1a..3bd3f2c 100644
@@ -67,6 +67,12 @@ SECTIONS
 	_edata = .;
 	PROVIDE (edata = .);
 
+	/*
+	 * _end - This is end of u-boot.bin image.
+	 * dtb will be appended here to make u-boot-dtb.bin
+	 */
+	_end = .;
+
 	/* UNINIT DATA - Small uninitialized data is first so it's
 	 * adjacent to sdata and can be referenced via gp. The normal
 	 * bss follows. We keep it adjacent to simplify init code.
Signature · 1 line
2.1.4
#74 lore raw

PATCH v4 6/7 nios2: define _end in link script

Quoted 5 lines · Thomas Chou

Since commit 44c6e6591cb451ae606f8bde71dd5fb7b4002544 "rename _end to __bss_end__" , the _end was removed. But we need it now for separated device tree control, ie, CONFIG_OF_SEPARATE .

Quoted 9 lines

The _end is used by fdtdec_setup() to find the blob.

---
  arch/nios2/cpu/u-boot.lds | 6 ++++++
  1 file changed, 6 insertions(+)

Applied to u-boot-nios.

#75 lore raw

PATCH v4 7/7 nios2: enable device tree control of U-Boot

In reply to Thomas Chou

This patch adds device tree control of U-Boot to nios2 boards. The example dts is taken from Linux kernel.

---
 arch/nios2/dts/.gitignore          |   1 +
 arch/nios2/dts/3c120_devboard.dts  | 153 +++++++++++++++++++++++++++++++++++++
 arch/nios2/dts/Makefile            |  11 +++
 arch/nios2/dts/include/dt-bindings |   1 +
 configs/nios2-generic_defconfig    |   2 +
 5 files changed, 168 insertions(+)
 create mode 100644 arch/nios2/dts/.gitignore
 create mode 100644 arch/nios2/dts/3c120_devboard.dts
 create mode 100644 arch/nios2/dts/Makefile
 create mode 120000 arch/nios2/dts/include/dt-bindings
arch/nios2/dts/.gitignore new file +1 -0
new file mode 100644
index 0000000..b60ed20
@@ -0,0 +1 @@
+*.dtb
arch/nios2/dts/3c120_devboard.dts new file +153 -0

153 lines not on this page · raw message

arch/nios2/dts/Makefile new file +11 -0
new file mode 100644
index 0000000..b2175a1
@@ -0,0 +1,11 @@
+dtb-y += 3c120_devboard.dtb
+
+targets += $(dtb-y)
+
+DTC_FLAGS += -R 4 -p 0x1000
+
+PHONY += dtbs
+dtbs: $(addprefix $(obj)/, $(dtb-y))
+	@:
+
+clean-files := *.dtb
arch/nios2/dts/include/dt-bindings new file +1 -0
new file mode 120000
index 0000000..0cecb3d
@@ -0,0 +1 @@
+../../../../include/dt-bindings
\ No newline at end of file
configs/nios2-generic_defconfig +2 -0
index f8d2821..09cc51e 100644
@@ -1,5 +1,6 @@
 CONFIG_NIOS2=y
 CONFIG_TARGET_NIOS2_GENERIC=y
+CONFIG_DEFAULT_DEVICE_TREE="3c120_devboard"
 CONFIG_HUSH_PARSER=y
 # CONFIG_CMD_BOOTD is not set
 # CONFIG_CMD_IMLS is not set
@@ -10,4 +11,5 @@ CONFIG_HUSH_PARSER=y
 CONFIG_CMD_DHCP=y
 # CONFIG_CMD_NFS is not set
 CONFIG_CMD_PING=y
+CONFIG_OF_CONTROL=y
 CONFIG_NET_RANDOM_ETHADDR=y
Signature · 1 line
2.1.4
#76 lore raw

PATCH v4 7/7 nios2: enable device tree control of U-Boot

Quoted 13 lines · Thomas Chou

This patch adds device tree control of U-Boot to nios2 boards. The example dts is taken from Linux kernel.

---
  arch/nios2/dts/.gitignore          |   1 +
  arch/nios2/dts/3c120_devboard.dts  | 153 +++++++++++++++++++++++++++++++++++++
  arch/nios2/dts/Makefile            |  11 +++
  arch/nios2/dts/include/dt-bindings |   1 +
  configs/nios2-generic_defconfig    |   2 +
  5 files changed, 168 insertions(+)
Quoted 5 lines

create mode 100644 arch/nios2/dts/.gitignore create mode 100644 arch/nios2/dts/3c120_devboard.dts create mode 100644 arch/nios2/dts/Makefile create mode 120000 arch/nios2/dts/include/dt-bindings

Applied to u-boot-nios.

#77 lore raw

v4 cover nios2: add device tree control of U-Boot

In reply to Thomas Chou
Quoted 10 lines · Thomas Chou

These patches add device tree control of U-Boot to nios2 boards.

v2
use SPDX license header.
use fdt relocation in board_init_f.
v3
fix comment style.
v4
drop fdt_blob print in board info, which needs more discussion.

Quoted 8 lines

Thomas Chou (7):
nios2: permit device tree control of U-Boot
nios2: move altera_pio_init to board_early_init_r
nios2: BSS should be cleared only after board_init_f
nios2: enlarge the code relocation range
nios2: remove gp assignments in link script
nios2: define _end in link script
nios2: enable device tree control of U-Boot

Hi,

Nice, I like seeing how NIOS2 getting back to shape. btw you could have waited a few days before applying patches that were just posted.

Best regards,
Marek Vasut

#78 lore raw

v4 cover nios2: add device tree control of U-Boot

Hi Marek,

Quoted 2 lines · Marek Vasut

Nice, I like seeing how NIOS2 getting back to shape. btw you could have waited a few days before applying patches that were just posted.

Thanks for reminding. I used to wait a week. But I hate too many things floating around, that would prevent me to focus. Something we might have enough discussion or too trivial..

Thank you again. And please continue your great work.

Cheers,
Thomas Chou