All of lore.kernel.org
 help / color / mirror / Atom feed
* microblaze: Statically linking device tree blobs into the kernel
@ 2009-04-27  4:24 John Williams
  2009-04-27 13:47   ` Grant Likely
  2009-04-28  4:10   ` David Gibson
  0 siblings, 2 replies; 5+ messages in thread
From: John Williams @ 2009-04-27  4:24 UTC (permalink / raw)
  To: linuxppc-dev, Linux Kernel list, Stephen Neuendorffer, John Linn,
	microblaze-uclinux, Michal Simek, Grant Likely

To MicroBlazers and other interested parties:

Currently the MicroBlaze kernel boot-time ABI requires r7 to point to
a valid DTB, whereupon in early kernel setup the DTB is copied to a
statically allocated 16k memory region inside the kernel. From there
it is later queried by the platform startup code.

For simple boot scenarios the ability to statically bind a DTB into
the kernel image would clearly be useful.  In PPC land, this is
achieved through the simpleboot bootloader that lives in
arch/powerpc/boot.  The DTB becomes part of the simpleboot payload,
and is passed to the kernel through the normal means.

I'm not convinced duplicating this for MicroBlaze is a good idea, I
think it would be overkill.  However, the make syntax that PPC uses to
achieve DTB binding is quite nice:

$ make simpleImage.<board>

which binds arch/powerpc/boot/dts/<board>.dts into the boot payload.

My feeling is that we should make use of the fact that the DTB region
is statically allocated in the MicroBlaze kernel anyway.  From
arch/microblaze/kernel/vmlinux.lds.S:

        . = ALIGN (4) ;
       _fdt_start = . ; /* place for fdt blob */
       . = . + 0x4000;
       _fdt_end = . ;

and in head.S, the DTB at r7 is copied into place at _fdt_start

/* save fdt to kernel location */
/* r7 stores pointer to fdt blob */
        beqi    r7, no_fdt_arg
        or      r11, r0, r0 /* incremment */
        ori     r4, r0, TOPHYS(_fdt_start) /* save bram context */
        ori     r3, r0, (0x4000 - 4)
_copy_fdt:
       <simple copy loop>
no_fdt_arg:

Since this memory is already allocated in the kernel image but is
normally just zeros, to bind a DTB to the kernel we could just store
it in-situ.  This way, if a non-zero r7 is passed in at boot time,
head.S will naturally overwrite (and thus override) the "default" DTB
that was inside the kernel image.

What I'm not so sure about is how best to achieve this in the kbuild
sequence.  I see two options:

 (a) use .incbin in a .S file, similar to how the initramfs gets
linked in in /usr/Makefile etc, or
 (b) use objcopy to manipulate vmlinux after final link, by directly
inserting the DTB into the appropriate ELF section.

(a) seems nice because it means that our standard make targets, such
as linux.bin etc, would still work unchanged.  (b) seems to go a bit
against the grain of kbuild, but maybe I'm wrong there.

I've hacked around with (a) a bit, part of the problem is that it
seems arch/microblaze/Makefile would need something like

core-y += arch/microblaze/boot

because the DTB "object file" must be ready before final vmlinux link.

Instead of how it's done now (and in PPC), which is:

$(BOOT_TARGETS): vmlinux
        $(Q)$(MAKE) ARCH=ppc64 $(build)=$(boot) $(patsubst %,$(boot)/%,$@)

where vmlinux is a dependency of the whole simpleImage/DTB binding process.

Anyway input on both the approach, and how to achieve it, would be
greatly appreciated before we go working to deeply on the
implementation.

Thanks,

John
-- 
John Williams,
PetaLogix - Linux Solutions for a Reconfigurable World
w: www.petalogix.com  p: +61-7-30090663  f: +61-7-30090663

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

* Re: microblaze: Statically linking device tree blobs into the kernel
  2009-04-27  4:24 microblaze: Statically linking device tree blobs into the kernel John Williams
@ 2009-04-27 13:47   ` Grant Likely
  2009-04-28  4:10   ` David Gibson
  1 sibling, 0 replies; 5+ messages in thread
From: Grant Likely @ 2009-04-27 13:47 UTC (permalink / raw)
  To: John Williams
  Cc: linuxppc-dev, Linux Kernel list, Stephen Neuendorffer, John Linn,
	microblaze-uclinux, Michal Simek

On Sun, Apr 26, 2009 at 10:24 PM, John Williams
<john.williams@petalogix.com> wrote:
> To MicroBlazers and other interested parties:
>
> Currently the MicroBlaze kernel boot-time ABI requires r7 to point to
> a valid DTB, whereupon in early kernel setup the DTB is copied to a
> statically allocated 16k memory region inside the kernel. From there
> it is later queried by the platform startup code.
>
> For simple boot scenarios the ability to statically bind a DTB into
> the kernel image would clearly be useful.  In PPC land, this is
> achieved through the simpleboot bootloader that lives in
> arch/powerpc/boot.  The DTB becomes part of the simpleboot payload,
> and is passed to the kernel through the normal means.
>
> I'm not convinced duplicating this for MicroBlaze is a good idea, I
> think it would be overkill.  However, the make syntax that PPC uses to
> achieve DTB binding is quite nice:
>
> $ make simpleImage.<board>
>
> which binds arch/powerpc/boot/dts/<board>.dts into the boot payload.
>
> My feeling is that we should make use of the fact that the DTB region
> is statically allocated in the MicroBlaze kernel anyway.  From
> arch/microblaze/kernel/vmlinux.lds.S:
>
>        . = ALIGN (4) ;
>       _fdt_start = . ; /* place for fdt blob */
>       . = . + 0x4000;
>       _fdt_end = . ;
>
> and in head.S, the DTB at r7 is copied into place at _fdt_start
>
> /* save fdt to kernel location */
> /* r7 stores pointer to fdt blob */
>        beqi    r7, no_fdt_arg
>        or      r11, r0, r0 /* incremment */
>        ori     r4, r0, TOPHYS(_fdt_start) /* save bram context */
>        ori     r3, r0, (0x4000 - 4)
> _copy_fdt:
>       <simple copy loop>
> no_fdt_arg:
>
> Since this memory is already allocated in the kernel image but is
> normally just zeros, to bind a DTB to the kernel we could just store
> it in-situ.  This way, if a non-zero r7 is passed in at boot time,
> head.S will naturally overwrite (and thus override) the "default" DTB
> that was inside the kernel image.
>
> What I'm not so sure about is how best to achieve this in the kbuild
> sequence.  I see two options:
>
>  (a) use .incbin in a .S file, similar to how the initramfs gets
> linked in in /usr/Makefile etc, or
>  (b) use objcopy to manipulate vmlinux after final link, by directly
> inserting the DTB into the appropriate ELF section.
>
> (a) seems nice because it means that our standard make targets, such
> as linux.bin etc, would still work unchanged.  (b) seems to go a bit
> against the grain of kbuild, but maybe I'm wrong there.
>
> I've hacked around with (a) a bit, part of the problem is that it
> seems arch/microblaze/Makefile would need something like

I'm partial to (a)too , but I don't know how to achieve it in Kbuild.
Using the linker means that even large .dtb files will get handled
gracefully.

> core-y += arch/microblaze/boot
>
> because the DTB "object file" must be ready before final vmlinux link.

Which works fine with the .dtb list is in the list of default targets,
but is harder for miscellaneous 'make simpleimage.<board>' usage.  You
could I suppose duplicate the vmlinux target as simpleimage.% (or
whatever name makes sense) and have the kernel be relinked for each
target provided.  In fact, this might be the only way to do (a).

g.

-- 
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

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

* Re: microblaze: Statically linking device tree blobs into the kernel
@ 2009-04-27 13:47   ` Grant Likely
  0 siblings, 0 replies; 5+ messages in thread
From: Grant Likely @ 2009-04-27 13:47 UTC (permalink / raw)
  To: John Williams
  Cc: Michal Simek, microblaze-uclinux, Linux Kernel list,
	linuxppc-dev, John Linn

On Sun, Apr 26, 2009 at 10:24 PM, John Williams
<john.williams@petalogix.com> wrote:
> To MicroBlazers and other interested parties:
>
> Currently the MicroBlaze kernel boot-time ABI requires r7 to point to
> a valid DTB, whereupon in early kernel setup the DTB is copied to a
> statically allocated 16k memory region inside the kernel. From there
> it is later queried by the platform startup code.
>
> For simple boot scenarios the ability to statically bind a DTB into
> the kernel image would clearly be useful. =A0In PPC land, this is
> achieved through the simpleboot bootloader that lives in
> arch/powerpc/boot. =A0The DTB becomes part of the simpleboot payload,
> and is passed to the kernel through the normal means.
>
> I'm not convinced duplicating this for MicroBlaze is a good idea, I
> think it would be overkill. =A0However, the make syntax that PPC uses to
> achieve DTB binding is quite nice:
>
> $ make simpleImage.<board>
>
> which binds arch/powerpc/boot/dts/<board>.dts into the boot payload.
>
> My feeling is that we should make use of the fact that the DTB region
> is statically allocated in the MicroBlaze kernel anyway. =A0From
> arch/microblaze/kernel/vmlinux.lds.S:
>
> =A0 =A0 =A0 =A0. =3D ALIGN (4) ;
> =A0 =A0 =A0 _fdt_start =3D . ; /* place for fdt blob */
> =A0 =A0 =A0 . =3D . + 0x4000;
> =A0 =A0 =A0 _fdt_end =3D . ;
>
> and in head.S, the DTB at r7 is copied into place at _fdt_start
>
> /* save fdt to kernel location */
> /* r7 stores pointer to fdt blob */
> =A0 =A0 =A0 =A0beqi =A0 =A0r7, no_fdt_arg
> =A0 =A0 =A0 =A0or =A0 =A0 =A0r11, r0, r0 /* incremment */
> =A0 =A0 =A0 =A0ori =A0 =A0 r4, r0, TOPHYS(_fdt_start) /* save bram contex=
t */
> =A0 =A0 =A0 =A0ori =A0 =A0 r3, r0, (0x4000 - 4)
> _copy_fdt:
> =A0 =A0 =A0 <simple copy loop>
> no_fdt_arg:
>
> Since this memory is already allocated in the kernel image but is
> normally just zeros, to bind a DTB to the kernel we could just store
> it in-situ. =A0This way, if a non-zero r7 is passed in at boot time,
> head.S will naturally overwrite (and thus override) the "default" DTB
> that was inside the kernel image.
>
> What I'm not so sure about is how best to achieve this in the kbuild
> sequence. =A0I see two options:
>
> =A0(a) use .incbin in a .S file, similar to how the initramfs gets
> linked in in /usr/Makefile etc, or
> =A0(b) use objcopy to manipulate vmlinux after final link, by directly
> inserting the DTB into the appropriate ELF section.
>
> (a) seems nice because it means that our standard make targets, such
> as linux.bin etc, would still work unchanged. =A0(b) seems to go a bit
> against the grain of kbuild, but maybe I'm wrong there.
>
> I've hacked around with (a) a bit, part of the problem is that it
> seems arch/microblaze/Makefile would need something like

I'm partial to (a)too , but I don't know how to achieve it in Kbuild.
Using the linker means that even large .dtb files will get handled
gracefully.

> core-y +=3D arch/microblaze/boot
>
> because the DTB "object file" must be ready before final vmlinux link.

Which works fine with the .dtb list is in the list of default targets,
but is harder for miscellaneous 'make simpleimage.<board>' usage.  You
could I suppose duplicate the vmlinux target as simpleimage.% (or
whatever name makes sense) and have the kernel be relinked for each
target provided.  In fact, this might be the only way to do (a).

g.

--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

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

* Re: microblaze: Statically linking device tree blobs into the kernel
  2009-04-27  4:24 microblaze: Statically linking device tree blobs into the kernel John Williams
@ 2009-04-28  4:10   ` David Gibson
  2009-04-28  4:10   ` David Gibson
  1 sibling, 0 replies; 5+ messages in thread
From: David Gibson @ 2009-04-28  4:10 UTC (permalink / raw)
  To: John Williams
  Cc: linuxppc-dev, Linux Kernel list, Stephen Neuendorffer, John Linn,
	microblaze-uclinux, Michal Simek, Grant Likely

On Mon, Apr 27, 2009 at 02:24:42PM +1000, John Williams wrote:
> To MicroBlazers and other interested parties:
> 
> Currently the MicroBlaze kernel boot-time ABI requires r7 to point to
> a valid DTB, whereupon in early kernel setup the DTB is copied to a
> statically allocated 16k memory region inside the kernel. From there
> it is later queried by the platform startup code.
> 
> For simple boot scenarios the ability to statically bind a DTB into
> the kernel image would clearly be useful.  In PPC land, this is
> achieved through the simpleboot bootloader that lives in
> arch/powerpc/boot.  The DTB becomes part of the simpleboot payload,
> and is passed to the kernel through the normal means.
> 
> I'm not convinced duplicating this for MicroBlaze is a good idea, I
> think it would be overkill.  However, the make syntax that PPC uses to
> achieve DTB binding is quite nice:
> 
> $ make simpleImage.<board>
> 
> which binds arch/powerpc/boot/dts/<board>.dts into the boot payload.
> 
> My feeling is that we should make use of the fact that the DTB region
> is statically allocated in the MicroBlaze kernel anyway.  From
> arch/microblaze/kernel/vmlinux.lds.S:
> 
>         . = ALIGN (4) ;
>        _fdt_start = . ; /* place for fdt blob */
>        . = . + 0x4000;
>        _fdt_end = . ;
> 
> and in head.S, the DTB at r7 is copied into place at _fdt_start
> 
> /* save fdt to kernel location */
> /* r7 stores pointer to fdt blob */
>         beqi    r7, no_fdt_arg
>         or      r11, r0, r0 /* incremment */
>         ori     r4, r0, TOPHYS(_fdt_start) /* save bram context */
>         ori     r3, r0, (0x4000 - 4)
> _copy_fdt:
>        <simple copy loop>
> no_fdt_arg:
> 
> Since this memory is already allocated in the kernel image but is
> normally just zeros, to bind a DTB to the kernel we could just store
> it in-situ.  This way, if a non-zero r7 is passed in at boot time,
> head.S will naturally overwrite (and thus override) the "default" DTB
> that was inside the kernel image.
> 
> What I'm not so sure about is how best to achieve this in the kbuild
> sequence.  I see two options:
> 
>  (a) use .incbin in a .S file, similar to how the initramfs gets
> linked in in /usr/Makefile etc, or

Or you could build the .dts directly into a .S file (which dtc
supports) and #include or link that in.  It's possible the dtc asm
output mode would need some work, but that's easily enough done.

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

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

* Re: microblaze: Statically linking device tree blobs into the kernel
@ 2009-04-28  4:10   ` David Gibson
  0 siblings, 0 replies; 5+ messages in thread
From: David Gibson @ 2009-04-28  4:10 UTC (permalink / raw)
  To: John Williams
  Cc: Michal Simek, microblaze-uclinux, Linux Kernel list,
	linuxppc-dev, John Linn

On Mon, Apr 27, 2009 at 02:24:42PM +1000, John Williams wrote:
> To MicroBlazers and other interested parties:
> 
> Currently the MicroBlaze kernel boot-time ABI requires r7 to point to
> a valid DTB, whereupon in early kernel setup the DTB is copied to a
> statically allocated 16k memory region inside the kernel. From there
> it is later queried by the platform startup code.
> 
> For simple boot scenarios the ability to statically bind a DTB into
> the kernel image would clearly be useful.  In PPC land, this is
> achieved through the simpleboot bootloader that lives in
> arch/powerpc/boot.  The DTB becomes part of the simpleboot payload,
> and is passed to the kernel through the normal means.
> 
> I'm not convinced duplicating this for MicroBlaze is a good idea, I
> think it would be overkill.  However, the make syntax that PPC uses to
> achieve DTB binding is quite nice:
> 
> $ make simpleImage.<board>
> 
> which binds arch/powerpc/boot/dts/<board>.dts into the boot payload.
> 
> My feeling is that we should make use of the fact that the DTB region
> is statically allocated in the MicroBlaze kernel anyway.  From
> arch/microblaze/kernel/vmlinux.lds.S:
> 
>         . = ALIGN (4) ;
>        _fdt_start = . ; /* place for fdt blob */
>        . = . + 0x4000;
>        _fdt_end = . ;
> 
> and in head.S, the DTB at r7 is copied into place at _fdt_start
> 
> /* save fdt to kernel location */
> /* r7 stores pointer to fdt blob */
>         beqi    r7, no_fdt_arg
>         or      r11, r0, r0 /* incremment */
>         ori     r4, r0, TOPHYS(_fdt_start) /* save bram context */
>         ori     r3, r0, (0x4000 - 4)
> _copy_fdt:
>        <simple copy loop>
> no_fdt_arg:
> 
> Since this memory is already allocated in the kernel image but is
> normally just zeros, to bind a DTB to the kernel we could just store
> it in-situ.  This way, if a non-zero r7 is passed in at boot time,
> head.S will naturally overwrite (and thus override) the "default" DTB
> that was inside the kernel image.
> 
> What I'm not so sure about is how best to achieve this in the kbuild
> sequence.  I see two options:
> 
>  (a) use .incbin in a .S file, similar to how the initramfs gets
> linked in in /usr/Makefile etc, or

Or you could build the .dts directly into a .S file (which dtc
supports) and #include or link that in.  It's possible the dtc asm
output mode would need some work, but that's easily enough done.

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

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

end of thread, other threads:[~2009-04-28  5:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-27  4:24 microblaze: Statically linking device tree blobs into the kernel John Williams
2009-04-27 13:47 ` Grant Likely
2009-04-27 13:47   ` Grant Likely
2009-04-28  4:10 ` David Gibson
2009-04-28  4:10   ` David Gibson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.