Skip to contentSkip to conversation

bootloader support for DTB on x86

DISCUSSION Thierry Reding 5 participants 6 messages May 22, 2012 – Jul 10, 2012 3 messages not in the archive x86

lore
Share & tools
lore
#0 lore raw

Hi,

I was looking at booting an x86-based platform using DT. However I wasn't able to find a bootloader that supports this. There also doesn't seem to be a method to append the DTB to the zImage (which I wouldn't want to use anyway). Does anybody know of a bootloader that supports this?

I'm currently using syslinux (specifically extlinux) and was looking at perhaps adding the support myself based on the information given in Documentation/x86/boot.txt. However I'm not overly familiar with syslinux code and this could prove more difficult than I anticipate.

The only x86 platforms that use DT seem to be OLPC and CE4100 and according to the web the OLPC has a complete OF implementation. Does anyone know which bootloader the CE4100 uses?

Thierry

_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss

#2 lore raw
In reply to a message not in the archive
Quoted 8 lines · Thierry Reding

Hi,

I was looking at booting an x86-based platform using DT. However I wasn't able to find a bootloader that supports this. There also doesn't seem to be a method to append the DTB to the zImage (which I wouldn't want to use anyway). Does anybody know of a bootloader that supports this?

Quoted 8 lines

I'm currently using syslinux (specifically extlinux) and was looking at perhaps adding the support myself based on the information given in Documentation/x86/boot.txt. However I'm not overly familiar with syslinux code and this could prove more difficult than I anticipate.

The only x86 platforms that use DT seem to be OLPC and CE4100 and according to the web the OLPC has a complete OF implementation. Does anyone know which bootloader the CE4100 uses?

The falcon falls CE4100 based board we used to do the DT support uses redboot The code is available at git://gitorious.org/driver-work/redboot.git

I never got to the point where the bootloader was loading the FDT from storage.
I linked the FDT blobs(s) into the kernel and used a kernel command line option to specify the compat string for the blob the kernel should use.

You can see a snapshot of what I was using at:
https://gitorious.org/driver-work/linux/commits/base-ce4100.public

The command line parameter stuff did not get merged linking the DTB(s) into the kernel did
aab9433 of: Add support for linking device tree blobs into vmlinux

Quoted 9 lines

Thierry

_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss

#3 lore raw
In reply to a message not in the archive
Quoted 1 line · * Thierry Reding | 2012-05-22 14:56:22 [+0200]:

Hi,

Hi,

Quoted 4 lines

I was looking at booting an x86-based platform using DT. However I wasn't able to find a bootloader that supports this. There also doesn't seem to be a method to append the DTB to the zImage (which I wouldn't want to use anyway). Does anybody know of a bootloader that supports this?

None that I am aware of.

Quoted 4 lines

I'm currently using syslinux (specifically extlinux) and was looking at perhaps adding the support myself based on the information given in Documentation/x86/boot.txt. However I'm not overly familiar with syslinux code and this could prove more difficult than I anticipate.

It should not be that difficult.
- Look how the initrd is loaded. Use the same technique to load the dtb blob.

- Allocate another memory block for setup_data. You need one entry of type SETUP_DTB pointing to the dtb. If I remember correctly, the setup_data is thrown away by kernel and the dtb blob itself is relocated to some place safe.

- You may need to set hardware_subarch to some similar to X86_SUBARCH_CE4100. I mean you *may* need your own subarch value but you can most likely reuse most of the functions that ce4100 is using. The PCI bus and UART is broken is a special way, everything else is generic. Since we don't have ACPI/SFI,
 we need something to find HPET, IO-APIC, irq routing,


Quoted 3 lines

The only x86 platforms that use DT seem to be OLPC and CE4100 and according to the web the OLPC has a complete OF implementation. Does anyone know which bootloader the CE4100 uses?

It jumps in the end to redboot which then loads the kernel. In the early days I had this patch make to sure the setup_data thingy works. So with this it should be easy to add the support to redboot/grub/isolinux/


From: Sebastian Andrzej Siewior <[email protected]>
Subject: [PATCH ] x86/dtb: add bzImage support

this adds two new targets:
- arch/x86/boot/$dt.dtb
a convience target which just calls dtc on the $dtb which lives in arch/x86/boot/dts/$dt.dts

- bzImage.$dt
embeds the device tree in the bzImage loader. The dtb will be passed to the kernel via setup_data if there is no dtb included. The memory location of the dtb will be before the initrd if one is available. If not it will placed at "memory size" or 128MiB depends which one is less. The upper limit is used a guess to ensure that it remains in lowmem. On a system with 1GiB the lowmem is around ~880MiB. The exact value depends on a few CONFIG_ swithes and is determined at run time. It can be additionaly increased or decreased via kernel parameters like memmap or vmalloc. So instead of parsing every piece of information we assume that nobody runs a kernel with only the first 100MiB mapped.

---
 arch/x86/Makefile                      |    6 +++
 arch/x86/boot/Makefile                 |   29 ++++++++++++++--
 arch/x86/boot/compressed/Makefile      |   25 ++++++++++++--
 arch/x86/boot/compressed/misc.c        |   60 +++++++++++++++++++++++++++++++-
 arch/x86/boot/compressed/vmlinux.lds.S |    7 ++++
 5 files changed, 120 insertions(+), 7 deletions(-)
arch/x86/Makefile +6 -0
index e8c8881..50dffd8 100644
@@ -161,6 +161,9 @@ endif
 	$(Q)mkdir -p $(objtree)/arch/$(UTS_MACHINE)/boot
 	$(Q)ln -fsn ../../x86/boot/bzImage $(objtree)/arch/$(UTS_MACHINE)/boot/$@
 
+bzImage.%: vmlinux
+	$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
+
 $(BOOT_TARGETS): vmlinux
 	$(Q)$(MAKE) $(build)=$(boot) $@
 
@@ -177,6 +180,9 @@ archclean:
 	$(Q)rm -rf $(objtree)/arch/x86_64
 	$(Q)$(MAKE) $(clean)=$(boot)
 
+%.dtb:
+	$(Q)$(MAKE) $(build)=$(boot) $@
+
 define archhelp
   echo  '* bzImage      - Compressed kernel image (arch/x86/boot/bzImage)'
   echo  '  install      - Install kernel using'
arch/x86/boot/Makefile +26 -3
index f7cb086..a7651f2 100644
@@ -72,20 +72,30 @@ KBUILD_CFLAGS	+= $(call cc-option, -m32)
 KBUILD_AFLAGS	:= $(KBUILD_CFLAGS) -D__ASSEMBLY__
 GCOV_PROFILE := n
 
-$(obj)/bzImage: asflags-y  := $(SVGA_MODE)
+$(obj)/bzImage $(obj)/bzImage.%: asflags-y  := $(SVGA_MODE)
 
 quiet_cmd_image = BUILD   $@
-cmd_image = $(obj)/tools/build $(obj)/setup.bin $(obj)/vmlinux.bin \
+cmd_image = $(obj)/tools/build $(obj)/setup.bin $2 \
 	$(ROOT_DEV) > $@
 
 $(obj)/bzImage: $(obj)/setup.bin $(obj)/vmlinux.bin $(obj)/tools/build FORCE
-	$(call if_changed,image)
+	$(call if_changed,image, $(obj)/vmlinux.bin)
+	@echo 'Kernel: $@ is ready' ' (#'`cat .version`')'
+
+$(obj)/bzImage.%: $(obj)/setup.bin $(obj)/vmlinux.bin.% $(obj)/tools/build FORCE
+	$(call if_changed,image,$(obj)/vmlinux.bin.$*)
 	@echo 'Kernel: $@ is ready' ' (#'`cat .version`')'
 
 OBJCOPYFLAGS_vmlinux.bin := -O binary -R .note -R .comment -S
 $(obj)/vmlinux.bin: $(obj)/compressed/vmlinux FORCE
 	$(call if_changed,objcopy)
 
+quiet_cmd_objcopybin = OBJCOPY $@
+      cmd_objcopybin = $(OBJCOPY) $(OBJCOPYFLAGS) -O binary -R .note -R .comment -S $< $@
+
+$(obj)/vmlinux.bin.%: $(obj)/compressed/vmlinux.dtb.% FORCE
+	$(call if_changed,objcopybin)
+
 SETUP_OBJS = $(addprefix $(obj)/,$(setup-y))
 
 sed-voffset := -e 's/^\([0-9a-fA-F]*\) . \(_text\|_end\)$$/\#define VO_\2 0x\1/p'
@@ -121,6 +131,19 @@ $(obj)/setup.bin: $(obj)/setup.elf FORCE
 $(obj)/compressed/vmlinux: FORCE
 	$(Q)$(MAKE) $(build)=$(obj)/compressed $@
 
+$(obj)/compressed/vmlinux.dtb.%: FORCE
+	$(Q)$(MAKE) $(build)=$(obj)/compressed $@
+
+dtstree		:= $(srctree)/$(src)/dts
+DTC = $(objtree)/scripts/dtc/dtc
+
+quiet_cmd_dtc = DTC	$@
+	cmd_dtc = $(DTC) -O dtb -o $(obj)/$*.dtb -b 0 -p 1024 $(dtstree)/$*.dts
+
+# Rule to build device tree blobs
+$(obj)/%.dtb: $(dtstree)/%.dts FORCE
+	$(call if_changed,dtc)
+
 # Set this if you want to pass append arguments to the
 # bzdisk/fdimage/isoimage kernel
 FDARGS =
arch/x86/boot/compressed/Makefile +22 -3
index 0c22955..4137939 100644
@@ -18,15 +18,34 @@ KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
 KBUILD_AFLAGS  := $(KBUILD_CFLAGS) -D__ASSEMBLY__
 GCOV_PROFILE := n
 
-LDFLAGS := -m elf_$(UTS_MACHINE)
-LDFLAGS_vmlinux := -T
+LDFLAGS := -m elf_$(UTS_MACHINE) -T
 
 hostprogs-y	:= mkpiggy
 
-$(obj)/vmlinux: $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o $(obj)/string.o $(obj)/cmdline.o $(obj)/early_serial_console.o $(obj)/piggy.o FORCE
+VMLINUX_DEP	:= $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o $(obj)/string.o $(obj)/cmdline.o $(obj)/early_serial_console.o $(obj)/piggy.o
+
+$(obj)/vmlinux: $(VMLINUX_DEP) FORCE
+	$(call if_changed,ld)
+	@:
+
+dtstree		:= $(srctree)/arch/x86/boot/dts
+DTC = $(objtree)/scripts/dtc/dtc
+
+quiet_cmd_dtc = DTC	$@
+      cmd_dtc = $(DTC) -O dtb -o $(obj)/$*.dtb -b 0 -p 1024 $(dtstree)/$*.dts
+
+$(obj)/%.dtb: $(dtstree)/%.dts
+	$(call if_changed,dtc)
+
+$(obj)/%.dtb.S: $(obj)/%.dtb
+	@echo '.section .data..dtb,"a"' > $@
+	@echo '.incbin "$<" ' >> $@
+
+$(obj)/vmlinux.dtb.%: $(VMLINUX_DEP) $(obj)/%.dtb.o FORCE
 	$(call if_changed,ld)
 	@:
 
+targets += vmlinux.dtb.%
 OBJCOPYFLAGS_vmlinux.bin :=  -R .comment -S
 $(obj)/vmlinux.bin: vmlinux FORCE
 	$(call if_changed,objcopy)
arch/x86/boot/compressed/misc.c +59 -1

78 lines not on this page · raw message

arch/x86/boot/compressed/vmlinux.lds.S +7 -0
index 34d047c..a4924f9 100644
@@ -41,6 +41,13 @@ SECTIONS
 		*(.rodata.*)
 		_erodata = . ;
 	}
+
+	_dtb_start = .;
+	.data..dtb : {
+		*(.data..dtb)
+	}
+	_dtb_end = . ;
+
 	.got : {
 		_got = .;
 		KEEP(*(.got.plt))
Signature · 1 line
1.7.2.3
Quoted 1 line

Thierry

Sebastian

#5 lore raw
In reply to a message not in the archive
Quoted 10 lines · Sebastian Andrzej Siewior

It should not be that difficult.
- Look how the initrd is loaded. Use the same technique to load the dtb blob.

- Allocate another memory block for setup_data. You need one entry of type SETUP_DTB pointing to the dtb. If I remember correctly, the setup_data is thrown away by kernel and the dtb blob itself is relocated to some place safe.

Quoted 7 lines

- You may need to set hardware_subarch to some similar to X86_SUBARCH_CE4100. I mean you *may* need your own subarch value but you can most likely reuse most of the functions that ce4100 is using. The PCI bus and UART is broken is a special way, everything else is generic. Since we don't have ACPI/SFI,
 we need something to find HPET, IO-APIC, irq routing,


Careful here!

We have just had a long discussion how we want to handle large data blobs which need bootloader support in x86 space. The consensus opinion ended up that they should be prepended to the initramfs, uncompressed, and using a cpio header with a file name beginning with "kernel/".

Thus, it is logically part of initramfs but can be accessed earlier in the boot. This has a number of advantages for the bootloader, including a modicum of backward compatibility with legacy bootloaders.

Intended users of this mechanism include microcode updates and ACPI table overrides.

I really don't want to see more ad hockery of the CE4100 variety.

The code for this is still not integrated; I wrote up some cpio parsing code for this:

http://www.zytor.com/~hpa/kernel/findcpio.c

... but it hasn't been included in any kernel trees yet. I know Thomas Renninger said he was going to work on it, but I haven't seen anything.

See the LKML thread "[PATCH] ACPI: Implement overriding of arbitrary ACPI tables via initrd":

http://lkml.kernel.org/r/[email protected]

-hpa

Signature · 7 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.

_______________________________________________
devicetree-discuss mailing list
[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss
#6 lore raw
In reply to a message not in the archive

Hi,

Quoted 9 lines · Thierry Reding

Hi,

I was looking at booting an x86-based platform using DT. However I wasn't able to find a bootloader that supports this. There also doesn't seem to be a
method to append the DTB to the zImage (which I wouldn't want to use anyway).
Does anybody know of a bootloader that supports this?

Maybe U-Boot with a FIT image? Also, you should support having multiple device trees in the image and the boot loader selecting the correct one.

I don't think we should rely on there being an initrd - what do we do if there isn't one?

Quoted 11 lines

I'm currently using syslinux (specifically extlinux) and was looking at perhaps adding the support myself based on the information given in Documentation/x86/boot.txt. However I'm not overly familiar with syslinux code and this could prove more difficult than I anticipate.

The only x86 platforms that use DT seem to be OLPC and CE4100 and according to the web the OLPC has a complete OF implementation. Does anyone know which
bootloader the CE4100 uses?

Quoted 8 lines

Thierry

_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss

Regards,
Simon

_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss

#8 lore raw
In reply to a message not in the archive
Quoted 15 lines · Simon Glass

Hi,

Quoted 9 lines · Thierry Reding

Hi,

I was looking at booting an x86-based platform using DT. However I wasn't able to find a bootloader that supports this. There also doesn't seem to be a
method to append the DTB to the zImage (which I wouldn't want to use anyway).
Does anybody know of a bootloader that supports this?

Quoted 5 lines

Maybe U-Boot with a FIT image? Also, you should support having multiple device trees in the image and the boot loader selecting the correct one.

I don't think we should rely on there being an initrd - what do we do if there isn't one?

I'm not sure if I can get U-Boot to run on this platform. It's Atom- based and I don't think anybody's gotten that to work yet.

syslinux 4.06 should support loading of DTBs on x86.

Thierry

_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss