From c5a4141343e601bac2789c137e8be665c074f898 Mon Sep 17 00:00:00 2001 From: Kever Yang Date: Tue, 31 Oct 2017 16:52:23 +0800 Subject: rockchip: config: update part table User do not need to access the reserved part in system, remove them from partition table. Rename atf to trust as generic name for armv7 do not use ATF. Signed-off-by: Kever Yang Acked-by: Philipp Tomsich Reviewed-by: Philipp Tomsich --- include/configs/rockchip-common.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/include/configs/rockchip-common.h b/include/configs/rockchip-common.h index 35d948ae29..4139a7b73d 100644 --- a/include/configs/rockchip-common.h +++ b/include/configs/rockchip-common.h @@ -52,10 +52,8 @@ #define PARTS_DEFAULT \ "uuid_disk=${uuid_gpt_disk};" \ "name=loader1,start=32K,size=4000K,uuid=${uuid_gpt_loader1};" \ - "name=reserved1,size=64K,uuid=${uuid_gpt_reserved1};" \ - "name=reserved2,size=4M,uuid=${uuid_gpt_reserved2};" \ - "name=loader2,size=4MB,uuid=${uuid_gpt_loader2};" \ - "name=atf,size=4M,uuid=${uuid_gpt_atf};" \ + "name=loader2,start=8MB,size=4MB,uuid=${uuid_gpt_loader2};" \ + "name=trust,size=4M,uuid=${uuid_gpt_atf};" \ "name=boot,size=112M,bootable,uuid=${uuid_gpt_boot};" \ "name=rootfs,size=-,uuid="ROOT_UUID -- cgit From aa41220f6f7c79284ce5880e2533f81c125237a4 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Fri, 15 Dec 2017 16:23:14 +0100 Subject: rockchip: rk3399-puma: set gpio4cd iodomain to 1.8V The PCIe reset signal is connected to GPIO4_C6 on the Puma module. This pin is supplied by 1.8V, but the default iodomain setting is 3.0V and in this situation the pin is unable to go high. Linux assumes that this signal works in early boot as PCIe is probed before loading the iodomain driver. Make PCIe work in Linux by setting the gpio4cd iodomain to 1.8V. Signed-off-by: Jakob Unterwurzacher Acked-by: Philipp Tomsich Reviewed-by: Philipp Tomsich --- board/theobroma-systems/puma_rk3399/puma-rk3399.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/board/theobroma-systems/puma_rk3399/puma-rk3399.c b/board/theobroma-systems/puma_rk3399/puma-rk3399.c index 27e3823d52..c6690fa069 100644 --- a/board/theobroma-systems/puma_rk3399/puma-rk3399.c +++ b/board/theobroma-systems/puma_rk3399/puma-rk3399.c @@ -8,13 +8,17 @@ #include #include #include +#include #include #include #include +#include #include #include #include #include +#include +#include #include #include #include @@ -180,10 +184,25 @@ static void setup_serial(void) #endif } +static void setup_iodomain(void) +{ + const u32 GRF_IO_VSEL_GPIO4CD_SHIFT = 3; + struct rk3399_grf_regs *grf = + syscon_get_first_range(ROCKCHIP_SYSCON_GRF); + + /* + * Set bit 3 in GRF_IO_VSEL so PCIE_RST# works (pin GPIO4_C6). + * Linux assumes that PCIE_RST# works out of the box as it probes + * PCIe before loading the iodomain driver. + */ + rk_setreg(&grf->io_vsel, 1 << GRF_IO_VSEL_GPIO4CD_SHIFT); +} + int misc_init_r(void) { setup_serial(); setup_macaddr(); + setup_iodomain(); return 0; } -- cgit From 81f53b0dafdfe9458f6d04fc5ec2732c2ea23a71 Mon Sep 17 00:00:00 2001 From: Klaus Goger Date: Mon, 11 Dec 2017 17:56:08 +0100 Subject: rockchip: move CONFIG_ENV_SIZE and CONFIG_ENV_OFFSET to Kconfig This commit adds ENV_SIZE and ENV_OFFSET configuration items for ARCH_ROCKCHIP, but keeps these non-visible (i.e. not prompt is given). With these new items present, the configuration from the header files is moved to Kconfig. Keeping these non-visible is necessary to have the possibility to select new default values if CONFIG_IS_IN_* is changed (interactively or with oldconfig). Otherwise it will always be set to a previous value if used with a prompt. As an example if we do a defconfig with CONFIG_IS_IN_MMC and change it to CONFIG_IS_IN_SPI_FLASH via menuconfig, ENV_SIZE and ENV_OFFSET will not be changed to the correct values as defconfig will already have set them to the default values of CONFIG_IS_IN_MMC in .config. Signed-off-by: Klaus Goger Reviewed-by: Philipp Tomsich --- board/theobroma-systems/puma_rk3399/Kconfig | 6 ++++++ env/Kconfig | 18 ++++++++++++++++++ include/configs/puma_rk3399.h | 8 -------- include/configs/rockchip-common.h | 6 ------ 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/board/theobroma-systems/puma_rk3399/Kconfig b/board/theobroma-systems/puma_rk3399/Kconfig index a645590d78..80b3460d4c 100644 --- a/board/theobroma-systems/puma_rk3399/Kconfig +++ b/board/theobroma-systems/puma_rk3399/Kconfig @@ -12,4 +12,10 @@ config SYS_CONFIG_NAME config BOARD_SPECIFIC_OPTIONS # dummy def_bool y +config ENV_SIZE + default 0x2000 if ENV_IS_IN_SPI_FLASH + +config ENV_OFFSET + default 0x3c000 if ENV_IS_IN_SPI_FLASH + endif diff --git a/env/Kconfig b/env/Kconfig index 2477bf8530..bef6e89bfc 100644 --- a/env/Kconfig +++ b/env/Kconfig @@ -427,4 +427,22 @@ config ENV_UBI_VOLUME endif +if ARCH_ROCKCHIP + +config ENV_OFFSET + hex + depends on !ENV_IS_IN_UBI + depends on !ENV_IS_NOWHERE + default 0x3f8000 + help + Offset from the start of the device (or partition) + +config ENV_SIZE + hex + default 0x8000 + help + Size of the environment storage area + +endif + endmenu diff --git a/include/configs/puma_rk3399.h b/include/configs/puma_rk3399.h index 39d0786266..6523a7c34a 100644 --- a/include/configs/puma_rk3399.h +++ b/include/configs/puma_rk3399.h @@ -9,14 +9,6 @@ #include -/* - * SPL @ 32kB for ~130kB - * ENV @ 240KB for 8kB - * FIT payload (ATF, U-Boot, FDT) @ 256kB - */ -#undef CONFIG_ENV_OFFSET -#define CONFIG_ENV_OFFSET (240 * 1024) - #if defined(CONFIG_ENV_IS_IN_MMC) #define CONFIG_SYS_MMC_ENV_DEV 1 #elif defined(CONFIG_ENV_IS_IN_SPI_FLASH) diff --git a/include/configs/rockchip-common.h b/include/configs/rockchip-common.h index 4139a7b73d..f465d35330 100644 --- a/include/configs/rockchip-common.h +++ b/include/configs/rockchip-common.h @@ -59,12 +59,6 @@ #endif -/* - * Rockchip SoCs use fixed ENV 32KB@(4MB-32KB) - */ -#define CONFIG_ENV_OFFSET (SZ_4M - SZ_32K) -#define CONFIG_ENV_SIZE SZ_32K - #define CONFIG_DISPLAY_BOARDINFO_LATE #endif /* _ROCKCHIP_COMMON_H_ */ -- cgit From 270288544e12c7c98e4bc9a5b121517ba0a959d2 Mon Sep 17 00:00:00 2001 From: Kever Yang Date: Mon, 18 Dec 2017 15:05:41 +0800 Subject: rockchip: update boot0 hook Rockchip SoCs only need boot0 hook at SPL, and the U-Boot proper do not need it. The very beginning of U-Boot proper is different between armv7 and armv8: armv7 start with ARM_VECTORS while armv8 start with 'b reset'. Here is the map of very beginning for all cases: armv7 SPL: TAG(overwrite 'b 1f')+'b reset' + ARM_VECTORS armv7 U-Boot: ARM_VECTORS armv8 SPL: TAG(overwrite 'b 1f')+'b reset' + Reserved_iram(rk3399) armv8 U-Boot: 'b reset' Signed-off-by: Kever Yang Acked-by: Philipp Tomsich Reviewed-by: Philipp Tomsich --- arch/arm/include/asm/arch-rockchip/boot0.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/arm/include/asm/arch-rockchip/boot0.h b/arch/arm/include/asm/arch-rockchip/boot0.h index af3a733e98..5d35c35c28 100644 --- a/arch/arm/include/asm/arch-rockchip/boot0.h +++ b/arch/arm/include/asm/arch-rockchip/boot0.h @@ -39,7 +39,12 @@ entry_counter: .word 0 #endif + +#if (defined(CONFIG_SPL_BUILD) || defined(CONFIG_ARM64)) + /* U-Boot proper of armv7 do not need this */ b reset +#endif + #if !defined(CONFIG_ARM64) /* * For armv7, the addr '_start' will used as vector start address @@ -50,6 +55,6 @@ _start: ARM_VECTORS #endif -#if defined(CONFIG_ROCKCHIP_RK3399) && defined(CONFIG_SPL_BUILD) +#if defined(CONFIG_SPL_BUILD) && (CONFIG_ROCKCHIP_SPL_RESERVE_IRAM > 0) .space CONFIG_ROCKCHIP_SPL_RESERVE_IRAM /* space for the ATF data */ #endif -- cgit From 8a8106f06639314f750c9f8dc2b72df3925f7fbf Mon Sep 17 00:00:00 2001 From: Kever Yang Date: Mon, 18 Dec 2017 15:13:19 +0800 Subject: rockchip: update ROCKCHIP_SPL_RESERVE_IRAM to 0 Only rk3399 atf need ROCKCHIP_SPL_RESERVE_IRAM. This commit updates its default setting to 0 so that other SoCs do not need to define it. Signed-off-by: Kever Yang Acked-by: Philipp Tomsich Reviewed-by: Philipp Tomsich --- arch/arm/mach-rockchip/Kconfig | 2 +- configs/evb-rk3399_defconfig | 1 + configs/firefly-rk3399_defconfig | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig index 1e74db3607..967290f9a5 100644 --- a/arch/arm/mach-rockchip/Kconfig +++ b/arch/arm/mach-rockchip/Kconfig @@ -179,7 +179,7 @@ config ROCKCHIP_BOOT_MODE_REG config ROCKCHIP_SPL_RESERVE_IRAM hex "Size of IRAM reserved in SPL" - default 0x4000 + default 0 help SPL may need reserve memory for firmware loaded by SPL, whose load address is in IRAM and may overlay with SPL text area if not diff --git a/configs/evb-rk3399_defconfig b/configs/evb-rk3399_defconfig index 7b5ea821f9..e8e52c3a7c 100644 --- a/configs/evb-rk3399_defconfig +++ b/configs/evb-rk3399_defconfig @@ -4,6 +4,7 @@ CONFIG_SPL_LIBCOMMON_SUPPORT=y CONFIG_SPL_LIBGENERIC_SUPPORT=y CONFIG_SYS_MALLOC_F_LEN=0x4000 CONFIG_ROCKCHIP_RK3399=y +CONFIG_ROCKCHIP_SPL_RESERVE_IRAM=0x4000 CONFIG_SPL_STACK_R_ADDR=0x80000 CONFIG_DEFAULT_DEVICE_TREE="rk3399-evb" CONFIG_DEBUG_UART=y diff --git a/configs/firefly-rk3399_defconfig b/configs/firefly-rk3399_defconfig index 731222cdd0..b8d065414a 100644 --- a/configs/firefly-rk3399_defconfig +++ b/configs/firefly-rk3399_defconfig @@ -4,6 +4,7 @@ CONFIG_SPL_LIBCOMMON_SUPPORT=y CONFIG_SPL_LIBGENERIC_SUPPORT=y CONFIG_SYS_MALLOC_F_LEN=0x4000 CONFIG_ROCKCHIP_RK3399=y +CONFIG_ROCKCHIP_SPL_RESERVE_IRAM=0x4000 CONFIG_SPL_STACK_R_ADDR=0x80000 CONFIG_DEFAULT_DEVICE_TREE="rk3399-firefly" CONFIG_DEBUG_UART=y -- cgit From 157c74b69b8bafa30940516b97f07ae618b555df Mon Sep 17 00:00:00 2001 From: Kever Yang Date: Fri, 15 Dec 2017 11:15:05 +0800 Subject: rockchip: evb-rk3399: update document for board bring up Since we support ATF in SPL and add script for it, let's make the document up to date. Signed-off-by: Kever Yang Acked-by: Philipp Tomsich Reviewed-by: Philipp Tomsich --- board/rockchip/evb_rk3399/README | 83 +++++++++++++++++++++++++++++++--------- 1 file changed, 65 insertions(+), 18 deletions(-) diff --git a/board/rockchip/evb_rk3399/README b/board/rockchip/evb_rk3399/README index fb8bb19763..ada8ca7f3c 100644 --- a/board/rockchip/evb_rk3399/README +++ b/board/rockchip/evb_rk3399/README @@ -18,8 +18,8 @@ evb key features: * PMIC: rk808 * debug console: UART2 -In order to support Arm Trust Firmware(ATF), we need to use the -miniloader from rockchip which: +In order to support Arm Trust Firmware(ATF), we can use either SPL or +miniloader from rockchip to do: * do DRAM init * load and verify ATF image * load and verify U-Boot image @@ -32,8 +32,8 @@ Get the Source and prebuild binary > mkdir ~/evb_rk3399 > cd ~/evb_rk3399 > git clone https://github.com/ARM-software/arm-trusted-firmware.git - > git clone https://github.com/rockchip-linux/rkbin - > git clone https://github.com/rockchip-linux/rkflashtool + > git clone https://github.com/rockchip-linux/rkbin.git + > git clone https://github.com/rockchip-linux/rkdeveloptool.git Compile the ATF =============== @@ -42,32 +42,79 @@ Compile the ATF > make realclean > make CROSS_COMPILE=aarch64-linux-gnu- PLAT=rk3399 bl31 + Or you can get the bl31.elf directly from Rockchip: + cp rkbin/rk33/rk3399_bl31_v1.00.elf ../u-boot/bl31.elf + + Get bl31.elf in this step, copy it to U-Boot root dir: + > cp bl31.elf ../u-boot/ + Compile the U-Boot ================== > cd ../u-boot - > make CROSS_COMPILE=aarch64-linux-gnu- evb-rk3399_defconfig all + > export ARCH=arm64 + > export CROSS_COMPILE=aarch64-linux-gnu- + > make evb-rk3399_defconfig + for firefly-rk3399, use below instead: + > make firefly-rk3399_defconfig + > make + > make u-boot.itb -Compile the rkflashtool -======================= + Get spl/u-boot-spl.bin and u-boot.itb in this step. +Compile the rkdeveloptool +======================= + Follow instructions in latest README > cd ../rkflashtool + > autoreconf -i + > ./configure > make + > sudo make install -Package the image for miniloader -================================ + Get rkdeveloptool in you Host in this step. + +Both origin binaries and Tool are ready now, choose either option 1 or +option 2 to deploy U-Boot. + +Package the image +================= + +Package the image for U-Boot SPL(option 1) +-------------------------------- > cd .. - > cp arm-trusted-firmware/build/rk3399/release/bl31.bin rkbin/rk33 + > tools/mkimage -n rk3399 -T rksd -d spl/u-boot-spl.bin idbspl.img + + Get idbspl.img in this step. + +Package the image for Rockchip miniloader(option 2) +------------------------------------------ + > cd .. + > cp arm-trusted-firmware/build/rk3399/release/bl31.elf rkbin/rk33 > ./rkbin/tools/trust_merger rkbin/tools/RK3399TRUST.ini > ./rkbin/tools/loaderimage --pack --uboot u-boot/u-boot-dtb.bin uboot.img - > mkdir image - > mv trust.img ./image/ - > mv uboot.img ./image/rk3399evb-uboot.bin -Flash the image -=============== -Power on(or reset with RESET KEY) with MASKROM KEY preesed, and then: + Get trust.img and uboot.img in this step. - > ./rkflashtool/rkflashloader rk3399evb +Flash the image to eMMC +======================= + +Flash the image with U-Boot SPL(option 1) +------------------------------- +Power on(or reset with RESET KEY) with MASKROM KEY preesed, and then: + > rkdeveloptool db rkbin/rk33/rk3399_loader_v1.08.106.bin + > rkdeveloptool wl 64 u-boot/idbspl.img + > rkdeveloptool wl 0x4000 u-boot/u-boot.itb + > rkdeveloptool rd -You should be able to get U-Boot log message in console/UART2 now. +Flash the image with Rockchip miniloader(option 2) +---------------------------------------- +Power on(or reset with RESET KEY) with MASKROM KEY preesed, and then: + > rkdeveloptool db rkbin/rk33/rk3399_loader_v1.08.106.bin + > rkdeveloptool ul rkbin/rk33/rk3399_loader_v1.08.106.bin + > rkdeveloptool wl 0x4000 u-boot/uboot.img + > rkdeveloptool wl 0x6000 u-boot/trust.img + > rkdeveloptool rd + +You should be able to get U-Boot log in console/UART2(baurdrate 1500000) +For more detail, please reference to: +http://opensource.rock-chips.com/wiki_Boot_option -- cgit From 1a066c22f233fcf59b2e8cddf295b98b6998e037 Mon Sep 17 00:00:00 2001 From: Kever Yang Date: Fri, 15 Dec 2017 11:15:04 +0800 Subject: rockchip: firefly-rk3399: add FIT for rk3399 Enable SPL_FIT_GENERATOR with path for it. With this patch you can get u-boot.itb for rk3399-firefly with: > make u-boot.itb Signed-off-by: Kever Yang Reviewed-by: Mark Kettenis Tested-by: Mark Kettenis Acked-by: Philipp Tomsich Reviewed-by: Philipp Tomsich --- configs/firefly-rk3399_defconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/firefly-rk3399_defconfig b/configs/firefly-rk3399_defconfig index b8d065414a..ab2501528f 100644 --- a/configs/firefly-rk3399_defconfig +++ b/configs/firefly-rk3399_defconfig @@ -10,6 +10,7 @@ CONFIG_DEFAULT_DEVICE_TREE="rk3399-firefly" CONFIG_DEBUG_UART=y CONFIG_FIT=y CONFIG_SPL_LOAD_FIT=y +CONFIG_SPL_FIT_GENERATOR="arch/arm/mach-rockchip/make_fit_atf.py" # CONFIG_DISPLAY_CPUINFO is not set CONFIG_SPL_STACK_R=y CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN=0x4000 -- cgit From cbe503793aba03c19b8d21e0a6e344afe624e2d6 Mon Sep 17 00:00:00 2001 From: Kever Yang Date: Fri, 15 Dec 2017 11:15:03 +0800 Subject: rockchip: add a common script for generate fit its Rockchip release bl31.elf file for armv8 SoCs like rk3399, rk3328, the elf have more than one section, we need to decode it first and packed them into u-boot.itb with its file. This script is to generate the its script. Need default bl31.elf in root directory of U-Boot source and dtb as parameter. Signed-off-by: Kever Yang Acked-by: Philipp Tomsich Reviewed-by: Philipp Tomsich --- arch/arm/mach-rockchip/make_fit_atf.py | 221 +++++++++++++++++++++++++++++++++ 1 file changed, 221 insertions(+) create mode 100755 arch/arm/mach-rockchip/make_fit_atf.py diff --git a/arch/arm/mach-rockchip/make_fit_atf.py b/arch/arm/mach-rockchip/make_fit_atf.py new file mode 100755 index 0000000000..7c6dd57678 --- /dev/null +++ b/arch/arm/mach-rockchip/make_fit_atf.py @@ -0,0 +1,221 @@ +#!/usr/bin/env python2 +""" +A script to generate FIT image source for rockchip boards +with ARM Trusted Firmware +and multiple device trees (given on the command line) + +usage: $0 [ [; + + images { + uboot@1 { + description = "U-Boot (64-bit)"; + data = /incbin/("u-boot-nodtb.bin"); + type = "standalone"; + os = "U-Boot"; + arch = "arm64"; + compression = "none"; + load = <0x%08x>; + }; +""" + +DT_IMAGES_NODE_END=""" + }; +""" + +DT_END=""" +}; +""" + +def append_atf_node(file, atf_index, phy_addr): + """ + Append ATF DT node to input FIT dts file. + """ + data = 'bl31_0x%08x.bin' % phy_addr + print >> file, '\t\tatf@%d {' % atf_index + print >> file, '\t\t\tdescription = \"ARM Trusted Firmware\";' + print >> file, '\t\t\tdata = /incbin/("%s");' % data + print >> file, '\t\t\ttype = "firmware";' + print >> file, '\t\t\tarch = "arm64";' + print >> file, '\t\t\tos = "arm-trusted-firmware";' + print >> file, '\t\t\tcompression = "none";' + print >> file, '\t\t\tload = <0x%08x>;' % phy_addr + if atf_index == 1: + print >> file, '\t\t\tentry = <0x%08x>;' % phy_addr + print >> file, '\t\t};' + print >> file, '' + +def append_fdt_node(file, dtbs): + """ + Append FDT nodes. + """ + cnt = 1 + for dtb in dtbs: + dtname = os.path.basename(dtb) + print >> file, '\t\tfdt@%d {' % cnt + print >> file, '\t\t\tdescription = "%s";' % dtname + print >> file, '\t\t\tdata = /incbin/("%s");' % dtb + print >> file, '\t\t\ttype = "flat_dt";' + print >> file, '\t\t\tcompression = "none";' + print >> file, '\t\t};' + print >> file, '' + cnt = cnt + 1 + +def append_conf_section(file, cnt, dtname, atf_cnt): + print >> file, '\t\tconfig@%d {' % cnt + print >> file, '\t\t\tdescription = "%s";' % dtname + print >> file, '\t\t\tfirmware = "atf@1";' + print >> file, '\t\t\tloadables = "uboot@1",', + for i in range(1, atf_cnt): + print >> file, '"atf@%d"' % (i+1), + if i != (atf_cnt - 1): + print >> file, ',', + else: + print >> file, ';' + print >> file, '\t\t\tfdt = "fdt@1";' + print >> file, '\t\t};' + print >> file, '' + +def append_conf_node(file, dtbs, atf_cnt): + """ + Append configeration nodes. + """ + cnt = 1 + print >> file, '\tconfigurations {' + print >> file, '\t\tdefault = "config@1";' + for dtb in dtbs: + dtname = os.path.basename(dtb) + append_conf_section(file, cnt, dtname, atf_cnt) + cnt = cnt + 1 + print >> file, '\t};' + print >> file, '' + +def generate_atf_fit_dts(fit_file_name, bl31_file_name, uboot_file_name, dtbs_file_name): + """ + Generate FIT script for ATF image. + """ + if fit_file_name != sys.stdout: + fit_file = open(fit_file_name, "wb") + else: + fit_file = sys.stdout + + num_load_seg = 0 + p_paddr = 0xFFFFFFFF + with open(uboot_file_name) as uboot_file: + uboot = ELFFile(uboot_file) + for i in range(uboot.num_segments()): + seg = uboot.get_segment(i) + if ('PT_LOAD' == seg.__getitem__(ELF_SEG_P_TYPE)): + p_paddr = seg.__getitem__(ELF_SEG_P_PADDR) + num_load_seg = num_load_seg + 1 + + assert (p_paddr != 0xFFFFFFFF and num_load_seg == 1) + + print >> fit_file, DT_HEADER % p_paddr + + with open(bl31_file_name) as bl31_file: + bl31 = ELFFile(bl31_file) + for i in range(bl31.num_segments()): + seg = bl31.get_segment(i) + if ('PT_LOAD' == seg.__getitem__(ELF_SEG_P_TYPE)): + paddr = seg.__getitem__(ELF_SEG_P_PADDR) + p= seg.__getitem__(ELF_SEG_P_PADDR) + append_atf_node(fit_file, i+1, paddr) + atf_cnt = i+1 + append_fdt_node(fit_file, dtbs_file_name) + print >> fit_file, '%s' % DT_IMAGES_NODE_END + append_conf_node(fit_file, dtbs_file_name, atf_cnt) + print >> fit_file, '%s' % DT_END + + if fit_file_name != sys.stdout: + fit_file.close() + +def generate_atf_binary(bl31_file_name): + with open(bl31_file_name) as bl31_file: + bl31 = ELFFile(bl31_file) + + num = bl31.num_segments() + for i in range(num): + seg = bl31.get_segment(i) + if ('PT_LOAD' == seg.__getitem__(ELF_SEG_P_TYPE)): + paddr = seg.__getitem__(ELF_SEG_P_PADDR) + file_name = 'bl31_0x%08x.bin' % paddr + with open(file_name, "wb") as atf: + atf.write(seg.data()); + +def get_bl31_segments_info(bl31_file_name): + """ + Get load offset, physical offset, file size + from bl31 elf file program headers. + """ + with open(bl31_file_name) as bl31_file: + bl31 = ELFFile(bl31_file) + + num = bl31.num_segments() + print 'Number of Segments : %d' % bl31.num_segments() + for i in range(num): + print 'Segment %d' % i + seg = bl31.get_segment(i) + ptype = seg[ELF_SEG_P_TYPE] + poffset = seg[ELF_SEG_P_OFFSET] + pmemsz = seg[ELF_SEG_P_MEMSZ] + pfilesz = seg[ELF_SEG_P_FILESZ] + print 'type: %s\nfilesz: %08x\nmemsz: %08x\noffset: %08x' % (ptype, pfilesz, pmemsz, poffset) + paddr = seg[ELF_SEG_P_PADDR] + print 'paddr: %08x' % paddr + +def main(): + uboot_elf="./u-boot" + bl31_elf="./bl31.elf" + FIT_ITS=sys.stdout + + opts, args = getopt.getopt(sys.argv[1:], "o:u:b:h") + for opt, val in opts: + if opt == "-o": + FIT_ITS=val + elif opt == "-u": + uboot_elf=val + elif opt == "-b": + bl31_elf=val + elif opt == "-h": + print __doc__ + sys.exit(2) + + dtbs = args + #get_bl31_segments_info("u-boot") + #get_bl31_segments_info("bl31.elf") + + generate_atf_fit_dts(FIT_ITS, bl31_elf, uboot_elf, dtbs) + generate_atf_binary(bl31_elf); + +if __name__ == "__main__": + main() -- cgit