<p><br>
On Feb 3, 2011 9:44 PM, "Nicolas Pitre" <<a href="mailto:nico@fluxnic.net">nico@fluxnic.net</a>> wrote:<br>
><br>
> On Wed, 26 Jan 2011, John Bonesio wrote:<br>
><br>
> > This patch is to merge in key atags into the appended device tree. An appended<br>
> > device tree is where the zImage has a dtb binary appended at the end of it. The<br>
> > boot code looks for an appended device tree, then looks for a few key atags<br>
> > passed in by the bootloader.<br>
> ><br>
> > The bootargs and memory size settings, if they exist, override existing values<br>
> > in the appended device tree. If these values don't currently exist in the<br>
> > appended device tree, they are added.<br>
> ><br>
> > Signed-off-by: John Bonesio <<a href="mailto:bones@secretlab.ca">bones@secretlab.ca</a>><br>
> > Acked-by: Grant Likely <<a href="mailto:grant.likely@secretlab.ca">grant.likely@secretlab.ca</a>><br>
><br>
> This is just for testing/evaluation purpose and not intended to be<br>
> merged upstream at some point, right?</p>
<p>Correct.</p>
<p>><br>
> > ---<br>
> ><br>
> > arch/arm/boot/compressed/Makefile | 31 +++++++++++++++++---<br>
> > arch/arm/boot/compressed/atags.c | 50 ++++++++++++++++++++++++++++++++<br>
> > arch/arm/boot/compressed/head.S | 7 ++++<br>
> > arch/arm/boot/compressed/misc.c | 58 ++++++++++++++++++++++++++++++++++++-<br>
> > 4 files changed, 139 insertions(+), 7 deletions(-)<br>
> > create mode 100644 arch/arm/boot/compressed/atags.c<br>
> ><br>
> > diff --git a/arch/arm/boot/compressed/Makefile b/arch/arm/boot/compressed/Makefile<br>
> > index 0a8f748..7978a39 100644<br>
> > --- a/arch/arm/boot/compressed/Makefile<br>
> > +++ b/arch/arm/boot/compressed/Makefile<br>
> > @@ -49,6 +49,10 @@ ifeq ($(CONFIG_ARCH_SHMOBILE),y)<br>
> > OBJS += head-shmobile.o<br>
> > endif<br>
> ><br>
> > +ifeq ($(CONFIG_ARM_APPENDED_DTB),y)<br>
> > +OBJS += atags.o libfdt.a<br>
> > +endif<br>
> > +<br>
> > #<br>
> > # We now have a PIC decompressor implementation. Decompressors running<br>
> > # from RAM should not define ZTEXTADDR. Decompressors running directly<br>
> > @@ -80,7 +84,9 @@ ORIG_CFLAGS := $(KBUILD_CFLAGS)<br>
> > KBUILD_CFLAGS = $(subst -pg, , $(ORIG_CFLAGS))<br>
> > endif<br>
> ><br>
> > -EXTRA_CFLAGS := -fpic -fno-builtin<br>
> > +fdttree := $(srctree)/scripts/dtc/libfdt<br>
> > +<br>
> > +EXTRA_CFLAGS := -fpic -fno-builtin -I$(fdttree) -I$(obj)<br>
> > EXTRA_AFLAGS := -Wa,-march=all<br>
> ><br>
> > # Supply ZRELADDR to the decompressor via a linker symbol.<br>
> > @@ -100,13 +106,28 @@ LDFLAGS_vmlinux += -X<br>
> > LDFLAGS_vmlinux += -T<br>
> ><br>
> > # For __aeabi_uidivmod<br>
> > -lib1funcs = $(obj)/lib1funcs.o<br>
> > +libfuncs = $(obj)/lib1funcs.o<br>
> ><br>
> > -$(obj)/lib1funcs.S: $(srctree)/arch/$(SRCARCH)/lib/lib1funcs.S FORCE<br>
> > - $(call cmd,shipped)<br>
> > +ifeq ($(CONFIG_ARM_APPENDED_DTB),y)<br>
> > +# For memchr, memmove, etc<br>
> > +libfuncs += $(obj)/memchr.o $(obj)/strchr.o $(obj)/memmove.o $(obj)/memzero.o<br>
> > +endif<br>
> > +<br>
> > +<br>
> > +libfdtheader := $(fdttree)/fdt.h $(fdttree)/libfdt.h $(fdttree)/libfdt_internal.h<br>
> > +libfdtobj := $(obj)/fdt.o $(obj)/fdt_ro.o $(obj)/fdt_wip.o $(obj)/fdt_sw.o $(obj)/fdt_rw.o $(obj)/fdt_strerror.o<br>
> > +<br>
> > +$(libfdtobj): $(obj)/%.o: $(srctree)/scripts/dtc/libfdt/%.c $(libfdtheader)<br>
> > + $(call cmd_cc_o_c)<br>
> > +<br>
> > +$(obj)/libfdt.a: $(libfdtobj)<br>
> > + $(AR) rcs $@ $^<br>
> > +<br>
> > +$(libfuncs): $(obj)/%.o: $(srctree)/arch/$(SRCARCH)/lib/%.S<br>
> > + $(call cmd_as_o_S)<br>
> ><br>
> > $(obj)/vmlinux: $(obj)/vmlinux.lds $(obj)/$(HEAD) $(obj)/piggy.$(suffix_y).o \<br>
> > - $(addprefix $(obj)/, $(OBJS)) $(lib1funcs) FORCE<br>
> > + $(addprefix $(obj)/, $(OBJS)) $(libfuncs) FORCE<br>
> > $(call if_changed,ld)<br>
> > @:<br>
> ><br>
> > diff --git a/arch/arm/boot/compressed/atags.c b/arch/arm/boot/compressed/atags.c<br>
> > new file mode 100644<br>
> > index 0000000..e37d8de<br>
> > --- /dev/null<br>
> > +++ b/arch/arm/boot/compressed/atags.c<br>
> > @@ -0,0 +1,50 @@<br>
> > +#include <stddef.h><br>
> > +#include <asm/byteorder.h><br>
> > +#include <asm/setup.h><br>
> > +#include <fdt.h><br>
> > +#include <libfdt.h><br>
> > +<br>
> > +<br>
> > +int dt_setprop(void *fdt, const char *node_path, const char *property,<br>
> > + uint32_t *val_array, int size)<br>
> > +{<br>
> > + int offset;<br>
> > +<br>
> > + offset = fdt_path_offset(fdt, node_path);<br>
> > + if (offset < 0)<br>
> > + return offset;<br>
> > +<br>
> > + return fdt_setprop(fdt, offset, property, val_array, size);<br>
> > +}<br>
> > +<br>
> > +int dt_setprop_string(void *fdt, const char *node_path,<br>
> > + const char *property, const char *string)<br>
> > +{<br>
> > + int offset;<br>
> > +<br>
> > + offset = fdt_path_offset(fdt, node_path);<br>
> > + if (offset < 0)<br>
> > + return offset;<br>
> > +<br>
> > + return fdt_setprop_string(fdt, offset, property, string);<br>
> > +}<br>
> > +<br>
> > +void dt_merge_atags(void *dt, void *ataglist)<br>
> > +{<br>
> > + struct tag *atag = ataglist;<br>
> > + uint32_t mem_reg_property[2];<br>
> > +<br>
> > + while (atag && atag->hdr.tag != 0) {<br>
> > + if (atag->hdr.tag == ATAG_CMDLINE) {<br>
> > + dt_setprop_string(dt, "/chosen", "bootargs",<br>
> > + atag->u.cmdline.cmdline);<br>
> > + } else if (atag->hdr.tag == ATAG_MEM) {<br>
> > + mem_reg_property[0] = cpu_to_fdt32(atag->u.mem.start);<br>
> > + mem_reg_property[1] = cpu_to_fdt32(atag->u.mem.size);<br>
> > + dt_setprop(dt, "/memory", "reg", mem_reg_property,<br>
> > + sizeof(mem_reg_property));<br>
> > + }<br>
> > + atag = tag_next(atag);<br>
> > + }<br>
> > +}<br>
> > +<br>
> > diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S<br>
> > index db860b3..09e659d 100644<br>
> > --- a/arch/arm/boot/compressed/head.S<br>
> > +++ b/arch/arm/boot/compressed/head.S<br>
> > @@ -257,6 +257,13 @@ not_relocated:<br>
> > cmp r1, r9<br>
> > bne keep_atags<br>
> ><br>
> > + /* Merge some of the atags into the device tree */<br>
> > + push {r2, r3, r10, r11}<br>
> > + mov r0, r2<br>
> > + mov r1, r8<br>
> > + bl dt_merge_atags<br>
> > + pop {r2, r3, r10, r11}<br>
> > +<br>
> > /* copy the device tree binary to 0x0 */<br>
> > ldr r9, [r10, #4] @ device tree size<br>
> ><br>
> > diff --git a/arch/arm/boot/compressed/misc.c b/arch/arm/boot/compressed/misc.c<br>
> > index e653a6d..2d4da4c 100644<br>
> > --- a/arch/arm/boot/compressed/misc.c<br>
> > +++ b/arch/arm/boot/compressed/misc.c<br>
> > @@ -29,7 +29,7 @@ unsigned int __machine_arch_type;<br>
> > #include <asm/unaligned.h><br>
> ><br>
> ><br>
> > -static void putstr(const char *ptr);<br>
> > +void putstr(const char *ptr);<br>
> > extern void error(char *x);<br>
> ><br>
> > #include <mach/uncompress.h><br>
> > @@ -100,7 +100,7 @@ static void icedcc_putc(int ch)<br>
> > #define putc(ch) icedcc_putc(ch)<br>
> > #endif<br>
> ><br>
> > -static void putstr(const char *ptr)<br>
> > +void putstr(const char *ptr)<br>
> > {<br>
> > char c;<br>
> ><br>
> > @@ -114,6 +114,60 @@ static void putstr(const char *ptr)<br>
> > }<br>
> ><br>
> ><br>
> > +#ifdef CONFIG_ARM_APPENDED_DTB<br>
> > +/**<br>
> > + * strlen - Find the length of a string<br>
> > + * @s: The string to be sized<br>
> > + */<br>
> > +size_t strlen(const char *s)<br>
> > +{<br>
> > + const char *sc;<br>
> > +<br>
> > + for (sc = s; *sc != '\0'; ++sc)<br>
> > + /* nothing */;<br>
> > + return sc - s;<br>
> > +}<br>
> > +<br>
> > +/**<br>
> > + * strcmp - Compare two strings<br>
> > + * @cs: One string<br>
> > + * @ct: Another string<br>
> > + */<br>
> > +#undef strcmp<br>
> > +int strcmp(const char *cs, const char *ct)<br>
> > +{<br>
> > + unsigned char c1, c2;<br>
> > +<br>
> > + while (1) {<br>
> > + c1 = *cs++;<br>
> > + c2 = *ct++;<br>
> > + if (c1 != c2)<br>
> > + return c1 < c2 ? -1 : 1;<br>
> > + if (!c1)<br>
> > + break;<br>
> > + }<br>
> > + return 0;<br>
> > +}<br>
> > +<br>
> > +/**<br>
> > + * memcmp - Compare two areas of memory<br>
> > + * @cs: One area of memory<br>
> > + * @ct: Another area of memory<br>
> > + * @count: The size of the area.<br>
> > + */<br>
> > +#undef memcmp<br>
> > +int memcmp(const void *cs, const void *ct, size_t count)<br>
> > +{<br>
> > + const unsigned char *su1, *su2;<br>
> > + int res = 0;<br>
> > +<br>
> > + for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)<br>
> > + if ((res = *su1 - *su2) != 0)<br>
> > + break;<br>
> > + return res;<br>
> > +}<br>
> > +#endif<br>
> > +<br>
> > void *memcpy(void *__dest, __const void *__src, size_t __n)<br>
> > {<br>
> > int i = 0;<br>
> ><br>
> ><br>
> > _______________________________________________<br>
> > linux-arm-kernel mailing list<br>
> > <a href="mailto:linux-arm-kernel@lists.infradead.org">linux-arm-kernel@lists.infradead.org</a><br>
> > <a href="http://lists.infradead.org/mailman/listinfo/linux-arm-kernel">http://lists.infradead.org/mailman/listinfo/linux-arm-kernel</a><br>
> ><br>
</p>