From 184e49acc6986af178de459363e3a5f66d66db91 Mon Sep 17 00:00:00 2001 From: Manoharan Vijaya Raghavan Date: Tue, 21 Jun 2016 17:52:04 +0530 Subject: [PATCH] dts: Added support for multiple dtbs in u-boot dtbs are made as .o a table specifying their machid and address is added the dtbs and header are added to u-boot image in a seperate section dtb will be chosen based on machid detected from SMEM Change-Id: I50ac5b56da3a431c1a75cb9fc113fafaedbc09b8 Signed-off-by: Manoharan Vijaya Raghavan --- Makefile | 4 +++- arch/arm/cpu/u-boot.lds | 14 ++++++------ arch/arm/dts/Makefile | 19 ++++++++++++++-- arch/arm/dts/ipq807x-hk01.dts | 1 + dts/Makefile | 6 +---- include/configs/ipq807x.h | 5 +--- lib/fdtdec.c | 39 +++++++++++++++++++++++++++++++ scripts/Makefile.lib | 43 +++++++++++++++++++++++++++++------ 8 files changed, 105 insertions(+), 26 deletions(-) diff --git a/Makefile b/Makefile index 12a1bf15c5..2d1ab2f0f0 100644 --- a/Makefile +++ b/Makefile @@ -630,7 +630,7 @@ HAVE_VENDOR_COMMON_LIB = $(if $(wildcard $(srctree)/board/$(VENDOR)/common/Makef libs-y += lib/ libs-$(HAVE_VENDOR_COMMON_LIB) += board/$(VENDOR)/common/ libs-$(CONFIG_OF_EMBED) += dts/ -libs-$(CONFIG_OF_COMBINE) += dts/ +libs-$(CONFIG_OF_COMBINE) += arch/$(ARCH)/dts/ libs-y += fs/ libs-y += net/ libs-y += disk/ @@ -753,7 +753,9 @@ endif ALL-$(CONFIG_SPL) += spl/u-boot-spl.bin ALL-$(CONFIG_SPL_FRAMEWORK) += u-boot.img ALL-$(CONFIG_TPL) += tpl/u-boot-tpl.bin +ifeq ($(CONFIG_OF_COMBINE),) ALL-$(CONFIG_OF_SEPARATE) += u-boot.dtb u-boot-dtb.bin +endif ifeq ($(CONFIG_SPL_FRAMEWORK),y) ALL-$(CONFIG_OF_SEPARATE) += u-boot-dtb.img endif diff --git a/arch/arm/cpu/u-boot.lds b/arch/arm/cpu/u-boot.lds index 5a78f3cb23..945da18701 100644 --- a/arch/arm/cpu/u-boot.lds +++ b/arch/arm/cpu/u-boot.lds @@ -78,6 +78,13 @@ SECTIONS *(.data*) } +#ifdef CONFIG_OF_COMBINE + . = ALIGN(4); + .dtb : { + KEEP(*(.dtb.combine*)); + } +#endif + . = ALIGN(4); . = .; @@ -144,13 +151,6 @@ SECTIONS KEEP(*(.__bss_end)); } -#ifdef CONFIG_OF_COMBINE - . = ALIGN(4); - . = CONFIG_DTB_LOAD_ADDR; - .dtb : { - KEEP(*(.dtb.combine*)); - } -#endif .dynsym _image_binary_end : { *(.dynsym) } .dynbss : { *(.dynbss) } .dynstr : { *(.dynstr*) } diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile index 9d72f4b178..569f18059e 100644 --- a/arch/arm/dts/Makefile +++ b/arch/arm/dts/Makefile @@ -205,7 +205,22 @@ targets += $(dtb-y) DTC_FLAGS += PHONY += dtbs -dtbs: $(addprefix $(obj)/, $(dtb-y)) + +ifneq ($(CONFIG_OF_COMBINE),) + +%(obj)/%.dtb.comb.S: %(obj)/%.dtb @: -clean-files := *.dtb +$(obj)/dtbtable.S: $(addsuffix .comb.o, $(addprefix $(obj)/, $(dtb-y))) + @: + +obj-y := dtbtable.o $(addsuffix .comb.o, $(dtb-y)) + +targets += obj-$(CONFIG_OF_EMBED) + +else +dtbs: $(addprefix $(obj)/, $(dtb-y)) + @: +endif + +clean-files := *.dtb *.o *.S diff --git a/arch/arm/dts/ipq807x-hk01.dts b/arch/arm/dts/ipq807x-hk01.dts index 294b9ce001..81f908b201 100644 --- a/arch/arm/dts/ipq807x-hk01.dts +++ b/arch/arm/dts/ipq807x-hk01.dts @@ -16,6 +16,7 @@ / { model ="QCA, IPQ807x-HK01"; compatible = "qca,ipq807x", "qca,ipq807x-hk01"; + machid = <0x01010000>; aliases { console = "/serial@78af000"; diff --git a/dts/Makefile b/dts/Makefile index dcb686f89a..d3122aa3b9 100644 --- a/dts/Makefile +++ b/dts/Makefile @@ -37,16 +37,12 @@ arch-dtbs: .SECONDARY: $(obj)/dt.dtb.S -.SECONDARY: $(obj)/dt_comb.dtb.S - obj-$(CONFIG_OF_EMBED) := dt.dtb.o -obj-$(CONFIG_OF_COMBINE) := dt_comb.dtb.o - dtbs: $(obj)/dt.dtb @: -clean-files := dt.dtb.S dt_comb.dtb.S +clean-files := dt.dtb.S # Let clean descend into dts directories subdir- += ../arch/arm/dts ../arch/microblaze/dts ../arch/sandbox/dts ../arch/x86/dts diff --git a/include/configs/ipq807x.h b/include/configs/ipq807x.h index fa20c289dd..f6d4e38cfc 100644 --- a/include/configs/ipq807x.h +++ b/include/configs/ipq807x.h @@ -86,10 +86,7 @@ #define CONFIG_OF_COMBINE 1 -#define CONFIG_DTB_LOAD_ADDR 0x4AE00000 -#define CONFIG_EXTRA_ENV_SETTINGS "fdtcontroladdr=0x4AE00000\0" - -#define CONFIG_QCA_SMEM_BASE 0x41000000 +#define CONFIG_QCA_SMEM_BASE 0x4AB00000 /* * SPI Flash Configs */ diff --git a/lib/fdtdec.c b/lib/fdtdec.c index 885bfb4410..e906ab35b3 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -11,6 +11,7 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -1212,6 +1213,39 @@ int fdtdec_decode_display_timing(const void *blob, int parent, int index, return 0; } +#ifdef CONFIG_OF_COMBINE +extern unsigned long __dtb_table_start; +struct dtb_combined_hdr { + unsigned long machid; + unsigned long dtbaddr; +}; + +static int parse_combined_fdt(unsigned long machid) +{ + unsigned long *ptr = NULL; + struct dtb_combined_hdr *fdt_table; + unsigned long ndtbs = 0; + + ptr = &__dtb_table_start; + ndtbs = *ptr; + + ptr++; + + fdt_table = (struct dtb_combined_hdr *)ptr; + + while(ndtbs && (fdt_table->machid != machid)) { + fdt_table++; + ndtbs--; + } + + if(ndtbs == 0) + hang(); + + return fdt_table->dtbaddr; + +} +#endif + int fdtdec_setup(void) { #if CONFIG_IS_ENABLED(OF_CONTROL) @@ -1226,8 +1260,13 @@ int fdtdec_setup(void) else gd->fdt_blob = (ulong *)&__bss_end; # else +#ifdef CONFIG_OF_COMBINE + gd->fdt_blob = (ulong *) + parse_combined_fdt(smem_get_board_platform_type()); +#else /* FDT is at end of image */ gd->fdt_blob = (ulong *)&_end; +#endif # endif # elif defined(CONFIG_OF_HOSTFILE) if (sandbox_read_fdt_from_file()) { diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index ac1a0ffdbc..0157507f04 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -289,15 +289,44 @@ $(obj)/%.dtb.S: $(obj)/%.dtb # Generate an assembly file to wrap the output of the device tree compiler quiet_cmd_dt_comb_S_dtb= DTB_COMB $@ # Modified for U-Boot Combined ELF -cmd_dt_comb_S_dtb= \ -( \ - echo '.section .dtb.combine,"a"'; \ - echo '.balign 16'; \ - echo '.incbin "$<" '; \ - echo '.balign 16'; \ +#get the Magic +cmd_dt_comb_S_dtb= \ + dtbmachid=`cat "$(obj)/$(*F).dts" | grep machid | \ + cut -f 2 -d '<' | cut -f 1 -d '>'` ; \ + if [ -e $$dtbmachid ]; \ + then \ + echo "Need to specify \"machid\" in dts $(obj)/$(*F).dts "; \ + exit 1; \ + fi; \ + machiddec=`printf %d $$dtbmachid`; \ + if [ ! -f $(obj)/dtbtable.S ]; \ + then \ + echo ".section .dtb.combine_table,\"a\"" > $(obj)/dtbtable.S; \ + echo ".balign 16" >> $(obj)/dtbtable.S; \ + echo ".global __dtb_table_start" >> $(obj)/dtbtable.S; \ + echo "__dtb_table_start:" >> $(obj)/dtbtable.S; \ + echo ".word 0" >> $(obj)/dtbtable.S; \ + fi; \ + echo ".extern __dtb_begin_$$machiddec " >> $(obj)/dtbtable.S ; \ + echo ".word $$machiddec" >> $(obj)/dtbtable.S ; \ + echo ".word __dtb_begin_$$machiddec " >> $(obj)/dtbtable.S ; \ + num=`cat $(obj)/dtbtable.S | head -n 5 | tail -n 1 | cut -f 2 -d ' '`; \ + num=$$(expr $$num + 1); \ + sed -i '5 d' $(obj)/dtbtable.S; \ + sed -i "5 i .word $$num" $(obj)/dtbtable.S; \ +( \ + dtbmachid=`cat "$(obj)/$(*F).dts" | grep machid | \ + cut -f 2 -d '<' | cut -f 1 -d '>'` ; \ + machiddec=`printf %d $$dtbmachid`; \ + echo ".section .dtb.combine_$$machiddec,\"a\""; \ + echo '.balign 16'; \ + echo ".global __dtb_begin_$$machiddec"; \ + echo "__dtb_begin_$$machiddec:"; \ + echo '.incbin "$<" '; \ + echo '.balign 16'; \ ) > $@ -$(obj)/%_comb.dtb.S: $(obj)/%.dtb +$(obj)/%.dtb.comb.S: $(obj)/%.dtb $(call cmd,dt_comb_S_dtb)