mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 00/10] ARM32: allow disabling ATAGS and DT fallback
@ 2025-05-28 10:50 Ahmad Fatoum
  2025-05-28 10:50 ` [PATCH 01/10] arch: add new HAVE_ARCH_BOOTM_OFTREE symbol Ahmad Fatoum
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: Ahmad Fatoum @ 2025-05-28 10:50 UTC (permalink / raw)
  To: barebox

New platforms shouldn't use atags, but we compile the code always.

New platforms should use device tree, but there may be binding
incompatibilities between barebox embedded device tree and device tree
shipped with the kernel.

For that reason, this series introduces two config options:

 - CONFIG_BOOT_ATAGS: Now disabled by default as it has been
   replaced by device trees

 - BOOTM_OFTREE_FALLBACK: Enabled by default, but should likely
   be disabled in products, so the device tree should be explicitly
   suppied.

Ahmad Fatoum (10):
  arch: add new HAVE_ARCH_BOOTM_OFTREE symbol
  bootm: enable CONFIG_BOOTM_OFTREE by default
  ARM: lib32: disable ATAGS support by default
  kvx: bootm: enforce existence of device tree
  bootm: booti: make device tree optional
  filetype: add new file type for 0-sized files
  bootm: have bootm_get_devicetree return NULL if passed empty DT
  bootm: make fallback to barebox internal tree optional
  commands: oftree: add option to return device tree without fixups
  of: drop undefined fdt_get_tree declaration

 .../migration-guides/migration-2025.07.0.rst  |   7 +
 arch/Kconfig                                  |   6 +
 arch/arm/Kconfig                              |  13 +-
 arch/arm/configs/animeo_ip_defconfig          |   1 +
 arch/arm/configs/at91rm9200ek_defconfig       |   1 +
 arch/arm/configs/at91sam9260ek_defconfig      |   1 +
 .../configs/at91sam9261ek_bootstrap_defconfig |   1 +
 arch/arm/configs/at91sam9261ek_defconfig      |   1 +
 arch/arm/configs/at91sam9g10ek_defconfig      |   1 +
 arch/arm/configs/at91sam9g20ek_defconfig      |   1 +
 arch/arm/configs/at91sam9m10g45ek_defconfig   |   1 +
 arch/arm/configs/at91sam9m10ihd_defconfig     |   1 +
 arch/arm/configs/at91sam9n12ek_defconfig      |   1 +
 arch/arm/configs/dss11_defconfig              |   1 +
 arch/arm/configs/haba_knx_lite_defconfig      |   1 +
 arch/arm/configs/imx23_defconfig              |   1 +
 arch/arm/configs/imx28_defconfig              |   1 +
 arch/arm/configs/kindle-mx50_defconfig        |   1 +
 arch/arm/configs/multi_v5_v6_defconfig        |   1 +
 arch/arm/configs/mvebu_defconfig              |   1 +
 arch/arm/configs/omap_defconfig               |   1 +
 arch/arm/configs/pm9261_defconfig             |   1 +
 arch/arm/configs/pm9263_defconfig             |   1 +
 arch/arm/configs/pm9g45_defconfig             |   1 +
 arch/arm/configs/qil_a9260_defconfig          |   1 +
 arch/arm/configs/qil_a9g20_defconfig          |   1 +
 arch/arm/configs/rockchip_v7a_defconfig       |   1 +
 arch/arm/configs/telit_evk_pro3_defconfig     |   1 +
 arch/arm/configs/tny_a9260_defconfig          |   1 +
 .../arm/configs/tny_a9263_bootstrap_defconfig |   1 +
 arch/arm/configs/tny_a9263_defconfig          |   1 +
 arch/arm/configs/tny_a9g20_defconfig          |   1 +
 arch/arm/configs/usb_a9260_defconfig          |   1 +
 .../arm/configs/usb_a9263_bootstrap_defconfig |   1 +
 arch/arm/configs/usb_a9263_defconfig          |   1 +
 arch/arm/configs/usb_a9g20_defconfig          |   1 +
 arch/arm/include/asm/armlinux.h               |  25 +-
 arch/arm/lib32/Makefile                       |   1 +
 arch/arm/lib32/armlinux.c                     | 234 +-----------------
 arch/arm/lib32/atags.c                        | 230 +++++++++++++++++
 arch/arm/lib32/bootm.c                        |   2 +-
 arch/arm/lib32/bootu.c                        |  11 +-
 arch/arm/lib32/bootz.c                        |   9 +-
 arch/arm/lib64/armlinux.c                     |   2 +-
 arch/arm/mach-imx/Kconfig                     |   1 +
 arch/kvx/Kconfig                              |   1 +
 arch/kvx/lib/bootm.c                          |   2 +
 arch/mips/Kconfig                             |   1 +
 arch/powerpc/Kconfig                          |   1 +
 arch/powerpc/lib/ppclinux.c                   |   2 +-
 arch/riscv/Kconfig                            |   1 +
 arch/riscv/lib/bootm.c                        |   2 +-
 arch/sandbox/Kconfig                          |   1 +
 arch/x86/configs/efi_defconfig                |   1 -
 commands/Kconfig                              |   8 +-
 commands/oftree.c                             |  14 +-
 common/Kconfig                                |  22 +-
 common/booti.c                                |  14 +-
 common/bootm.c                                |  14 +-
 common/filetype.c                             |   3 +-
 common/oftree.c                               |  22 +-
 include/filetype.h                            |   1 +
 include/of.h                                  |  37 ++-
 63 files changed, 447 insertions(+), 274 deletions(-)
 create mode 100644 arch/arm/lib32/atags.c

-- 
2.39.5




^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 01/10] arch: add new HAVE_ARCH_BOOTM_OFTREE symbol
  2025-05-28 10:50 [PATCH 00/10] ARM32: allow disabling ATAGS and DT fallback Ahmad Fatoum
@ 2025-05-28 10:50 ` Ahmad Fatoum
  2025-05-28 10:50 ` [PATCH 02/10] bootm: enable CONFIG_BOOTM_OFTREE by default Ahmad Fatoum
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Ahmad Fatoum @ 2025-05-28 10:50 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

On platforms like x86, where barebox doesn't pass a device tree to the
kernel, it doesn't make sense to have CONFIG_BOOTM_OFTREE selectable, so
add a hidden symbol to hide it behind.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/Kconfig                   | 6 ++++++
 arch/arm/Kconfig               | 1 +
 arch/kvx/Kconfig               | 1 +
 arch/mips/Kconfig              | 1 +
 arch/powerpc/Kconfig           | 1 +
 arch/riscv/Kconfig             | 1 +
 arch/sandbox/Kconfig           | 1 +
 arch/x86/configs/efi_defconfig | 1 -
 common/Kconfig                 | 2 +-
 9 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/arch/Kconfig b/arch/Kconfig
index dc5d1e454df5..890923ad059c 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -77,6 +77,12 @@ config HAVE_EFFICIENT_UNALIGNED_ACCESS
 config HAVE_ARCH_BOARD_GENERIC_DT
 	bool
 
+config HAVE_ARCH_BOOTM_OFTREE
+	bool
+	help
+	  Selected by architectures where barebox can pass a device tree to the
+	  kernel while booting with bootm.
+
 config HAVE_MOD_ARCH_SPECIFIC
 	bool
 	help
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 0800b15d784c..0b1dbd43a8f0 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -14,6 +14,7 @@ config ARM
 	select PBL_RELOCATABLE
 	select USE_COMPRESSED_DTB
 	select HAVE_ARCH_BOARD_GENERIC_DT if OFDEVICE
+	select HAVE_ARCH_BOOTM_OFTREE
 	default y
 
 config ARCH_LINUX_NAME
diff --git a/arch/kvx/Kconfig b/arch/kvx/Kconfig
index bb662e4fd8a5..987fdb2e1e89 100644
--- a/arch/kvx/Kconfig
+++ b/arch/kvx/Kconfig
@@ -4,6 +4,7 @@ config KVX
 	bool
 	select 64BIT
 	select BOOTM
+	select HAVE_ARCH_BOOTM_OFTREE
 	select BOOTM_OFTREE
 	select BOOTM_INITRD
 	select COMMON_CLK
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 43c493978c8f..44c4fc82ae5b 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -12,6 +12,7 @@ config MIPS
 	select ARCH_HAS_DATA_ABORT_MASK
 	select ARCH_HAS_SJLJ
 	select ELF
+	select HAVE_ARCH_BOOTM_OFTREE
 	default y
 
 config ARCH_LINUX_NAME
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 4e282bc3ac80..49050a26d524 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -7,6 +7,7 @@ config PPC
 	select HAS_MODULES
 	select GENERIC_FIND_NEXT_BIT
 	select OFTREE
+	select HAVE_ARCH_BOOTM_OFTREE
 	select ARCH_HAS_SJLJ
 	default y
 
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index 4d56e55b533f..96d013d8514a 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -18,6 +18,7 @@ config RISCV
 	select RISCV_TIMER if RISCV_SBI
 	select HW_HAS_PCI
 	select HAVE_ARCH_BOARD_GENERIC_DT
+	select HAVE_ARCH_BOOTM_OFTREE
 
 config ARCH_LINUX_NAME
 	string
diff --git a/arch/sandbox/Kconfig b/arch/sandbox/Kconfig
index c404f73a9970..b48eb29c7db4 100644
--- a/arch/sandbox/Kconfig
+++ b/arch/sandbox/Kconfig
@@ -20,6 +20,7 @@ config SANDBOX
 	select ARCH_DMA_DEFAULT_COHERENT
 	select ARCH_WANT_FRAME_POINTERS
 	select BAREBOX_CMDLINE
+	select HAVE_ARCH_BOOTM_OFTREE
 	default y
 
 config ARCH_LINUX_NAME
diff --git a/arch/x86/configs/efi_defconfig b/arch/x86/configs/efi_defconfig
index 57e1080195c2..c7bdbcd5640c 100644
--- a/arch/x86/configs/efi_defconfig
+++ b/arch/x86/configs/efi_defconfig
@@ -9,7 +9,6 @@ CONFIG_MENU=y
 CONFIG_BOOTM_SHOW_TYPE=y
 CONFIG_BOOTM_VERBOSE=y
 CONFIG_BOOTM_INITRD=y
-CONFIG_BOOTM_OFTREE=y
 CONFIG_BLSPEC=y
 CONFIG_CONSOLE_ACTIVATE_ALL=y
 CONFIG_PARTITION_DISK_EFI=y
diff --git a/common/Kconfig b/common/Kconfig
index fe50da8f3084..86a651661c35 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -633,7 +633,7 @@ config BOOTM_INITRD
 
 config BOOTM_OFTREE
 	bool
-	depends on BOOTM
+	depends on BOOTM && HAVE_ARCH_BOOTM_OFTREE
 	select OFTREE
 	prompt "device tree (oftree) support"
 	help
-- 
2.39.5




^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 02/10] bootm: enable CONFIG_BOOTM_OFTREE by default
  2025-05-28 10:50 [PATCH 00/10] ARM32: allow disabling ATAGS and DT fallback Ahmad Fatoum
  2025-05-28 10:50 ` [PATCH 01/10] arch: add new HAVE_ARCH_BOOTM_OFTREE symbol Ahmad Fatoum
@ 2025-05-28 10:50 ` Ahmad Fatoum
  2025-05-28 10:50 ` [PATCH 03/10] ARM: lib32: disable ATAGS support " Ahmad Fatoum
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Ahmad Fatoum @ 2025-05-28 10:50 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

All pltforms that have HAVE_ARCH_BOOTM_OFTREE selected, should probably
support booting kernels with a device tree enabled.
CONFIG_BOOTM_OFTREE does that, but only indirectly via selecting OFTREE.
Many architectures and boards already select OFTREE and thus can keep
CONFIG_BOOTM_OFTREE unselected undermining its function.

Make CONFIG_BOOTM_OFTREE the default now, so we could at some point in
the future actually require it for bootm -o as it was meant to.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/Kconfig b/common/Kconfig
index 86a651661c35..0a7d9aee3abe 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -632,7 +632,7 @@ config BOOTM_INITRD
 	  -L ADDR    specify initrd load address
 
 config BOOTM_OFTREE
-	bool
+	def_bool y
 	depends on BOOTM && HAVE_ARCH_BOOTM_OFTREE
 	select OFTREE
 	prompt "device tree (oftree) support"
-- 
2.39.5




^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 03/10] ARM: lib32: disable ATAGS support by default
  2025-05-28 10:50 [PATCH 00/10] ARM32: allow disabling ATAGS and DT fallback Ahmad Fatoum
  2025-05-28 10:50 ` [PATCH 01/10] arch: add new HAVE_ARCH_BOOTM_OFTREE symbol Ahmad Fatoum
  2025-05-28 10:50 ` [PATCH 02/10] bootm: enable CONFIG_BOOTM_OFTREE by default Ahmad Fatoum
@ 2025-05-28 10:50 ` Ahmad Fatoum
  2025-05-28 10:50 ` [PATCH 04/10] kvx: bootm: enforce existence of device tree Ahmad Fatoum
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Ahmad Fatoum @ 2025-05-28 10:50 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We haven't had any new platforms with ATAGS for many years, so it's
about time we make the support configurable and disable it by default.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 .../migration-guides/migration-2025.07.0.rst  |   7 +
 arch/arm/Kconfig                              |  12 +-
 arch/arm/configs/animeo_ip_defconfig          |   1 +
 arch/arm/configs/at91rm9200ek_defconfig       |   1 +
 arch/arm/configs/at91sam9260ek_defconfig      |   1 +
 .../configs/at91sam9261ek_bootstrap_defconfig |   1 +
 arch/arm/configs/at91sam9261ek_defconfig      |   1 +
 arch/arm/configs/at91sam9g10ek_defconfig      |   1 +
 arch/arm/configs/at91sam9g20ek_defconfig      |   1 +
 arch/arm/configs/at91sam9m10g45ek_defconfig   |   1 +
 arch/arm/configs/at91sam9m10ihd_defconfig     |   1 +
 arch/arm/configs/at91sam9n12ek_defconfig      |   1 +
 arch/arm/configs/dss11_defconfig              |   1 +
 arch/arm/configs/haba_knx_lite_defconfig      |   1 +
 arch/arm/configs/imx23_defconfig              |   1 +
 arch/arm/configs/imx28_defconfig              |   1 +
 arch/arm/configs/kindle-mx50_defconfig        |   1 +
 arch/arm/configs/multi_v5_v6_defconfig        |   1 +
 arch/arm/configs/mvebu_defconfig              |   1 +
 arch/arm/configs/omap_defconfig               |   1 +
 arch/arm/configs/pm9261_defconfig             |   1 +
 arch/arm/configs/pm9263_defconfig             |   1 +
 arch/arm/configs/pm9g45_defconfig             |   1 +
 arch/arm/configs/qil_a9260_defconfig          |   1 +
 arch/arm/configs/qil_a9g20_defconfig          |   1 +
 arch/arm/configs/rockchip_v7a_defconfig       |   1 +
 arch/arm/configs/telit_evk_pro3_defconfig     |   1 +
 arch/arm/configs/tny_a9260_defconfig          |   1 +
 .../arm/configs/tny_a9263_bootstrap_defconfig |   1 +
 arch/arm/configs/tny_a9263_defconfig          |   1 +
 arch/arm/configs/tny_a9g20_defconfig          |   1 +
 arch/arm/configs/usb_a9260_defconfig          |   1 +
 .../arm/configs/usb_a9263_bootstrap_defconfig |   1 +
 arch/arm/configs/usb_a9263_defconfig          |   1 +
 arch/arm/configs/usb_a9g20_defconfig          |   1 +
 arch/arm/include/asm/armlinux.h               |  25 +-
 arch/arm/lib32/Makefile                       |   1 +
 arch/arm/lib32/armlinux.c                     | 234 +-----------------
 arch/arm/lib32/atags.c                        | 230 +++++++++++++++++
 arch/arm/mach-imx/Kconfig                     |   1 +
 40 files changed, 319 insertions(+), 224 deletions(-)
 create mode 100644 arch/arm/lib32/atags.c

diff --git a/Documentation/migration-guides/migration-2025.07.0.rst b/Documentation/migration-guides/migration-2025.07.0.rst
index 55f0baef6550..896d2552e9ea 100644
--- a/Documentation/migration-guides/migration-2025.07.0.rst
+++ b/Documentation/migration-guides/migration-2025.07.0.rst
@@ -1,2 +1,9 @@
 Release v2025.07.0
 ==================
+
+Configuration options
+---------------------
+
+* The legacy ARM 32-bit ATAGS mechanism is now disabled by default.
+  It can be re-enabled using the newly added ``CONFIG_BOOT_ATAGS`` option.
+  Use of ATAGS is deprecated. Users should migrate to OpenFirmware device trees.
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 0b1dbd43a8f0..48ed6773cd86 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -328,7 +328,7 @@ config THUMB2_BAREBOX
 
 config ARM_BOARD_APPEND_ATAG
 	bool "Let board specific code to add ATAGs to be passed to the kernel"
-	depends on ARM_LINUX && !CPU_V8
+	depends on BOOT_ATAGS
 	help
 	  This option is purely to start some vendor provided kernels.
 	  ** DO NOT USE FOR YOUR OWN DESIGNS! **
@@ -468,6 +468,16 @@ config ARM_MODULE_PLTS
 	  Say y if your memory configuration puts the heap to far away from the
 	  barebox image, causing relocation out of range errors
 
+config BOOT_ATAGS
+	bool "Support booting with legacy ATAGS mechanism"
+	depends on ARM_LINUX && ARM32
+	help
+	  Add support for passing hardware information with the legacy ATAGS
+	  mechanism that preceded OpenFirmware device trees.
+
+	  Unless you have a very old kernel, say n here and enable BOOTM_OFTREE
+	  instead.
+
 config ARM_BOOTM_ELF
 	bool
 	depends on BOOTM
diff --git a/arch/arm/configs/animeo_ip_defconfig b/arch/arm/configs/animeo_ip_defconfig
index 90e0c72a06b0..864721be93b2 100644
--- a/arch/arm/configs/animeo_ip_defconfig
+++ b/arch/arm/configs/animeo_ip_defconfig
@@ -1,6 +1,7 @@
 CONFIG_ARCH_AT91=y
 CONFIG_ARCH_AT91SAM9260=y
 CONFIG_AEABI=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_MMU=y
 CONFIG_BAREBOX_MAX_IMAGE_SIZE=0x40000
diff --git a/arch/arm/configs/at91rm9200ek_defconfig b/arch/arm/configs/at91rm9200ek_defconfig
index 34dc4058ba29..665b5b80ef8e 100644
--- a/arch/arm/configs/at91rm9200ek_defconfig
+++ b/arch/arm/configs/at91rm9200ek_defconfig
@@ -1,4 +1,5 @@
 CONFIG_ARCH_AT91=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_MMU=y
 CONFIG_BAREBOX_MAX_IMAGE_SIZE=0x40000
diff --git a/arch/arm/configs/at91sam9260ek_defconfig b/arch/arm/configs/at91sam9260ek_defconfig
index db5d8d6652a0..1ea33a116065 100644
--- a/arch/arm/configs/at91sam9260ek_defconfig
+++ b/arch/arm/configs/at91sam9260ek_defconfig
@@ -2,6 +2,7 @@ CONFIG_ARCH_AT91=y
 CONFIG_ARCH_AT91SAM9260=y
 CONFIG_MACH_AT91SAM9260EK=y
 CONFIG_AEABI=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_MMU=y
 CONFIG_BAREBOX_MAX_IMAGE_SIZE=0x40000
diff --git a/arch/arm/configs/at91sam9261ek_bootstrap_defconfig b/arch/arm/configs/at91sam9261ek_bootstrap_defconfig
index 3811594b1a63..09cc5b23ed47 100644
--- a/arch/arm/configs/at91sam9261ek_bootstrap_defconfig
+++ b/arch/arm/configs/at91sam9261ek_bootstrap_defconfig
@@ -2,6 +2,7 @@ CONFIG_ARCH_AT91=y
 CONFIG_ARCH_AT91SAM9261=y
 CONFIG_AT91_BOOTSTRAP=y
 CONFIG_AEABI=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_MMU=y
 CONFIG_BAREBOX_MAX_IMAGE_SIZE=0x27000
diff --git a/arch/arm/configs/at91sam9261ek_defconfig b/arch/arm/configs/at91sam9261ek_defconfig
index bf0df025e3b5..ad37108b31f2 100644
--- a/arch/arm/configs/at91sam9261ek_defconfig
+++ b/arch/arm/configs/at91sam9261ek_defconfig
@@ -1,6 +1,7 @@
 CONFIG_ARCH_AT91=y
 CONFIG_ARCH_AT91SAM9261=y
 CONFIG_AEABI=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_MMU=y
 CONFIG_BAREBOX_MAX_IMAGE_SIZE=0x40000
diff --git a/arch/arm/configs/at91sam9g10ek_defconfig b/arch/arm/configs/at91sam9g10ek_defconfig
index 02432f2971f4..d92047683a4c 100644
--- a/arch/arm/configs/at91sam9g10ek_defconfig
+++ b/arch/arm/configs/at91sam9g10ek_defconfig
@@ -1,6 +1,7 @@
 CONFIG_ARCH_AT91=y
 CONFIG_ARCH_AT91SAM9G10=y
 CONFIG_AEABI=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_MMU=y
 CONFIG_BAREBOX_MAX_IMAGE_SIZE=0x40000
diff --git a/arch/arm/configs/at91sam9g20ek_defconfig b/arch/arm/configs/at91sam9g20ek_defconfig
index 99dce447638d..7200f7a5b8ce 100644
--- a/arch/arm/configs/at91sam9g20ek_defconfig
+++ b/arch/arm/configs/at91sam9g20ek_defconfig
@@ -2,6 +2,7 @@ CONFIG_ARCH_AT91=y
 CONFIG_ARCH_AT91SAM9G20=y
 CONFIG_AT91_HAVE_2MMC=y
 CONFIG_AEABI=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_MMU=y
 CONFIG_BAREBOX_MAX_IMAGE_SIZE=0x40000
diff --git a/arch/arm/configs/at91sam9m10g45ek_defconfig b/arch/arm/configs/at91sam9m10g45ek_defconfig
index 17248c6504c3..d4988e58284d 100644
--- a/arch/arm/configs/at91sam9m10g45ek_defconfig
+++ b/arch/arm/configs/at91sam9m10g45ek_defconfig
@@ -2,6 +2,7 @@ CONFIG_ARCH_AT91=y
 CONFIG_ARCH_AT91SAM9G45=y
 CONFIG_MACH_AT91SAM9M10G45EK=y
 CONFIG_AEABI=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_MMU=y
 CONFIG_BAREBOX_MAX_IMAGE_SIZE=0x40000
diff --git a/arch/arm/configs/at91sam9m10ihd_defconfig b/arch/arm/configs/at91sam9m10ihd_defconfig
index be0a539f3eb9..f50025375f45 100644
--- a/arch/arm/configs/at91sam9m10ihd_defconfig
+++ b/arch/arm/configs/at91sam9m10ihd_defconfig
@@ -1,6 +1,7 @@
 CONFIG_ARCH_AT91=y
 CONFIG_ARCH_AT91SAM9G45=y
 CONFIG_AEABI=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_MMU=y
 CONFIG_BAREBOX_MAX_IMAGE_SIZE=0x40000
diff --git a/arch/arm/configs/at91sam9n12ek_defconfig b/arch/arm/configs/at91sam9n12ek_defconfig
index 8e6439aa7cad..4ef07dba2c94 100644
--- a/arch/arm/configs/at91sam9n12ek_defconfig
+++ b/arch/arm/configs/at91sam9n12ek_defconfig
@@ -2,6 +2,7 @@ CONFIG_TEXT_BASE=0x26f00000
 CONFIG_ARCH_AT91=y
 CONFIG_ARCH_AT91SAM9N12=y
 CONFIG_AEABI=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_IMAGE_COMPRESSION_XZKERN=y
 CONFIG_MMU=y
diff --git a/arch/arm/configs/dss11_defconfig b/arch/arm/configs/dss11_defconfig
index ecab7a6b14c9..af37fc0681a8 100644
--- a/arch/arm/configs/dss11_defconfig
+++ b/arch/arm/configs/dss11_defconfig
@@ -1,6 +1,7 @@
 CONFIG_ARCH_AT91=y
 CONFIG_ARCH_AT91SAM9G20=y
 CONFIG_MACH_DSS11=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_MTD_NAND_ATMEL_BUSWIDTH_16=y
 CONFIG_CMDLINE_EDITING=y
 CONFIG_AUTO_COMPLETE=y
diff --git a/arch/arm/configs/haba_knx_lite_defconfig b/arch/arm/configs/haba_knx_lite_defconfig
index 2c68ed222aca..7d0201b3481a 100644
--- a/arch/arm/configs/haba_knx_lite_defconfig
+++ b/arch/arm/configs/haba_knx_lite_defconfig
@@ -2,6 +2,7 @@ CONFIG_TEXT_BASE=0x27f00000
 CONFIG_ARCH_AT91=y
 CONFIG_ARCH_AT91SAM9G20=y
 CONFIG_MACH_HABA_KNX_LITE=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_AEABI=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_MMU=y
diff --git a/arch/arm/configs/imx23_defconfig b/arch/arm/configs/imx23_defconfig
index 48bf14a39006..aa47c6089ffc 100644
--- a/arch/arm/configs/imx23_defconfig
+++ b/arch/arm/configs/imx23_defconfig
@@ -4,6 +4,7 @@ CONFIG_MACH_CHUMBY=y
 CONFIG_MACH_IMX233_OLINUXINO=y
 CONFIG_MXS_OCOTP=y
 CONFIG_AEABI=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_ARM_UNWIND=y
 CONFIG_MMU=y
diff --git a/arch/arm/configs/imx28_defconfig b/arch/arm/configs/imx28_defconfig
index 8e66983e3582..a864c05b20d6 100644
--- a/arch/arm/configs/imx28_defconfig
+++ b/arch/arm/configs/imx28_defconfig
@@ -5,6 +5,7 @@ CONFIG_MACH_MX28EVK=y
 CONFIG_MACH_DUCKBILL=y
 CONFIG_MACH_CFA10036=y
 CONFIG_AEABI=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_ARM_UNWIND=y
 CONFIG_MMU=y
diff --git a/arch/arm/configs/kindle-mx50_defconfig b/arch/arm/configs/kindle-mx50_defconfig
index 1ceef8088ace..4694514f549f 100644
--- a/arch/arm/configs/kindle-mx50_defconfig
+++ b/arch/arm/configs/kindle-mx50_defconfig
@@ -1,6 +1,7 @@
 CONFIG_ARCH_IMX=y
 CONFIG_MACH_KINDLE_MX50=y
 CONFIG_THUMB2_BAREBOX=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_ARM_UNWIND=y
 CONFIG_IMAGE_COMPRESSION_XZKERN=y
diff --git a/arch/arm/configs/multi_v5_v6_defconfig b/arch/arm/configs/multi_v5_v6_defconfig
index 7748ec43b0ce..2afc072e129c 100644
--- a/arch/arm/configs/multi_v5_v6_defconfig
+++ b/arch/arm/configs/multi_v5_v6_defconfig
@@ -10,6 +10,7 @@ CONFIG_IMX_IIM=y
 CONFIG_IMX_IIM_FUSE_BLOW=y
 CONFIG_BOARD_GENERIC_DT=y
 CONFIG_AEABI=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_ARM_UNWIND=y
 CONFIG_MMU=y
diff --git a/arch/arm/configs/mvebu_defconfig b/arch/arm/configs/mvebu_defconfig
index 6a436f3abdb7..f446d4b65989 100644
--- a/arch/arm/configs/mvebu_defconfig
+++ b/arch/arm/configs/mvebu_defconfig
@@ -12,6 +12,7 @@ CONFIG_MACH_GLOBALSCALE_GURUPLUG=y
 CONFIG_MACH_PLATHOME_OPENBLOCKS_A6=y
 CONFIG_MACH_USI_TOPKICK=y
 CONFIG_AEABI=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_MMU=y
 CONFIG_MALLOC_SIZE=0x0
diff --git a/arch/arm/configs/omap_defconfig b/arch/arm/configs/omap_defconfig
index 5c86a8f47a8f..a3e7629afab1 100644
--- a/arch/arm/configs/omap_defconfig
+++ b/arch/arm/configs/omap_defconfig
@@ -10,6 +10,7 @@ CONFIG_MACH_PHYTEC_SOM_AM335X=y
 CONFIG_MACH_VSCOM_BALTOS=y
 CONFIG_MACH_WAGO_PFC_AM35XX=y
 CONFIG_THUMB2_BAREBOX=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_ARM_BOARD_APPEND_ATAG=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_ARM_UNWIND=y
diff --git a/arch/arm/configs/pm9261_defconfig b/arch/arm/configs/pm9261_defconfig
index 8e2d21664b8a..f3660b052798 100644
--- a/arch/arm/configs/pm9261_defconfig
+++ b/arch/arm/configs/pm9261_defconfig
@@ -1,6 +1,7 @@
 CONFIG_ARCH_AT91=y
 CONFIG_ARCH_AT91SAM9261=y
 CONFIG_MACH_PM9261=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_PROMPT="PM9261:"
 CONFIG_HUSH_FANCY_PROMPT=y
diff --git a/arch/arm/configs/pm9263_defconfig b/arch/arm/configs/pm9263_defconfig
index 2b7149c058b8..2b0e971e9c52 100644
--- a/arch/arm/configs/pm9263_defconfig
+++ b/arch/arm/configs/pm9263_defconfig
@@ -1,5 +1,6 @@
 CONFIG_ARCH_AT91=y
 CONFIG_ARCH_AT91SAM9263=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_PROMPT_HUSH_PS2="y"
 CONFIG_CMDLINE_EDITING=y
diff --git a/arch/arm/configs/pm9g45_defconfig b/arch/arm/configs/pm9g45_defconfig
index 969dd7a83074..061ea0e70c1b 100644
--- a/arch/arm/configs/pm9g45_defconfig
+++ b/arch/arm/configs/pm9g45_defconfig
@@ -2,6 +2,7 @@ CONFIG_ARCH_AT91=y
 CONFIG_ARCH_AT91SAM9G45=y
 CONFIG_MACH_PM9G45=y
 CONFIG_AEABI=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_MMU=y
 CONFIG_BAREBOX_MAX_IMAGE_SIZE=0x40000
diff --git a/arch/arm/configs/qil_a9260_defconfig b/arch/arm/configs/qil_a9260_defconfig
index 1ed7fc7ede0d..9949a1c785d0 100644
--- a/arch/arm/configs/qil_a9260_defconfig
+++ b/arch/arm/configs/qil_a9260_defconfig
@@ -3,6 +3,7 @@ CONFIG_ARCH_AT91SAM9260=y
 CONFIG_MACH_QIL_A9260=y
 CONFIG_CALAO_MB_QIL_A9260=y
 CONFIG_AEABI=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_MMU=y
 CONFIG_BAREBOX_MAX_IMAGE_SIZE=0x40000
diff --git a/arch/arm/configs/qil_a9g20_defconfig b/arch/arm/configs/qil_a9g20_defconfig
index 19748e355530..0eef133d877e 100644
--- a/arch/arm/configs/qil_a9g20_defconfig
+++ b/arch/arm/configs/qil_a9g20_defconfig
@@ -3,6 +3,7 @@ CONFIG_ARCH_AT91SAM9G20=y
 CONFIG_MACH_QIL_A9G20=y
 CONFIG_CALAO_MB_QIL_A9260=y
 CONFIG_AEABI=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_MMU=y
 CONFIG_BAREBOX_MAX_IMAGE_SIZE=0x40000
diff --git a/arch/arm/configs/rockchip_v7a_defconfig b/arch/arm/configs/rockchip_v7a_defconfig
index 67f5b5e8446f..f69320715695 100644
--- a/arch/arm/configs/rockchip_v7a_defconfig
+++ b/arch/arm/configs/rockchip_v7a_defconfig
@@ -4,6 +4,7 @@ CONFIG_MACH_RADXA_ROCK=y
 CONFIG_MACH_PHYTEC_SOM_RK3288=y
 CONFIG_BOARD_GENERIC_DT=y
 CONFIG_THUMB2_BAREBOX=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_ARM_BOARD_APPEND_ATAG=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_ARM_UNWIND=y
diff --git a/arch/arm/configs/telit_evk_pro3_defconfig b/arch/arm/configs/telit_evk_pro3_defconfig
index 72246f3675cc..ead5c5826929 100644
--- a/arch/arm/configs/telit_evk_pro3_defconfig
+++ b/arch/arm/configs/telit_evk_pro3_defconfig
@@ -2,6 +2,7 @@ CONFIG_ARCH_AT91=y
 CONFIG_ARCH_AT91SAM9260=y
 CONFIG_MACH_GE863=y
 CONFIG_AEABI=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_MMU=y
 CONFIG_BAREBOX_MAX_IMAGE_SIZE=0x40000
diff --git a/arch/arm/configs/tny_a9260_defconfig b/arch/arm/configs/tny_a9260_defconfig
index 72135a7277c8..e7be7ee912f4 100644
--- a/arch/arm/configs/tny_a9260_defconfig
+++ b/arch/arm/configs/tny_a9260_defconfig
@@ -3,6 +3,7 @@ CONFIG_ARCH_AT91SAM9260=y
 CONFIG_MACH_TNY_A9260=y
 CONFIG_CALAO_MOB_TNY_MD2=y
 CONFIG_AEABI=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_MMU=y
 CONFIG_BAREBOX_MAX_IMAGE_SIZE=0x40000
diff --git a/arch/arm/configs/tny_a9263_bootstrap_defconfig b/arch/arm/configs/tny_a9263_bootstrap_defconfig
index 80b42f5f86f1..76c0bd33a0b9 100644
--- a/arch/arm/configs/tny_a9263_bootstrap_defconfig
+++ b/arch/arm/configs/tny_a9263_bootstrap_defconfig
@@ -2,6 +2,7 @@ CONFIG_ARCH_AT91=y
 CONFIG_ARCH_AT91SAM9263=y
 CONFIG_MACH_TNY_A9263=y
 CONFIG_AEABI=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_ENVIRONMENT_VARIABLES=y
 CONFIG_MMU=y
diff --git a/arch/arm/configs/tny_a9263_defconfig b/arch/arm/configs/tny_a9263_defconfig
index e0448cf187ab..f33d08c331d9 100644
--- a/arch/arm/configs/tny_a9263_defconfig
+++ b/arch/arm/configs/tny_a9263_defconfig
@@ -3,6 +3,7 @@ CONFIG_ARCH_AT91SAM9263=y
 CONFIG_MACH_TNY_A9263=y
 CONFIG_CALAO_MOB_TNY_MD2=y
 CONFIG_AEABI=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_MMU=y
 CONFIG_BAREBOX_MAX_IMAGE_SIZE=0x40000
diff --git a/arch/arm/configs/tny_a9g20_defconfig b/arch/arm/configs/tny_a9g20_defconfig
index 52bbae67d9f7..d404b12b3d93 100644
--- a/arch/arm/configs/tny_a9g20_defconfig
+++ b/arch/arm/configs/tny_a9g20_defconfig
@@ -3,6 +3,7 @@ CONFIG_ARCH_AT91SAM9G20=y
 CONFIG_MACH_TNY_A9G20=y
 CONFIG_CALAO_MOB_TNY_MD2=y
 CONFIG_AEABI=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_MMU=y
 CONFIG_BAREBOX_MAX_IMAGE_SIZE=0x40000
diff --git a/arch/arm/configs/usb_a9260_defconfig b/arch/arm/configs/usb_a9260_defconfig
index 47d0c633bbf0..fddced5ef0e7 100644
--- a/arch/arm/configs/usb_a9260_defconfig
+++ b/arch/arm/configs/usb_a9260_defconfig
@@ -2,6 +2,7 @@ CONFIG_ARCH_AT91=y
 CONFIG_ARCH_AT91SAM9260=y
 CONFIG_MACH_USB_A9260=y
 CONFIG_AEABI=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_MMU=y
 CONFIG_BAREBOX_MAX_IMAGE_SIZE=0x40000
diff --git a/arch/arm/configs/usb_a9263_bootstrap_defconfig b/arch/arm/configs/usb_a9263_bootstrap_defconfig
index 2adf1143891e..9df009d65b8e 100644
--- a/arch/arm/configs/usb_a9263_bootstrap_defconfig
+++ b/arch/arm/configs/usb_a9263_bootstrap_defconfig
@@ -3,6 +3,7 @@ CONFIG_ARCH_AT91SAM9263=y
 CONFIG_MACH_USB_A9263=y
 CONFIG_AT91_BOOTSTRAP=y
 CONFIG_AEABI=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_ENVIRONMENT_VARIABLES=y
 CONFIG_MMU=y
diff --git a/arch/arm/configs/usb_a9263_defconfig b/arch/arm/configs/usb_a9263_defconfig
index 51494ad71284..1656ff4176b6 100644
--- a/arch/arm/configs/usb_a9263_defconfig
+++ b/arch/arm/configs/usb_a9263_defconfig
@@ -2,6 +2,7 @@ CONFIG_ARCH_AT91=y
 CONFIG_ARCH_AT91SAM9263=y
 CONFIG_MACH_USB_A9263=y
 CONFIG_AEABI=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_MMU=y
 CONFIG_BAREBOX_MAX_IMAGE_SIZE=0x40000
diff --git a/arch/arm/configs/usb_a9g20_defconfig b/arch/arm/configs/usb_a9g20_defconfig
index 56f78ba7a809..36c5203d5162 100644
--- a/arch/arm/configs/usb_a9g20_defconfig
+++ b/arch/arm/configs/usb_a9g20_defconfig
@@ -2,6 +2,7 @@ CONFIG_ARCH_AT91=y
 CONFIG_ARCH_AT91SAM9G20=y
 CONFIG_MACH_USB_A9G20=y
 CONFIG_AEABI=y
+CONFIG_BOOT_ATAGS=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_MMU=y
 CONFIG_BAREBOX_MAX_IMAGE_SIZE=0x40000
diff --git a/arch/arm/include/asm/armlinux.h b/arch/arm/include/asm/armlinux.h
index c648ef3d78d0..871664824643 100644
--- a/arch/arm/include/asm/armlinux.h
+++ b/arch/arm/include/asm/armlinux.h
@@ -6,21 +6,38 @@
 #include <asm/memory.h>
 #include <asm/setup.h>
 #include <asm/secure.h>
+#include <linux/bug.h>
 
-#if defined CONFIG_ARM_LINUX && defined CONFIG_CPU_32
+struct tag;
+
+#if defined CONFIG_BOOT_ATAGS
 void armlinux_set_bootparams(void *params);
+struct tag *armlinux_get_bootparams(void);
 void armlinux_set_architecture(unsigned architecture);
+unsigned armlinux_get_architecture(void);
 void armlinux_set_revision(unsigned int);
 void armlinux_set_serial(u64);
+void armlinux_setup_tags(unsigned long initrd_address,
+			 unsigned long initrd_size, int swap);
 #else
 static inline void armlinux_set_bootparams(void *params)
 {
 }
 
+static inline struct tag *armlinux_get_bootparams(void)
+{
+	BUG();
+}
+
 static inline void armlinux_set_architecture(unsigned architecture)
 {
 }
 
+static inline unsigned armlinux_get_architecture(void)
+{
+	return 0;
+}
+
 static inline void armlinux_set_revision(unsigned int rev)
 {
 }
@@ -28,8 +45,12 @@ static inline void armlinux_set_revision(unsigned int rev)
 static inline void armlinux_set_serial(u64 serial)
 {
 }
-#endif
 
+static inline void armlinux_setup_tags(unsigned long initrd_address,
+				       unsigned long initrd_size, int swap)
+{
+}
+#endif
 #if defined CONFIG_ARM_BOARD_APPEND_ATAG
 void armlinux_set_atag_appender(struct tag *(*)(struct tag *));
 #else
diff --git a/arch/arm/lib32/Makefile b/arch/arm/lib32/Makefile
index a139a80fb849..f76010e93350 100644
--- a/arch/arm/lib32/Makefile
+++ b/arch/arm/lib32/Makefile
@@ -5,6 +5,7 @@ obj-$(CONFIG_CMD_BOOTZ)	+= bootz.o
 obj-$(CONFIG_BOOTM)     += bootm.o
 obj-$(CONFIG_BOOTM_OPTEE) += start-kernel-optee.o
 obj-$(CONFIG_CMD_BOOTU) += bootu.o
+obj-$(CONFIG_BOOT_ATAGS) += atags.o
 obj-y	+= div0.o
 obj-y	+= findbit.o
 obj-y	+= io.o
diff --git a/arch/arm/lib32/armlinux.c b/arch/arm/lib32/armlinux.c
index 56f278d3dbae..6890d9cb6fda 100644
--- a/arch/arm/lib32/armlinux.c
+++ b/arch/arm/lib32/armlinux.c
@@ -28,224 +28,6 @@
 #include <asm/secure.h>
 #include <asm/boot.h>
 
-static struct tag *params;
-static void *armlinux_bootparams = NULL;
-
-static unsigned armlinux_architecture;
-static u32 armlinux_system_rev;
-static u64 armlinux_system_serial;
-
-BAREBOX_MAGICVAR(armlinux_architecture, "ARM machine ID");
-BAREBOX_MAGICVAR(armlinux_system_rev, "ARM system revision");
-BAREBOX_MAGICVAR(armlinux_system_serial, "ARM system serial");
-
-void armlinux_set_architecture(unsigned architecture)
-{
-	export_env_ull("armlinux_architecture", architecture);
-	armlinux_architecture = architecture;
-}
-
-static unsigned armlinux_get_architecture(void)
-{
-	getenv_uint("armlinux_architecture", &armlinux_architecture);
-
-	return armlinux_architecture;
-}
-
-void armlinux_set_revision(unsigned int rev)
-{
-	export_env_ull("armlinux_system_rev", rev);
-	armlinux_system_rev = rev;
-}
-
-static unsigned int armlinux_get_revision(void)
-{
-	getenv_uint("armlinux_system_rev", &armlinux_system_rev);
-
-	return armlinux_system_rev;
-}
-
-void armlinux_set_serial(u64 serial)
-{
-	export_env_ull("armlinux_system_serial", serial);
-	armlinux_system_serial = serial;
-}
-
-static u64 armlinux_get_serial(void)
-{
-	getenv_ull("armlinux_system_serial", &armlinux_system_serial);
-
-	return armlinux_system_serial;
-}
-
-void armlinux_set_bootparams(void *params)
-{
-	armlinux_bootparams = params;
-}
-
-static struct tag *armlinux_get_bootparams(void)
-{
-	struct memory_bank *mem;
-
-	if (armlinux_bootparams)
-		return armlinux_bootparams;
-
-	for_each_memory_bank(mem)
-		return (void *)mem->start + 0x100;
-
-	BUG();
-}
-
-static struct tag *(*atag_appender)(struct tag *);
-
-#if defined CONFIG_ARM_BOARD_APPEND_ATAG
-void armlinux_set_atag_appender(struct tag *(*func)(struct tag *))
-{
-	atag_appender = func;
-}
-#endif
-
-static void setup_start_tag(void)
-{
-	params = armlinux_get_bootparams();
-
-	params->hdr.tag = ATAG_CORE;
-	params->hdr.size = tag_size(tag_core);
-
-	params->u.core.flags = 0;
-	params->u.core.pagesize = 0;
-	params->u.core.rootdev = 0;
-
-	params = tag_next(params);
-}
-
-static void setup_memory_tags(void)
-{
-	struct memory_bank *bank;
-
-	for_each_memory_bank(bank) {
-		params->hdr.tag = ATAG_MEM;
-		params->hdr.size = tag_size(tag_mem32);
-
-		params->u.mem.start = bank->start;
-		params->u.mem.size = bank->size;
-
-		params = tag_next(params);
-	}
-}
-
-static void setup_commandline_tag(const char *commandline, int swap)
-{
-	const char *p;
-	size_t words;
-
-	if (!commandline)
-		return;
-
-	/* eat leading white space */
-	for (p = commandline; *p == ' '; p++) ;
-
-	/*
-	 * skip non-existent command lines so the kernel will still
-	 * use its default command line.
-	 */
-	if (*p == '\0')
-		return;
-
-	words = (strlen(p) + 1 /* NUL */ + 3 /* round up */) >> 2;
-	params->hdr.tag = ATAG_CMDLINE;
-	params->hdr.size = (sizeof(struct tag_header) >> 2) + words;
-
-	strcpy(params->u.cmdline.cmdline, p);
-
-#ifdef CONFIG_BOOT_ENDIANNESS_SWITCH
-	if (swap) {
-		u32 *cmd = (u32 *)params->u.cmdline.cmdline;
-		while (words--)
-			cmd[words] = swab32(cmd[words]);
-	}
-#endif
-
-	params = tag_next(params);
-}
-
-static void setup_revision_tag(void)
-{
-	u32 system_rev = armlinux_get_revision();
-
-	if (system_rev) {
-		params->hdr.tag = ATAG_REVISION;
-		params->hdr.size = tag_size(tag_revision);
-
-		params->u.revision.rev = system_rev;
-
-		params = tag_next(params);
-	}
-}
-
-static void setup_serial_tag(void)
-{
-	u64 system_serial = armlinux_get_serial();
-
-	if (system_serial) {
-		params->hdr.tag = ATAG_SERIAL;
-		params->hdr.size = tag_size(tag_serialnr);
-
-		params->u.serialnr.low  = system_serial & 0xffffffff;
-		params->u.serialnr.high = system_serial >> 32;
-
-		params = tag_next(params);
-	}
-}
-
-static void setup_initrd_tag(unsigned long start, unsigned long size)
-{
-	/* an ATAG_INITRD node tells the kernel where the compressed
-	 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
-	 */
-	params->hdr.tag = ATAG_INITRD2;
-	params->hdr.size = tag_size(tag_initrd);
-
-	params->u.initrd.start = start;
-	params->u.initrd.size = size;
-
-	params = tag_next(params);
-}
-
-static void setup_end_tag (void)
-{
-	params->hdr.tag = ATAG_NONE;
-	params->hdr.size = 0;
-}
-
-static void setup_tags(unsigned long initrd_address,
-		unsigned long initrd_size, int swap)
-{
-	const char *commandline = linux_bootargs_get();
-
-	setup_start_tag();
-	if (IS_ENABLED(CONFIG_ARM_BOARD_PREPEND_ATAG) && atag_appender)
-		params = atag_appender(params);
-
-	setup_memory_tags();
-	setup_commandline_tag(commandline, swap);
-
-	if (initrd_size)
-		setup_initrd_tag(initrd_address, initrd_size);
-
-	setup_revision_tag();
-	setup_serial_tag();
-	if (IS_ENABLED(CONFIG_ARM_BOARD_APPEND_ATAG) && atag_appender &&
-			!IS_ENABLED(CONFIG_ARM_BOARD_PREPEND_ATAG))
-		params = atag_appender(params);
-
-	setup_end_tag();
-
-	printf("commandline: %s\n"
-	       "arch_number: %u\n", commandline, armlinux_get_architecture());
-
-}
-
 void start_kernel_optee(void *optee, void *kernel, void *oftree);
 
 void start_linux(void *adr, int swap, unsigned long initrd_address,
@@ -265,15 +47,25 @@ void start_linux(void *adr, int swap, unsigned long initrd_address,
 	if (oftree) {
 		pr_debug("booting kernel with devicetree\n");
 		params = virt_to_phys(oftree);
-	} else {
+		architecture = ~0;
+	} else if (IS_ENABLED(CONFIG_BOOT_ATAGS)) {
+		pr_debug("booting kernel with ATAGS\n");
+
 		params = virt_to_phys(armlinux_get_bootparams());
 
 		if (params < PAGE_SIZE)
 			zero_page_access();
 
-		setup_tags(initrd_address, initrd_size, swap);
+		armlinux_setup_tags(initrd_address, initrd_size, swap);
+		architecture = armlinux_get_architecture();
+	} else {
+		static struct tag dummy = {
+			.hdr.tag = ATAG_NONE, .hdr.size = 0
+		};
+		params = virt_to_phys(&dummy);
+		architecture = 0;
+		pr_debug("booting kernel without external device tree\n");
 	}
-	architecture = armlinux_get_architecture();
 
 	shutdown_barebox();
 
diff --git a/arch/arm/lib32/atags.c b/arch/arm/lib32/atags.c
new file mode 100644
index 000000000000..d567a13563b6
--- /dev/null
+++ b/arch/arm/lib32/atags.c
@@ -0,0 +1,230 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+// SPDX-FileCopyrightText: 2002 Sysgo Real-Time Solutions GmbH (http://www.elinos.com, Marius Groeger <mgroeger@sysgo.de>)
+// SPDX-FileCopyrightText: 2001 Erik Mouw <J.A.K.Mouw@its.tudelft.nl>
+
+#include <bootargs.h>
+#include <common.h>
+#include <environment.h>
+#include <xfuncs.h>
+#include <magicvar.h>
+
+#include <asm/setup.h>
+#include <asm/armlinux.h>
+
+static struct tag *params;
+static void *armlinux_bootparams = NULL;
+
+static unsigned armlinux_architecture;
+static u32 armlinux_system_rev;
+static u64 armlinux_system_serial;
+
+BAREBOX_MAGICVAR(armlinux_architecture, "ARM machine ID");
+BAREBOX_MAGICVAR(armlinux_system_rev, "ARM system revision");
+BAREBOX_MAGICVAR(armlinux_system_serial, "ARM system serial");
+
+void armlinux_set_architecture(unsigned architecture)
+{
+	export_env_ull("armlinux_architecture", architecture);
+	armlinux_architecture = architecture;
+}
+
+unsigned armlinux_get_architecture(void)
+{
+	getenv_uint("armlinux_architecture", &armlinux_architecture);
+
+	return armlinux_architecture;
+}
+
+void armlinux_set_revision(unsigned int rev)
+{
+	export_env_ull("armlinux_system_rev", rev);
+	armlinux_system_rev = rev;
+}
+
+static unsigned int armlinux_get_revision(void)
+{
+	getenv_uint("armlinux_system_rev", &armlinux_system_rev);
+
+	return armlinux_system_rev;
+}
+
+void armlinux_set_serial(u64 serial)
+{
+	export_env_ull("armlinux_system_serial", serial);
+	armlinux_system_serial = serial;
+}
+
+static u64 armlinux_get_serial(void)
+{
+	getenv_ull("armlinux_system_serial", &armlinux_system_serial);
+
+	return armlinux_system_serial;
+}
+
+void armlinux_set_bootparams(void *params)
+{
+	armlinux_bootparams = params;
+}
+
+struct tag *armlinux_get_bootparams(void)
+{
+	struct memory_bank *mem;
+
+	if (armlinux_bootparams)
+		return armlinux_bootparams;
+
+	for_each_memory_bank(mem)
+		return (void *)mem->start + 0x100;
+
+	BUG();
+}
+
+static struct tag *(*atag_appender)(struct tag *);
+
+#if defined CONFIG_ARM_BOARD_APPEND_ATAG
+void armlinux_set_atag_appender(struct tag *(*func)(struct tag *))
+{
+	atag_appender = func;
+}
+#endif
+
+static void setup_start_tag(void)
+{
+	params = armlinux_get_bootparams();
+
+	params->hdr.tag = ATAG_CORE;
+	params->hdr.size = tag_size(tag_core);
+
+	params->u.core.flags = 0;
+	params->u.core.pagesize = 0;
+	params->u.core.rootdev = 0;
+
+	params = tag_next(params);
+}
+
+static void setup_memory_tags(void)
+{
+	struct memory_bank *bank;
+
+	for_each_memory_bank(bank) {
+		params->hdr.tag = ATAG_MEM;
+		params->hdr.size = tag_size(tag_mem32);
+
+		params->u.mem.start = bank->start;
+		params->u.mem.size = bank->size;
+
+		params = tag_next(params);
+	}
+}
+
+static void setup_commandline_tag(const char *commandline, int swap)
+{
+	const char *p;
+	size_t words;
+
+	if (!commandline)
+		return;
+
+	/* eat leading white space */
+	for (p = commandline; *p == ' '; p++) ;
+
+	/*
+	 * skip non-existent command lines so the kernel will still
+	 * use its default command line.
+	 */
+	if (*p == '\0')
+		return;
+
+	words = (strlen(p) + 1 /* NUL */ + 3 /* round up */) >> 2;
+	params->hdr.tag = ATAG_CMDLINE;
+	params->hdr.size = (sizeof(struct tag_header) >> 2) + words;
+
+	strcpy(params->u.cmdline.cmdline, p);
+
+#ifdef CONFIG_BOOT_ENDIANNESS_SWITCH
+	if (swap) {
+		u32 *cmd = (u32 *)params->u.cmdline.cmdline;
+		while (words--)
+			cmd[words] = swab32(cmd[words]);
+	}
+#endif
+
+	params = tag_next(params);
+}
+
+static void setup_revision_tag(void)
+{
+	u32 system_rev = armlinux_get_revision();
+
+	if (system_rev) {
+		params->hdr.tag = ATAG_REVISION;
+		params->hdr.size = tag_size(tag_revision);
+
+		params->u.revision.rev = system_rev;
+
+		params = tag_next(params);
+	}
+}
+
+static void setup_serial_tag(void)
+{
+	u64 system_serial = armlinux_get_serial();
+
+	if (system_serial) {
+		params->hdr.tag = ATAG_SERIAL;
+		params->hdr.size = tag_size(tag_serialnr);
+
+		params->u.serialnr.low  = system_serial & 0xffffffff;
+		params->u.serialnr.high = system_serial >> 32;
+
+		params = tag_next(params);
+	}
+}
+
+static void setup_initrd_tag(unsigned long start, unsigned long size)
+{
+	/* an ATAG_INITRD node tells the kernel where the compressed
+	 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
+	 */
+	params->hdr.tag = ATAG_INITRD2;
+	params->hdr.size = tag_size(tag_initrd);
+
+	params->u.initrd.start = start;
+	params->u.initrd.size = size;
+
+	params = tag_next(params);
+}
+
+static void setup_end_tag (void)
+{
+	params->hdr.tag = ATAG_NONE;
+	params->hdr.size = 0;
+}
+
+void armlinux_setup_tags(unsigned long initrd_address,
+			 unsigned long initrd_size, int swap)
+{
+	const char *commandline = linux_bootargs_get();
+
+	setup_start_tag();
+	if (IS_ENABLED(CONFIG_ARM_BOARD_PREPEND_ATAG) && atag_appender)
+		params = atag_appender(params);
+
+	setup_memory_tags();
+	setup_commandline_tag(commandline, swap);
+
+	if (initrd_size)
+		setup_initrd_tag(initrd_address, initrd_size);
+
+	setup_revision_tag();
+	setup_serial_tag();
+	if (IS_ENABLED(CONFIG_ARM_BOARD_APPEND_ATAG) && atag_appender &&
+			!IS_ENABLED(CONFIG_ARM_BOARD_PREPEND_ATAG))
+		params = atag_appender(params);
+
+	setup_end_tag();
+
+	printf("commandline: %s\n"
+	       "arch_number: %u\n", commandline, armlinux_get_architecture());
+
+}
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index 552e7227a022..0b233f7b3fe4 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -258,6 +258,7 @@ config MACH_KINDLE_MX50
 	select I2C
 	select I2C_IMX
 	select MFD_MC13XXX
+	select BOOT_ATAGS
 	select ARM_BOARD_APPEND_ATAG
 	select ARM_LINUX
 	select OFTREE
-- 
2.39.5




^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 04/10] kvx: bootm: enforce existence of device tree
  2025-05-28 10:50 [PATCH 00/10] ARM32: allow disabling ATAGS and DT fallback Ahmad Fatoum
                   ` (2 preceding siblings ...)
  2025-05-28 10:50 ` [PATCH 03/10] ARM: lib32: disable ATAGS support " Ahmad Fatoum
@ 2025-05-28 10:50 ` Ahmad Fatoum
  2025-05-28 10:50 ` [PATCH 05/10] bootm: booti: make device tree optional Ahmad Fatoum
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Ahmad Fatoum @ 2025-05-28 10:50 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Later commits will allow users to skip providing a device tree
when an empty file is passed, e.g. /dev/null.

Maintain existing behavior for kvx by translating the NULL return
from bootm_get_devicetree() that indicates this to an error pointer.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/kvx/lib/bootm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/kvx/lib/bootm.c b/arch/kvx/lib/bootm.c
index 33d714e873bc..6eba4054e500 100644
--- a/arch/kvx/lib/bootm.c
+++ b/arch/kvx/lib/bootm.c
@@ -84,6 +84,8 @@ static int do_boot_elf(struct image_data *data, struct elf_image *elf)
 	}
 
 	fdt = bootm_get_devicetree(data);
+	if (!fdt)
+		fdt = ERR_PTR(-EINVAL);
 	if (IS_ERR(fdt)) {
 		printf("Failed to load dtb\n");
 		return PTR_ERR(fdt);
-- 
2.39.5




^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 05/10] bootm: booti: make device tree optional
  2025-05-28 10:50 [PATCH 00/10] ARM32: allow disabling ATAGS and DT fallback Ahmad Fatoum
                   ` (3 preceding siblings ...)
  2025-05-28 10:50 ` [PATCH 04/10] kvx: bootm: enforce existence of device tree Ahmad Fatoum
@ 2025-05-28 10:50 ` Ahmad Fatoum
  2025-05-28 10:50 ` [PATCH 06/10] filetype: add new file type for 0-sized files Ahmad Fatoum
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Ahmad Fatoum @ 2025-05-28 10:50 UTC (permalink / raw)
  To: barebox

In case the user supplied a /dev/null device tree with a follow-up
commit, we want to pass a long a NULL pointer to the booted kernel and
skip all device tree and initrd related work.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 arch/arm/lib64/armlinux.c |  2 +-
 arch/riscv/lib/bootm.c    |  2 +-
 common/booti.c            | 14 ++++++++------
 3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/arch/arm/lib64/armlinux.c b/arch/arm/lib64/armlinux.c
index 13721a71236b..74922cecd9ba 100644
--- a/arch/arm/lib64/armlinux.c
+++ b/arch/arm/lib64/armlinux.c
@@ -11,7 +11,7 @@
 static int do_bootm_linux(struct image_data *data)
 {
 	void *image;
-	phys_addr_t devicetree;
+	phys_addr_t devicetree = 0;
 	int ret;
 
 	image = booti_load_image(data, &devicetree);
diff --git a/arch/riscv/lib/bootm.c b/arch/riscv/lib/bootm.c
index 23ce3873b151..08791458f824 100644
--- a/arch/riscv/lib/bootm.c
+++ b/arch/riscv/lib/bootm.c
@@ -8,7 +8,7 @@
 static int do_bootm_linux(struct image_data *data)
 {
 	void (*fn)(unsigned long a0, unsigned long dtb, unsigned long a2);
-	phys_addr_t devicetree;
+	phys_addr_t devicetree = 0;
 	long hartid = riscv_hartid();
 	int ret;
 
diff --git a/common/booti.c b/common/booti.c
index 40611b8f7228..2d4cb3598737 100644
--- a/common/booti.c
+++ b/common/booti.c
@@ -66,6 +66,12 @@ void *booti_load_image(struct image_data *data, phys_addr_t *oftree)
 		unsigned long devicetree;
 		const struct resource *initrd_res;
 
+		fdt = bootm_get_devicetree(data);
+		if (IS_ERR(fdt))
+			return fdt;
+		if (!fdt)
+			goto out;
+
 		initrd_res = bootm_load_initrd(data, image_end);
 		if (IS_ERR(initrd_res)) {
 			return ERR_CAST(initrd_res);
@@ -76,12 +82,7 @@ void *booti_load_image(struct image_data *data, phys_addr_t *oftree)
 
 		devicetree = image_end;
 
-		fdt = bootm_get_devicetree(data);
-		if (IS_ERR(fdt))
-			return fdt;
-
 		ret = bootm_load_devicetree(data, fdt, devicetree);
-
 		free(fdt);
 
 		if (ret)
@@ -90,8 +91,9 @@ void *booti_load_image(struct image_data *data, phys_addr_t *oftree)
 		*oftree = devicetree;
 	}
 
+out:
 	printf("Loaded kernel to 0x%08lx", kernel);
-	if (oftree)
+	if (oftree && *oftree)
 		printf(", devicetree at %pa", oftree);
 	printf("\n");
 
-- 
2.39.5




^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 06/10] filetype: add new file type for 0-sized files
  2025-05-28 10:50 [PATCH 00/10] ARM32: allow disabling ATAGS and DT fallback Ahmad Fatoum
                   ` (4 preceding siblings ...)
  2025-05-28 10:50 ` [PATCH 05/10] bootm: booti: make device tree optional Ahmad Fatoum
@ 2025-05-28 10:50 ` Ahmad Fatoum
  2025-05-28 10:50 ` [PATCH 07/10] bootm: have bootm_get_devicetree return NULL if passed empty DT Ahmad Fatoum
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Ahmad Fatoum @ 2025-05-28 10:50 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We have commands and functionality like the boot code that so far
accepted either an optional argument or substituted a default in its
place if it's missing. One example is the device tree used during boot,
which is transparently replaced by the barebox internal device tree when
none was specified. To allow forcing a device-tree free boot, /dev/null
can be used in future and code can just check for filetype_empty.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/filetype.c  | 3 ++-
 include/filetype.h | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/common/filetype.c b/common/filetype.c
index a79c8ea77e45..a7bbd8f48534 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -28,6 +28,7 @@ struct filetype_str {
 
 static const struct filetype_str filetype_str[] = {
 	[filetype_unknown] = { "unknown", "unknown" },
+	[filetype_empty] = { "empty", "empty" },
 	[filetype_arm_zimage] = { "ARM Linux zImage", "arm-zimage" },
 	[filetype_lzo_compressed] = { "LZO compressed", "lzo" },
 	[filetype_lz4_compressed] = { "LZ4 compressed", "lz4" },
@@ -510,7 +511,7 @@ int file_name_detect_type_offset(const char *filename, loff_t pos, enum filetype
 	if (ret < 0)
 		goto err_out;
 
-	*type = detect(buf, ret);
+	*type = ret ? detect(buf, ret) : filetype_empty;
 
 	ret = 0;
 err_out:
diff --git a/include/filetype.h b/include/filetype.h
index 5d652f952f5b..e699815975d0 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -11,6 +11,7 @@
  */
 enum filetype {
 	filetype_unknown,
+	filetype_empty,
 	filetype_arm_zimage,
 	filetype_lzo_compressed,
 	filetype_lz4_compressed,
-- 
2.39.5




^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 07/10] bootm: have bootm_get_devicetree return NULL if passed empty DT
  2025-05-28 10:50 [PATCH 00/10] ARM32: allow disabling ATAGS and DT fallback Ahmad Fatoum
                   ` (5 preceding siblings ...)
  2025-05-28 10:50 ` [PATCH 06/10] filetype: add new file type for 0-sized files Ahmad Fatoum
@ 2025-05-28 10:50 ` Ahmad Fatoum
  2025-05-28 10:50 ` [PATCH 08/10] bootm: make fallback to barebox internal tree optional Ahmad Fatoum
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Ahmad Fatoum @ 2025-05-28 10:50 UTC (permalink / raw)
  To: barebox

This will allow users to force boot of an image without passing a device
tree.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 common/bootm.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/common/bootm.c b/common/bootm.c
index 4c5913ffb95c..4aebc8a66abd 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -418,7 +418,8 @@ static bool fitconfig_has_fdt(struct image_data *data)
  * devicetree. It returns a pointer to the allocated devicetree which must be
  * freed after use.
  *
- * Return: pointer to the fixed devicetree or a ERR_PTR() on failure.
+ * Return: pointer to the fixed devicetree, NULL if image_data has an empty DT
+ *         or a ERR_PTR() on failure.
  */
 void *bootm_get_devicetree(struct image_data *data)
 {
@@ -463,6 +464,8 @@ void *bootm_get_devicetree(struct image_data *data)
 			ret = read_file_2(data->oftree_file, &size, (void *)&oftree,
 					  FILESIZE_MAX);
 			break;
+		case filetype_empty:
+			return NULL;
 		default:
 			return ERR_PTR(-EINVAL);
 		}
-- 
2.39.5




^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 08/10] bootm: make fallback to barebox internal tree optional
  2025-05-28 10:50 [PATCH 00/10] ARM32: allow disabling ATAGS and DT fallback Ahmad Fatoum
                   ` (6 preceding siblings ...)
  2025-05-28 10:50 ` [PATCH 07/10] bootm: have bootm_get_devicetree return NULL if passed empty DT Ahmad Fatoum
@ 2025-05-28 10:50 ` Ahmad Fatoum
  2025-05-28 10:50 ` [PATCH 09/10] commands: oftree: add option to return device tree without fixups Ahmad Fatoum
  2025-05-28 10:50 ` [PATCH 10/10] of: drop undefined fdt_get_tree declaration Ahmad Fatoum
  9 siblings, 0 replies; 11+ messages in thread
From: Ahmad Fatoum @ 2025-05-28 10:50 UTC (permalink / raw)
  To: barebox

barebox substituting its own device tree in place of a missing kernel
is often not what the user intended. Add a config option to disable
this, so users notice right away that they didn't supply a kernel device
tree.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 arch/arm/lib32/bootm.c      |  2 +-
 arch/arm/lib32/bootu.c      | 11 ++++++++---
 arch/arm/lib32/bootz.c      |  9 ++++++---
 arch/powerpc/lib/ppclinux.c |  2 +-
 common/Kconfig              | 18 ++++++++++++++++++
 common/bootm.c              |  9 +++------
 include/of.h                | 25 +++++++++++++++++++++++--
 7 files changed, 60 insertions(+), 16 deletions(-)

diff --git a/arch/arm/lib32/bootm.c b/arch/arm/lib32/bootm.c
index 32af112ae8c8..963c83051de0 100644
--- a/arch/arm/lib32/bootm.c
+++ b/arch/arm/lib32/bootm.c
@@ -428,7 +428,7 @@ static int do_bootz_linux_fdt(int fd, struct image_data *data, void **outfdt)
 			pr_err("unable to unflatten devicetree\n");
 			goto err_free;
 		}
-		*outfdt = of_get_fixed_tree(root);
+		*outfdt = of_get_fixed_tree_for_boot(root);
 		if (!*outfdt) {
 			pr_err("Unable to get fixed tree\n");
 			ret = -EINVAL;
diff --git a/arch/arm/lib32/bootu.c b/arch/arm/lib32/bootu.c
index 31c3c56cc597..4b0f495aea5f 100644
--- a/arch/arm/lib32/bootu.c
+++ b/arch/arm/lib32/bootu.c
@@ -1,5 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
 
+#define pr_fmt(fmt) "bootu: " fmt
+
 #include <common.h>
 #include <command.h>
 #include <fs.h>
@@ -24,9 +26,12 @@ static int do_bootu(int argc, char *argv[])
 	if (!kernel)
 		kernel = (void *)simple_strtoul(argv[1], NULL, 0);
 
-#ifdef CONFIG_OFTREE
-	oftree = of_get_fixed_tree(NULL);
-#endif
+	oftree = of_get_fixed_tree_for_boot(NULL);
+	if (!oftree) {
+		pr_err("No devicetree given.\n");
+		return -EINVAL;
+	}
+
 	ret = of_overlay_load_firmware();
 	if (ret)
 		return ret;
diff --git a/arch/arm/lib32/bootz.c b/arch/arm/lib32/bootz.c
index 8e8b0d225ecf..ab275c367711 100644
--- a/arch/arm/lib32/bootz.c
+++ b/arch/arm/lib32/bootz.c
@@ -110,9 +110,12 @@ static int do_bootz(int argc, char *argv[])
 	}
 
 	printf("loaded zImage from %s with size %d\n", argv[1], end);
-#ifdef CONFIG_OFTREE
-	oftree = of_get_fixed_tree(NULL);
-#endif
+	oftree = of_get_fixed_tree_for_boot(NULL);
+	if (!oftree) {
+		printf("No devicetree given.\n");
+		return -EINVAL;
+	}
+
 	ret = of_overlay_load_firmware();
 	if (ret)
 		return ret;
diff --git a/arch/powerpc/lib/ppclinux.c b/arch/powerpc/lib/ppclinux.c
index 6b00c2ee5756..564086482e5f 100644
--- a/arch/powerpc/lib/ppclinux.c
+++ b/arch/powerpc/lib/ppclinux.c
@@ -60,7 +60,7 @@ static int do_bootm_linux(struct image_data *data)
 	if (ret)
 		return ret;
 
-	fdt = of_get_fixed_tree(data->of_root_node);
+	fdt = of_get_fixed_tree_for_boot(data->of_root_node);
 	if (!fdt) {
 		pr_err("bootm: No devicetree given.\n");
 		return -EINVAL;
diff --git a/common/Kconfig b/common/Kconfig
index 0a7d9aee3abe..da19cb8d9980 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -642,6 +642,24 @@ config BOOTM_OFTREE
 
 	  -o DTS  specify device tree
 
+config BOOTM_OFTREE_FALLBACK
+	def_bool y
+	# We intentionally don't depend on BOOTM_OFTREE, because many boards
+	# don't enable it and instead rely on OFTREE being selected...
+	depends on BOOTM && HAVE_ARCH_BOOTM_OFTREE && OFTREE
+	prompt "pass along barebox' own DT as fallback"
+	help
+	  Say y here to substitute in the barebox device tree, when no kernel
+	  device tree was supplied. If unsure, say n.
+
+	  It's recommended to boot a kernel with the device tree that was
+	  shipped with it as DT binding breakage is not an infrequent
+	  occurrence.
+
+	  This especially applies to A/B boot setups, where each kernel
+	  should have its own DT, so fallback restores the system cleanly
+	  to the old state.
+
 config BOOTM_UIMAGE
 	def_bool y
 	prompt "support the legacy uImage format"
diff --git a/common/bootm.c b/common/bootm.c
index 4aebc8a66abd..b98dc2715914 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -484,14 +484,11 @@ void *bootm_get_devicetree(struct image_data *data)
 		}
 
 	} else {
-		struct device_node *root = of_get_root_node();
-
-		if (!root)
+		data->of_root_node = of_dup_root_node_for_boot();
+		if (!data->of_root_node)
 			return NULL;
 
-		data->of_root_node = of_dup(root);
-
-		if (bootm_verbose(data) > 1 && data->of_root_node)
+		if (bootm_verbose(data) > 1)
 			printf("using internal devicetree\n");
 	}
 
diff --git a/include/of.h b/include/of.h
index e46d410d3651..a9bd37fdca2f 100644
--- a/include/of.h
+++ b/include/of.h
@@ -80,8 +80,6 @@ int of_add_initrd(struct device_node *root, resource_size_t start,
 
 struct fdt_header *fdt_get_tree(void);
 
-struct fdt_header *of_get_fixed_tree(const struct device_node *node);
-
 /* Helper to read a big number; size is in cells (not bytes) */
 static inline u64 of_read_number(const __be32 *cell, int size)
 {
@@ -325,6 +323,7 @@ extern const char *of_parse_phandle_and_get_alias_from(struct device_node *root,
 						       int index);
 
 extern struct device_node *of_get_root_node(void);
+extern struct fdt_header *of_get_fixed_tree(const struct device_node *node);
 extern int of_set_root_node(struct device_node *node);
 extern int barebox_register_of(struct device_node *root);
 extern int barebox_register_fdt(const void *dtb);
@@ -467,6 +466,11 @@ static inline struct device_node *of_get_root_node(void)
 	return NULL;
 }
 
+static inline struct fdt_header *of_get_fixed_tree(const struct device_node *node)
+{
+	return NULL;
+}
+
 static inline int of_set_root_node(struct device_node *node)
 {
 	return -ENOSYS;
@@ -1354,6 +1358,23 @@ static inline struct device_node *of_find_root_node(struct device_node *node)
 	return node;
 }
 
+
+static inline struct fdt_header *of_get_fixed_tree_for_boot(const struct device_node *node)
+{
+	if (!IS_ENABLED(CONFIG_BOOTM_OFTREE_FALLBACK) && !node)
+		return NULL;
+
+	return of_get_fixed_tree(node);
+}
+
+static inline struct device_node *of_dup_root_node_for_boot(void)
+{
+	if (!IS_ENABLED(CONFIG_BOOTM_OFTREE_FALLBACK))
+		return NULL;
+
+	return of_dup(of_get_root_node());
+}
+
 struct of_overlay_filter {
 	bool (*filter_filename)(struct of_overlay_filter *, const char *filename);
 	bool (*filter_content)(struct of_overlay_filter *, struct device_node *);
-- 
2.39.5




^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 09/10] commands: oftree: add option to return device tree without fixups
  2025-05-28 10:50 [PATCH 00/10] ARM32: allow disabling ATAGS and DT fallback Ahmad Fatoum
                   ` (7 preceding siblings ...)
  2025-05-28 10:50 ` [PATCH 08/10] bootm: make fallback to barebox internal tree optional Ahmad Fatoum
@ 2025-05-28 10:50 ` Ahmad Fatoum
  2025-05-28 10:50 ` [PATCH 10/10] of: drop undefined fdt_get_tree declaration Ahmad Fatoum
  9 siblings, 0 replies; 11+ messages in thread
From: Ahmad Fatoum @ 2025-05-28 10:50 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

When extracting the barebox device tree to use as argument to bootm when
BOOTM_OFTREE_FALLBACK is disabled, we will not want to apply fixups
twice, so add to oftree a -S option that just flattens the barebox
device tree as-is.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 commands/Kconfig  |  8 ++++----
 commands/oftree.c | 14 +++++++++-----
 common/oftree.c   | 22 ++++++++++++----------
 include/of.h      | 14 ++++++++++++--
 4 files changed, 37 insertions(+), 21 deletions(-)

diff --git a/commands/Kconfig b/commands/Kconfig
index 0f3155d123ab..7b84ef70e875 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -2530,13 +2530,13 @@ config CMD_OFTREE
 	help
 	  oftree - handle device trees
 
-	  Usage: oftree [-lspf] [DTB]
+	  Usage: oftree [-lsSp]
 
 	  Options:
-		  -l		Load DTB to internal device tree
-		  -s		save internal device tree to DTB
+		  -l <DTB>	Load <DTB> to internal device tree
+		  -s <DTB>	save internal device tree with fixups to <DTB>
+		  -S <DTB>	save internal device tree without fixups to <DTB>
 		  -p		probe devices from stored device tree
-		  -f		free stored device tree
 
 config CMD_TIME
 	bool "time"
diff --git a/commands/oftree.c b/commands/oftree.c
index 3adc660a77e0..b172aee9e074 100644
--- a/commands/oftree.c
+++ b/commands/oftree.c
@@ -32,13 +32,13 @@ static int do_oftree(int argc, char *argv[])
 {
 	struct fdt_header *fdt = NULL;
 	int opt;
-	int probe = 0;
+	int probe = 0, fixup = 0;
 	char *load = NULL;
 	char *save = NULL;
 	int ret;
 	struct device_node *root;
 
-	while ((opt = getopt(argc, argv, "pfl:s:")) > 0) {
+	while ((opt = getopt(argc, argv, "pfl:s:S:")) > 0) {
 		switch (opt) {
 		case 'l':
 			load = optarg;
@@ -52,6 +52,9 @@ static int do_oftree(int argc, char *argv[])
 			}
 			break;
 		case 's':
+			fixup = 1;
+			fallthrough;
+		case 'S':
 			save = optarg;
 			break;
 		}
@@ -61,7 +64,7 @@ static int do_oftree(int argc, char *argv[])
 		return COMMAND_ERROR_USAGE;
 
 	if (save) {
-		fdt = of_get_fixed_tree(NULL);
+		fdt = of_get_flattened_tree(NULL, fixup);
 		if (!fdt) {
 			printf("no devicetree available\n");
 			ret = -EINVAL;
@@ -102,14 +105,15 @@ static int do_oftree(int argc, char *argv[])
 BAREBOX_CMD_HELP_START(oftree)
 BAREBOX_CMD_HELP_TEXT("Options:")
 BAREBOX_CMD_HELP_OPT ("-l <DTB>",  "Load <DTB> to internal devicetree")
-BAREBOX_CMD_HELP_OPT ("-s <DTB>",  "save internal devicetree to <DTB>")
+BAREBOX_CMD_HELP_OPT ("-s <DTB>",  "save internal devicetree after fixups to <DTB>")
+BAREBOX_CMD_HELP_OPT ("-S <DTB>",  "save internal devicetree without fixups to <DTB>")
 BAREBOX_CMD_HELP_OPT ("-p",  "probe devices from stored device tree")
 BAREBOX_CMD_HELP_END
 
 BAREBOX_CMD_START(oftree)
 	.cmd		= do_oftree,
 	BAREBOX_CMD_DESC("handle device trees")
-	BAREBOX_CMD_OPTS("[-lsp]")
+	BAREBOX_CMD_OPTS("[-lsSp]")
 	BAREBOX_CMD_GROUP(CMD_GRP_MISC)
 	BAREBOX_CMD_HELP(cmd_oftree_help)
 BAREBOX_CMD_END
diff --git a/common/oftree.c b/common/oftree.c
index b9a854c786f6..58e96c39d897 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -413,15 +413,14 @@ void of_fix_tree(struct device_node *node)
 }
 
 /*
- * Get the fixed fdt. This function uses the fdt input pointer
+ * Get the fdt. This function uses the fdt input pointer
  * if provided or the barebox internal devicetree if not.
- * It increases the size of the tree and applies the registered
- * fixups.
  */
-struct fdt_header *of_get_fixed_tree(const struct device_node *node)
+struct fdt_header *of_get_flattened_tree(const struct device_node *node,
+					 bool fixup)
 {
 	struct fdt_header *fdt = NULL;
-	struct device_node *np;
+	struct device_node *np = NULL;
 
 	if (!node) {
 		node = of_get_root_node();
@@ -429,16 +428,19 @@ struct fdt_header *of_get_fixed_tree(const struct device_node *node)
 			return NULL;
 	}
 
-	np = of_dup(node);
+	if (fixup)
+		node = np = of_dup(node);
 
-	if (!np)
+	if (!node)
 		return NULL;
 
-	of_fix_tree(np);
+	if (fixup)
+		of_fix_tree(np);
 
-	fdt = of_flatten_dtb(np);
+	fdt = of_flatten_dtb((struct device_node *)node);
 
-	of_delete_node(np);
+	if (fixup)
+		of_delete_node(np);
 
 	return fdt;
 }
diff --git a/include/of.h b/include/of.h
index a9bd37fdca2f..f08ac8ccca69 100644
--- a/include/of.h
+++ b/include/of.h
@@ -323,7 +323,7 @@ extern const char *of_parse_phandle_and_get_alias_from(struct device_node *root,
 						       int index);
 
 extern struct device_node *of_get_root_node(void);
-extern struct fdt_header *of_get_fixed_tree(const struct device_node *node);
+extern struct fdt_header *of_get_flattened_tree(const struct device_node *node, bool fixup);
 extern int of_set_root_node(struct device_node *node);
 extern int barebox_register_of(struct device_node *root);
 extern int barebox_register_fdt(const void *dtb);
@@ -466,7 +466,7 @@ static inline struct device_node *of_get_root_node(void)
 	return NULL;
 }
 
-static inline struct fdt_header *of_get_fixed_tree(const struct device_node *node)
+static inline struct fdt_header *of_get_flattened_tree(const struct device_node *node, bool fixup)
 {
 	return NULL;
 }
@@ -1358,6 +1358,16 @@ static inline struct device_node *of_find_root_node(struct device_node *node)
 	return node;
 }
 
+/*
+ * Get the fixed fdt. This function uses the fdt input pointer
+ * if provided or the barebox internal devicetree if not.
+ * It increases the size of the tree and applies the registered
+ * fixups.
+ */
+static inline struct fdt_header *of_get_fixed_tree(const struct device_node *node)
+{
+	return of_get_flattened_tree(node, true);
+}
 
 static inline struct fdt_header *of_get_fixed_tree_for_boot(const struct device_node *node)
 {
-- 
2.39.5




^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 10/10] of: drop undefined fdt_get_tree declaration
  2025-05-28 10:50 [PATCH 00/10] ARM32: allow disabling ATAGS and DT fallback Ahmad Fatoum
                   ` (8 preceding siblings ...)
  2025-05-28 10:50 ` [PATCH 09/10] commands: oftree: add option to return device tree without fixups Ahmad Fatoum
@ 2025-05-28 10:50 ` Ahmad Fatoum
  9 siblings, 0 replies; 11+ messages in thread
From: Ahmad Fatoum @ 2025-05-28 10:50 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We don't use this anywhere, so drop it.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 include/of.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/include/of.h b/include/of.h
index f08ac8ccca69..2258cd501b72 100644
--- a/include/of.h
+++ b/include/of.h
@@ -78,8 +78,6 @@ bool of_match(struct device *dev, const struct driver *drv);
 int of_add_initrd(struct device_node *root, resource_size_t start,
 		resource_size_t end);
 
-struct fdt_header *fdt_get_tree(void);
-
 /* Helper to read a big number; size is in cells (not bytes) */
 static inline u64 of_read_number(const __be32 *cell, int size)
 {
-- 
2.39.5




^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-05-28 12:19 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-28 10:50 [PATCH 00/10] ARM32: allow disabling ATAGS and DT fallback Ahmad Fatoum
2025-05-28 10:50 ` [PATCH 01/10] arch: add new HAVE_ARCH_BOOTM_OFTREE symbol Ahmad Fatoum
2025-05-28 10:50 ` [PATCH 02/10] bootm: enable CONFIG_BOOTM_OFTREE by default Ahmad Fatoum
2025-05-28 10:50 ` [PATCH 03/10] ARM: lib32: disable ATAGS support " Ahmad Fatoum
2025-05-28 10:50 ` [PATCH 04/10] kvx: bootm: enforce existence of device tree Ahmad Fatoum
2025-05-28 10:50 ` [PATCH 05/10] bootm: booti: make device tree optional Ahmad Fatoum
2025-05-28 10:50 ` [PATCH 06/10] filetype: add new file type for 0-sized files Ahmad Fatoum
2025-05-28 10:50 ` [PATCH 07/10] bootm: have bootm_get_devicetree return NULL if passed empty DT Ahmad Fatoum
2025-05-28 10:50 ` [PATCH 08/10] bootm: make fallback to barebox internal tree optional Ahmad Fatoum
2025-05-28 10:50 ` [PATCH 09/10] commands: oftree: add option to return device tree without fixups Ahmad Fatoum
2025-05-28 10:50 ` [PATCH 10/10] of: drop undefined fdt_get_tree declaration Ahmad Fatoum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox