Re: [U-Boot] [RFC PATCH] rockchip, Makefile: add u-boot-tpl-with-spl.img target
Simon Glass wrote: Chris Webb wrote: My worry about using binman for cracking such a simple nut is the dependencies it pulls in that wouldn't otherwise be needed: the documentation suggests at least lzma-alone, liblz4, and pyelftools. I should probably update this. Unless you use compression and SPL symbols you shouldn't need these. Hi Simon. If it doesn't pull in these extra dependencies, please ignore my concern/objection above. I was kind of hoping you'd tell me I was wrong! :) We've just exorcised the pyelftools requirement for building Rockchip u-boot; it would be a pity for to re-inflict it on users and casual developers just for a convenience feature. You mean make_fit_atf.py? Again I think that this logic should be moved into binman. It doesn't actually have support to generic FITs but should. We don't use a lot from this library so perhaps could adopt a similar implmentation. Happy to try to help if I can; ELF is just a collection of fixed C-style structures so is dead easy to parse with Python's built in struct support. The only (minor) complication for binman compared to make_fit_atf.py is the need work across 32/64-bit and big/little-endian platforms. Field sizes and therefore offsets vary between the two cases of 32-bit and 64-bit ELF files. (I could just verify 64-bit little-endian ARM and then used fixed offsets in make_fit_atf.py.) Best wishes, Chris. ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
Re: [U-Boot] [RFC PATCH] rockchip, Makefile: add u-boot-tpl-with-spl.img target
Mark Kettenis wrote: [Simon Glass wrote:] Well, for producing an image that works. E.g. producing a full image (TPL, SPL and U-Boot) for an SD card - it would be nice to have u-boot-rockchip.sd.bin or something like that. True. That'd be an image you write at certain offset I suppose so it preserves the MBR/partition tables? This is also just concatenation and padding, surely? tools/mkimage -n rk3399 -T rksd -d tpl/u-boot-tpl-dtb.bin u-boot-sd.img cat spl/u-boot-spl-dtb.bin >>u-boot-sd.img dd if=u-boot.itb of=u-boot-sd.img seek=16320 # 16384 - 64 ...or truncate(1) and cat(1) instead of dd(1) if you prefer. As you say, Mark, this assumes it's meant to be written at offset 64 sectors in to avoid blowing away the partition table. (Pad with 64 leading NULs if it's supposed to be a bootable card image I guess.) My worry about using binman for cracking such a simple nut is the dependencies it pulls in that wouldn't otherwise be needed: the documentation suggests at least lzma-alone, liblz4, and pyelftools. We've just exorcised the pyelftools requirement for building Rockchip u-boot; it would be a pity for to re-inflict it on users and casual developers just for a convenience feature. Best wishes, Chris. ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
Re: [U-Boot] [RFC PATCH] rockchip, Makefile: add u-boot-tpl-with-spl.img target
Matwey V. Kornilov wrote: Here, we introduce generic u-boot-tpl-with-spl.img target which is the TPL image followed by the SPL binary. Having built U-Boot TPL + SPL images over and over again for testing on various rk3399 hardware, something like this would certainly be a convenience. It would simplify instructions to end users too. Best wishes, Chris. ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
Re: [U-Boot] [PATCH v3 3/3] arm64: dts: rockchip: Add support for Khadas Edge-Captain
xieqin...@gmail.com wrote: From: Nick Xie Add devicetree support for Khadas Edge-Captain. Khadas Captain is the carrier board for Khadas Edge. Tested-by: Chris Webb Here's the boot log of TPL -> SPL -> U-Boot proper -> Linux on a 4GB Edge board in a Captain V12 carrier, booting from a card in the carrier board uSD slot: U-Boot TPL 2019.10-rc1-3-g3027e6a322 (Jul 30 2019 - 15:49:25) Trying to boot from BOOTROM Returning to boot ROM... U-Boot SPL 2019.10-rc1-3-g3027e6a322 (Jul 30 2019 - 15:49:25 +0100) Trying to boot from MMC1 U-Boot 2019.10-rc1-3-g3027e6a322 (Jul 30 2019 - 15:49:25 +0100) Model: Khadas Edge-Captain DRAM: 3.9 GiB Cannot find regulator pwm init_voltage MMC: dwmmc@fe31: 2, dwmmc@fe32: 1, sdhci@fe33: 0 Loading Environment from MMC... *** Warning - bad CRC, using default environment In:serial@ff1a Out: serial@ff1a Err: serial@ff1a Model: Khadas Edge-Captain rockchip_dnl_key_pressed: adc_channel_single_shot fail! Net: Warning: ethernet@fe30 (eth0) using random MAC address - fe:af:d6:78:94:dd eth0: ethernet@fe30 Hit any key to stop autoboot: 0 switch to partitions #0, OK mmc0(part 0) is current device ** No partition table - mmc 0 ** switch to partitions #0, OK mmc1 is current device Scanning mmc 1:1... Found /boot/extlinux/extlinux.conf Retrieving file: /boot/extlinux/extlinux.conf 182 bytes read in 9 ms (19.5 KiB/s) 1: Linux Retrieving file: /boot/Image 17600520 bytes read in 748 ms (22.4 MiB/s) append: root=179:1 rw console=uart8250,mmio32,0xff1a init=/bin/bash Retrieving file: /boot/rk3399-khadas-edge.dtb 55654 bytes read in 10 ms (5.3 MiB/s) ## Flattened Device Tree blob at 01f0 Booting using the fdt blob at 0x1f0 Loading Device Tree to f5f14000, end f5f24965 ... OK Starting kernel ... [1.333010] rockchip-drm display-subsystem: failed to bind ff94.hdmi (ops dw_hdmi_rockchip_ops): -517 [1.342980] rk_gmac-dwmac fe30.ethernet: phy regulator is not available yet, deferred probing [1.648786] rk_gmac-dwmac fe30.ethernet: cannot get clock clk_mac_speed bash: cannot set terminal process group (-1): Not a tty bash: no job control in this shell bash-4.4# Best wishes, Chris. ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
Re: [U-Boot] [PATCH v3 1/3] arm64: dts: rockchip: Add support for Khadas Edge
xieqin...@gmail.com wrote: From: Nick Xie Add devicetree support for Khadas Edge. Khadas Edge is an expandable Rockchip RK3399 board with goldfinger. Tested-by: Chris Webb Here's the boot log of TPL -> SPL -> U-Boot proper -> Linux on a 4GB Edge board booting from an SD card: U-Boot TPL 2019.10-rc1-3-g3027e6a322 (Jul 30 2019 - 15:36:43) Trying to boot from BOOTROM Returning to boot ROM... U-Boot SPL 2019.10-rc1-3-g3027e6a322 (Jul 30 2019 - 15:36:43 +0100) Trying to boot from MMC1 U-Boot 2019.10-rc1-3-g3027e6a322 (Jul 30 2019 - 15:36:43 +0100) Model: Khadas Edge DRAM: 3.9 GiB Cannot find regulator pwm init_voltage MMC: dwmmc@fe31: 2, dwmmc@fe32: 1, sdhci@fe33: 0 Loading Environment from MMC... *** Warning - bad CRC, using default environment In:serial@ff1a Out: serial@ff1a Err: serial@ff1a Model: Khadas Edge rockchip_dnl_key_pressed: adc_channel_single_shot fail! Net: No ethernet found. Hit any key to stop autoboot: 0 switch to partitions #0, OK mmc0(part 0) is current device ** No partition table - mmc 0 ** switch to partitions #0, OK mmc1 is current device Scanning mmc 1:1... Found /boot/extlinux/extlinux.conf Retrieving file: /boot/extlinux/extlinux.conf 182 bytes read in 10 ms (17.6 KiB/s) 1: Linux Retrieving file: /boot/Image 17600520 bytes read in 749 ms (22.4 MiB/s) append: root=179:1 rw console=uart8250,mmio32,0xff1a init=/bin/bash Retrieving file: /boot/rk3399-khadas-edge.dtb 55654 bytes read in 10 ms (5.3 MiB/s) ## Flattened Device Tree blob at 01f0 Booting using the fdt blob at 0x1f0 Loading Device Tree to f5f14000, end f5f24965 ... OK Starting kernel ... [1.333076] rockchip-drm display-subsystem: failed to bind ff94.hdmi (ops dw_hdmi_rockchip_ops): -517 [1.343026] rk_gmac-dwmac fe30.ethernet: phy regulator is not available yet, deferred probing [1.652854] rk_gmac-dwmac fe30.ethernet: cannot get clock clk_mac_speed bash: cannot set terminal process group (-1): Not a tty bash: no job control in this shell bash-4.4# Best wishes, Chris. ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
Re: [U-Boot] [PATCH] rockchip: rk3399: Add Khadas Edge board support
Nick Xie wrote: That's great! I'll update the patches and send them soon. I'll make sure I test your specific patch when you post it, but I can already confirm that u-boot.git master happily boots a Khadas Edge board. I just added the unmodified Edge device tree from mainline Linux into arch/arm/dts/, created the u-boot fixup .dtsi and defconfig with sed 's/rock-pi-4/khadas-edge/g' configs/rock-pi-4-rk3399_defconfig \ >configs/khadas-edge-rk3399_defconfig cp arch/arm/dts/rk3399-{rock-pi-4,khadas-edge}-u-boot.dtsi make khadas-edge-rk3399_defconfig then built u-boot with an rk3399 bl31.elf from master of arm-trusted-firmware.git. It boots TPL -> SPL -> U-Boot proper -> Linux just fine without any external idbloader.bin or standalone trusted firmware - faster and much less noisy! Best wishes, Chris. ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
Re: [U-Boot] [PATCH] rockchip: rk3399: Add Khadas Edge board support
Hi Nick. I think Kever has merged the LPDDR4 series, and it's already made its way into the mainline u-boot master branch. https://gitlab.denx.de/u-boot/u-boot/commit/852f6ddd76fad2d5adef3f7e3a75d0065c68db3b and its ancestors are the v3 series Jagan posted to the list. There have also been a number of other rk3399 cleanups since then, so the defconfig might need updating to suit. (I just copied the rock-pi-4 defconfig and replaced the default device tree.) Best wishes, Chris. ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
[U-Boot] [PATCH 2/2] rockchip: TPL banner should depend on CONFIG_TPL_BANNER_PRINT
The generic code in common/spl/spl.c allows TPL/SPL banners to be silenced by unsetting CONFIG_TPL_BANNER_PRINT or CONFIG_SPL_BANNER_PRINT respectively. However, arch/arm/mach-rockchip/tpl.c prints this banner unconditionally. Fix the rockchip-specific tpl.c so that the TPL banner depends on CONFIG_TPL_BANNER_PRINT in the same way as the generic code. Signed-off-by: --- arch/arm/mach-rockchip/tpl.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm/mach-rockchip/tpl.c b/arch/arm/mach-rockchip/tpl.c index 5df88bddeb..55f6e922d0 100644 --- a/arch/arm/mach-rockchip/tpl.c +++ b/arch/arm/mach-rockchip/tpl.c @@ -54,8 +54,10 @@ void board_init_f(ulong dummy) * printascii("string"); */ debug_uart_init(); +#ifdef CONFIG_TPL_BANNER_PRINT printascii("\nU-Boot TPL " PLAIN_VERSION " (" U_BOOT_DATE " - " \ U_BOOT_TIME ")\n"); +#endif #endif ret = spl_early_init(); if (ret) { ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
[U-Boot] [PATCH 1/2] rockchip: Fix TPL build without CONFIG_TPL_SERIAL_SUPPORT
If CONFIG_DEBUG_UART is set but CONFIG_TPL_SERIAL_SUPPORT is not, the serial output should be available in SPL and full U-Boot, but not built in TPL. However, the rockchip tpl.c instead fails to compile with undefined references to the debug UART. Instead, initialise the debug UART and print the TPL banner only if both CONFIG_DEBUG_UART and CONFIG_TPL_SERIAL_SUPPORT are set. Signed-off-by: --- arch/arm/mach-rockchip/tpl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/mach-rockchip/tpl.c b/arch/arm/mach-rockchip/tpl.c index 0ff2a197ed..5df88bddeb 100644 --- a/arch/arm/mach-rockchip/tpl.c +++ b/arch/arm/mach-rockchip/tpl.c @@ -44,7 +44,7 @@ void board_init_f(ulong dummy) struct udevice *dev; int ret; -#ifdef CONFIG_DEBUG_UART +#if defined(CONFIG_DEBUG_UART) && defined(CONFIG_TPL_SERIAL_SUPPORT) /* * Debug UART can be used from here if required: * ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
[U-Boot] [PATCH 0/2] rockchip: tpl.c #ifdef fixes
These are two trivial patches which fix up the #ifdef conditionals in mach-rockchip/tpl.c to do the right thing in two configuration scenarios: 1. Debug UART enabled (for SPL and main U-Boot) but serial support disabled for the TPL stage. 2. TPL banner disabled by unsetting CONFIG_TPL_BANNER_PRINT. I stumbled over these edge cases while trying various permitted config permutations, trying to make U-Boot less noisy without killing useful error messages. The diffs are against u-boot-rockchip.git: this already has changes that haven't yet reached mainline u-boot yet, moving the relevant code from board specific source files into the shared mach-rockchip/tpl.c. ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
[U-Boot] [PATCH v3 2/2] rockchip: Remove obsolete references to pyelftools
make_fit_atf.py no longer requires pyelftools, and nothing else in the rockchip build requires it either, so remove references to installing it from the documentation. Signed-off-by: Chris Webb --- board/rockchip/evb_rk3399/README | 6 -- doc/README.rockchip | 4 2 files changed, 10 deletions(-) diff --git a/board/rockchip/evb_rk3399/README b/board/rockchip/evb_rk3399/README index 6469821987..ea3258cf37 100644 --- a/board/rockchip/evb_rk3399/README +++ b/board/rockchip/evb_rk3399/README @@ -35,12 +35,6 @@ Get the Source and prebuild binary > git clone https://github.com/rockchip-linux/rkbin.git > git clone https://github.com/rockchip-linux/rkdeveloptool.git -Get some prerequisites -== - -You need the Python elftools.elf.elffile library for make_fit_atf.py to work: - - > sudo apt-get install python-pyelftools Compile ATF === diff --git a/doc/README.rockchip b/doc/README.rockchip index 02e2497b15..8ccbb87264 100644 --- a/doc/README.rockchip +++ b/doc/README.rockchip @@ -123,10 +123,6 @@ For example: Option 2: Package the image with SPL: - - We need the Python elftools.elf.elffile library for make_fit_atf.py to work - - => sudo apt-get install python-pyelftools - - Export cross compiler path for aarch64 - Compile ATF ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
[U-Boot] [PATCH v3 1/2] rockchip: make_fit_atf.py: Eliminate pyelftools dependency
make_fit_aft.py depends on the non-standard library pyelftools to pull out PT_LOAD segments from ELF files. However, this is as easy to do manually, without imposing the extra dependency on users. Structures in the ELF file are unpacked into variables named to exactly match the ELF spec to ensure the destructuring code is reasonably self-documenting. Signed-off-by: Chris Webb --- arch/arm/mach-rockchip/make_fit_atf.py | 75 +++--- 1 file changed, 32 insertions(+), 43 deletions(-) diff --git a/arch/arm/mach-rockchip/make_fit_atf.py b/arch/arm/mach-rockchip/make_fit_atf.py index db0ae96ca8..b9a1988298 100755 --- a/arch/arm/mach-rockchip/make_fit_atf.py +++ b/arch/arm/mach-rockchip/make_fit_atf.py @@ -13,16 +13,7 @@ import os import sys import getopt import logging - -# pip install pyelftools -from elftools.elf.elffile import ELFFile - -ELF_SEG_P_TYPE = 'p_type' -ELF_SEG_P_PADDR = 'p_paddr' -ELF_SEG_P_VADDR = 'p_vaddr' -ELF_SEG_P_OFFSET = 'p_offset' -ELF_SEG_P_FILESZ = 'p_filesz' -ELF_SEG_P_MEMSZ = 'p_memsz' +import struct DT_HEADER = """ /* @@ -118,33 +109,19 @@ def append_conf_node(file, dtbs, segments): file.write('\n') def generate_atf_fit_dts_uboot(fit_file, uboot_file_name): -num_load_seg = 0 -p_paddr = 0x -with open(uboot_file_name, 'rb') as uboot_file: -uboot = ELFFile(uboot_file) -for i in range(uboot.num_segments()): -seg = uboot.get_segment(i) -if seg.__getitem__(ELF_SEG_P_TYPE) == 'PT_LOAD': -p_paddr = seg.__getitem__(ELF_SEG_P_PADDR) -num_load_seg = num_load_seg + 1 - -assert (p_paddr != 0x and num_load_seg == 1) - +segments = unpack_elf(uboot_file_name) +if len(segments) != 1: +raise ValueError("Invalid u-boot ELF image '%s'" % uboot_file_name) +index, entry, p_paddr, data = segments[0] fit_file.write(DT_UBOOT % p_paddr) def generate_atf_fit_dts_bl31(fit_file, bl31_file_name, dtbs_file_name): -with open(bl31_file_name, 'rb') as bl31_file: -bl31 = ELFFile(bl31_file) -elf_entry = bl31.header['e_entry'] -segments = bl31.num_segments() -for i in range(segments): -seg = bl31.get_segment(i) -if seg.__getitem__(ELF_SEG_P_TYPE) == 'PT_LOAD': -paddr = seg.__getitem__(ELF_SEG_P_PADDR) -append_bl31_node(fit_file, i + 1, paddr, elf_entry) +segments = unpack_elf(bl31_file_name) +for index, entry, paddr, data in segments: +append_bl31_node(fit_file, index + 1, paddr, entry) append_fdt_node(fit_file, dtbs_file_name) fit_file.write(DT_IMAGES_NODE_END) -append_conf_node(fit_file, dtbs_file_name, segments) +append_conf_node(fit_file, dtbs_file_name, len(segments)) def generate_atf_fit_dts(fit_file_name, bl31_file_name, uboot_file_name, dtbs_file_name): # Generate FIT script for ATF image. @@ -162,17 +139,29 @@ def generate_atf_fit_dts(fit_file_name, bl31_file_name, uboot_file_name, dtbs_fi fit_file.close() def generate_atf_binary(bl31_file_name): -with open(bl31_file_name, 'rb') as bl31_file: -bl31 = ELFFile(bl31_file) - -num = bl31.num_segments() -for i in range(num): -seg = bl31.get_segment(i) -if seg.__getitem__(ELF_SEG_P_TYPE) == 'PT_LOAD': -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()) +for index, entry, paddr, data in unpack_elf(bl31_file_name): +file_name = 'bl31_0x%08x.bin' % paddr +with open(file_name, "wb") as atf: +atf.write(data) + +def unpack_elf(filename): +with open(filename, 'rb') as file: +elf = file.read() +if elf[0:7] != b'\x7fELF\x02\x01\x01' or elf[18:20] != b'\xb7\x00': +raise ValueError("Invalid arm64 ELF file '%s'" % filename) + +e_entry, e_phoff = struct.unpack_from('<2Q', elf, 0x18) +e_phentsize, e_phnum = struct.unpack_from('<2H', elf, 0x36) +segments = [] + +for index in range(e_phnum): +offset = e_phoff + e_phentsize * index +p_type, p_flags, p_offset = struct.unpack_from('https://lists.denx.de/listinfo/u-boot
[U-Boot] [PATCH v3 0/2] rockchip: make_fit_atf.py Eliminate pyelftools dependency
Building for rockchip, make_fit_atf.py depends on pyelftools, a non-bundled python module that is not used elsewhere in building u-boot or the kernel. We only use pyelftools to pull out PT_LOAD segments. ELF is very simple, so doing this manually is easy and spares users the extra dependency. In fact, a straightforward implementation shrinks make_fit_aft.py rather than adding complexity. Andy Yan's patch https://gitlab.denx.de/u-boot/custodians/u-boot-rockchip/commit/619f002db864ef8caa30863bde62df5c651a7312 is a prerequisite for this. The new code does not erroneously count GNU_STACK sections and therefore without the above patch, the loadables in the conf section will always be one short, even where GNU_STACK is present. I have tested this script with python 2 and 3 against all bl31 elf files at https://github.com/rockchip-linux/rkbin/tree/master/bin/rk33 as well as an rk3399 bl31.elf built locally from the master branch of https://github.com/ARM-software/arm-trusted-firmware to which my toolchain added the extra GNU_STACK segment. In each case, identical *.bin files were produced compared to the pyelftools implementation, and a correct .its configuration (without off-by-one error) was emitted, with and without dtbs supplied to the script. Changes in v2: - no exception on a valid but completely empty bl31 ELF file - restrict documentation updates to the Rockchip docs (!) Changes in v3: - code style: add correct whitespace around multiply operator ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
Re: [U-Boot] [PATCH v2 1/2] rockchip: make_fit_atf.py: Eliminate pyelftools dependency
Hi Andy and Kever Andy Yan writes: > One small coding style issue: > > offset = e_phoff + e_phentsize * index Thanks, will fix this. Kever Yang writes: > Please fix the coding style comment by Andy, for other codes: > > Reviewed-by: Kever Yang Newbie contributor so can I check: is it right to add this Reviewed-by: line to the end of the patch commit message after my Signed-off-by: when I resend the patches as v3 with the style correction? Many thanks, Chris. ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
[U-Boot] [PATCH v2 2/2] rockchip: Remove obsolete references to pyelftools
make_fit_atf.py no longer requires pyelftools, and nothing else in the rockchip build requires it either, so remove references to installing it from the documentation. Signed-off-by: Chris Webb --- board/rockchip/evb_rk3399/README | 6 -- doc/README.rockchip | 4 2 files changed, 10 deletions(-) diff --git a/board/rockchip/evb_rk3399/README b/board/rockchip/evb_rk3399/README index 6469821987..ea3258cf37 100644 --- a/board/rockchip/evb_rk3399/README +++ b/board/rockchip/evb_rk3399/README @@ -35,12 +35,6 @@ Get the Source and prebuild binary > git clone https://github.com/rockchip-linux/rkbin.git > git clone https://github.com/rockchip-linux/rkdeveloptool.git -Get some prerequisites -== - -You need the Python elftools.elf.elffile library for make_fit_atf.py to work: - - > sudo apt-get install python-pyelftools Compile ATF === diff --git a/doc/README.rockchip b/doc/README.rockchip index 02e2497b15..8ccbb87264 100644 --- a/doc/README.rockchip +++ b/doc/README.rockchip @@ -123,10 +123,6 @@ For example: Option 2: Package the image with SPL: - - We need the Python elftools.elf.elffile library for make_fit_atf.py to work - - => sudo apt-get install python-pyelftools - - Export cross compiler path for aarch64 - Compile ATF ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
[U-Boot] [PATCH v2 1/2] rockchip: make_fit_atf.py: Eliminate pyelftools dependency
make_fit_aft.py depends on the non-standard library pyelftools to pull out PT_LOAD segments from ELF files. However, this is as easy to do manually, without imposing the extra dependency on users. Structures in the ELF file are unpacked into variables named to exactly match the ELF spec to ensure the destructuring code is reasonably self-documenting. Signed-off-by: Chris Webb --- arch/arm/mach-rockchip/make_fit_atf.py | 75 +++--- 1 file changed, 32 insertions(+), 43 deletions(-) diff --git a/arch/arm/mach-rockchip/make_fit_atf.py b/arch/arm/mach-rockchip/make_fit_atf.py index db0ae96ca8..9acc1edfc6 100755 --- a/arch/arm/mach-rockchip/make_fit_atf.py +++ b/arch/arm/mach-rockchip/make_fit_atf.py @@ -13,16 +13,7 @@ import os import sys import getopt import logging - -# pip install pyelftools -from elftools.elf.elffile import ELFFile - -ELF_SEG_P_TYPE = 'p_type' -ELF_SEG_P_PADDR = 'p_paddr' -ELF_SEG_P_VADDR = 'p_vaddr' -ELF_SEG_P_OFFSET = 'p_offset' -ELF_SEG_P_FILESZ = 'p_filesz' -ELF_SEG_P_MEMSZ = 'p_memsz' +import struct DT_HEADER = """ /* @@ -118,33 +109,19 @@ def append_conf_node(file, dtbs, segments): file.write('\n') def generate_atf_fit_dts_uboot(fit_file, uboot_file_name): -num_load_seg = 0 -p_paddr = 0x -with open(uboot_file_name, 'rb') as uboot_file: -uboot = ELFFile(uboot_file) -for i in range(uboot.num_segments()): -seg = uboot.get_segment(i) -if seg.__getitem__(ELF_SEG_P_TYPE) == 'PT_LOAD': -p_paddr = seg.__getitem__(ELF_SEG_P_PADDR) -num_load_seg = num_load_seg + 1 - -assert (p_paddr != 0x and num_load_seg == 1) - +segments = unpack_elf(uboot_file_name) +if len(segments) != 1: +raise ValueError("Invalid u-boot ELF image '%s'" % uboot_file_name) +index, entry, p_paddr, data = segments[0] fit_file.write(DT_UBOOT % p_paddr) def generate_atf_fit_dts_bl31(fit_file, bl31_file_name, dtbs_file_name): -with open(bl31_file_name, 'rb') as bl31_file: -bl31 = ELFFile(bl31_file) -elf_entry = bl31.header['e_entry'] -segments = bl31.num_segments() -for i in range(segments): -seg = bl31.get_segment(i) -if seg.__getitem__(ELF_SEG_P_TYPE) == 'PT_LOAD': -paddr = seg.__getitem__(ELF_SEG_P_PADDR) -append_bl31_node(fit_file, i + 1, paddr, elf_entry) +segments = unpack_elf(bl31_file_name) +for index, entry, paddr, data in segments: +append_bl31_node(fit_file, index + 1, paddr, entry) append_fdt_node(fit_file, dtbs_file_name) fit_file.write(DT_IMAGES_NODE_END) -append_conf_node(fit_file, dtbs_file_name, segments) +append_conf_node(fit_file, dtbs_file_name, len(segments)) def generate_atf_fit_dts(fit_file_name, bl31_file_name, uboot_file_name, dtbs_file_name): # Generate FIT script for ATF image. @@ -162,17 +139,29 @@ def generate_atf_fit_dts(fit_file_name, bl31_file_name, uboot_file_name, dtbs_fi fit_file.close() def generate_atf_binary(bl31_file_name): -with open(bl31_file_name, 'rb') as bl31_file: -bl31 = ELFFile(bl31_file) - -num = bl31.num_segments() -for i in range(num): -seg = bl31.get_segment(i) -if seg.__getitem__(ELF_SEG_P_TYPE) == 'PT_LOAD': -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()) +for index, entry, paddr, data in unpack_elf(bl31_file_name): +file_name = 'bl31_0x%08x.bin' % paddr +with open(file_name, "wb") as atf: +atf.write(data) + +def unpack_elf(filename): +with open(filename, 'rb') as file: +elf = file.read() +if elf[0:7] != b'\x7fELF\x02\x01\x01' or elf[18:20] != b'\xb7\x00': +raise ValueError("Invalid arm64 ELF file '%s'" % filename) + +e_entry, e_phoff = struct.unpack_from('<2Q', elf, 0x18) +e_phentsize, e_phnum = struct.unpack_from('<2H', elf, 0x36) +segments = [] + +for index in range(e_phnum): +offset = e_phoff + e_phentsize*index +p_type, p_flags, p_offset = struct.unpack_from('https://lists.denx.de/listinfo/u-boot
[U-Boot] [PATCH v2 0/2] rockchip: make_fit_atf.py Eliminate pyelftools dependency
[Sorry for a respin so soon, but this fixes the overzealous documentation update and also ensures the script's behaviour is identical to the existing implementation in the case of a completely empty bl31 ELF file.] Building for Rockchip, make_fit_atf.py depends on pyelftools, a non-bundled python module that is not used elsewhere in building u-boot or the kernel. We only use pyelftools to pull out PT_LOAD segments. ELF is very simple, so doing this manually is easy and spares users the extra dependency. In fact, a straightforward implementation shrinks make_fit_aft.py rather than adding complexity. Andy Yan's patch https://gitlab.denx.de/u-boot/custodians/u-boot-rockchip/commit/619f002db864ef8caa30863bde62df5c651a7312 is a prerequisite for this. The new code does not erroneously count GNU_STACK sections and therefore without the above patch, the loadables in the conf section will always be one short, even where GNU_STACK is present. I have tested this script with python 2 and 3 against all bl31 elf files at https://github.com/rockchip-linux/rkbin/tree/master/bin/rk33 as well as an rk3399 bl31.elf built locally from the master branch of https://github.com/ARM-software/arm-trusted-firmware to which my toolchain added the extra GNU_STACK segment. In each case, identical *.bin files were produced compared to the pyelftools implementation, and a correct .its configuration (without off-by-one error) was emitted, with and without dtbs supplied to the script. Changes in v2: - no exception on a valid but completely empty bl31 ELF file - restrict documentation updates to the Rockchip docs (!) ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
Re: [U-Boot] [PATCH 2/2] rockchip: Remove obsolete references to pyelftools
Oops, sorry; I'm an idiot. The synopsys board does indeed still use pyelftools, and therefore while these are correct: > board/rockchip/evb_rk3399/README | 6 -- > doc/README.rockchip | 4 these removals are incorrect: > .travis.yml | 1 - > board/synopsys/hsdk/README | 7 --- Please disregard this second tidy-up patch for now. ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
[U-Boot] [PATCH 2/2] rockchip: Remove obsolete references to pyelftools
make_fit_atf.py no longer requires pyelftools, and nothing else in the tree requires it either, so remove references to installing it from the documentation and travis configuration. Signed-off-by: Chris Webb --- .travis.yml | 1 - board/rockchip/evb_rk3399/README | 6 -- board/synopsys/hsdk/README | 7 --- doc/README.rockchip | 4 4 files changed, 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6662ca126a..e4e7e653f6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,7 +50,6 @@ install: - . /tmp/venv/bin/activate - pip install pytest==2.8.7 - pip install python-subunit - - pip install pyelftools - grub-mkimage -o ~/grub_x86.efi -O i386-efi normal echo lsefimmap lsefi lsefisystab efinet tftp minicmd - grub-mkimage -o ~/grub_x64.efi -O x86_64-efi normal echo lsefimmap lsefi lsefisystab efinet tftp minicmd - mkdir ~/grub2-arm diff --git a/board/rockchip/evb_rk3399/README b/board/rockchip/evb_rk3399/README index 6469821987..ea3258cf37 100644 --- a/board/rockchip/evb_rk3399/README +++ b/board/rockchip/evb_rk3399/README @@ -35,12 +35,6 @@ Get the Source and prebuild binary > git clone https://github.com/rockchip-linux/rkbin.git > git clone https://github.com/rockchip-linux/rkdeveloptool.git -Get some prerequisites -== - -You need the Python elftools.elf.elffile library for make_fit_atf.py to work: - - > sudo apt-get install python-pyelftools Compile ATF === diff --git a/board/synopsys/hsdk/README b/board/synopsys/hsdk/README index 9155f17c6e..6e7f9a6c3e 100644 --- a/board/synopsys/hsdk/README +++ b/board/synopsys/hsdk/README @@ -82,13 +82,6 @@ Useful notes on bulding and using of U-Boot on ARC HS Development Kit (AKA HSDK) be put on the first FAT partition of micro SD-card to be inserted in the HSDK board. - Note that Python3 script is used for generation of a header, thus - to get that done it's required to have Python3 with "pyelftools" installed. - - "pyelftools" could be installed with help of "pip" even w/o root rights: - ->8-- - python3 -m pip install --user pyelftools - ->8-- EXECUTING U-BOOT diff --git a/doc/README.rockchip b/doc/README.rockchip index 02e2497b15..8ccbb87264 100644 --- a/doc/README.rockchip +++ b/doc/README.rockchip @@ -123,10 +123,6 @@ For example: Option 2: Package the image with SPL: - - We need the Python elftools.elf.elffile library for make_fit_atf.py to work - - => sudo apt-get install python-pyelftools - - Export cross compiler path for aarch64 - Compile ATF ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
[U-Boot] [PATCH 1/2] rockchip: make_fit_atf.py: Eliminate pyelftools dependency
make_fit_aft.py depends on the non-standard library pyelftools to pull out PT_LOAD segments from ELF files. However, this is as easy to do manually, without imposing the extra dependency on users. Structures in the ELF file are unpacked into variables named to exactly match the ELF spec to ensure the destructuring code is reasonably self-documenting. Signed-off-by: Chris Webb --- arch/arm/mach-rockchip/make_fit_atf.py | 74 +++--- 1 file changed, 31 insertions(+), 43 deletions(-) diff --git a/arch/arm/mach-rockchip/make_fit_atf.py b/arch/arm/mach-rockchip/make_fit_atf.py index db0ae96ca8..4b0acb8105 100755 --- a/arch/arm/mach-rockchip/make_fit_atf.py +++ b/arch/arm/mach-rockchip/make_fit_atf.py @@ -13,16 +13,7 @@ import os import sys import getopt import logging - -# pip install pyelftools -from elftools.elf.elffile import ELFFile - -ELF_SEG_P_TYPE = 'p_type' -ELF_SEG_P_PADDR = 'p_paddr' -ELF_SEG_P_VADDR = 'p_vaddr' -ELF_SEG_P_OFFSET = 'p_offset' -ELF_SEG_P_FILESZ = 'p_filesz' -ELF_SEG_P_MEMSZ = 'p_memsz' +import struct DT_HEADER = """ /* @@ -118,33 +109,19 @@ def append_conf_node(file, dtbs, segments): file.write('\n') def generate_atf_fit_dts_uboot(fit_file, uboot_file_name): -num_load_seg = 0 -p_paddr = 0x -with open(uboot_file_name, 'rb') as uboot_file: -uboot = ELFFile(uboot_file) -for i in range(uboot.num_segments()): -seg = uboot.get_segment(i) -if seg.__getitem__(ELF_SEG_P_TYPE) == 'PT_LOAD': -p_paddr = seg.__getitem__(ELF_SEG_P_PADDR) -num_load_seg = num_load_seg + 1 - -assert (p_paddr != 0x and num_load_seg == 1) - +segments = unpack_elf(uboot_file_name) +if len(segments) != 1: +raise ValueError("Invalid u-boot ELF image '%s'" % uboot_file_name) +entry, p_paddr, data = segments[0] fit_file.write(DT_UBOOT % p_paddr) def generate_atf_fit_dts_bl31(fit_file, bl31_file_name, dtbs_file_name): -with open(bl31_file_name, 'rb') as bl31_file: -bl31 = ELFFile(bl31_file) -elf_entry = bl31.header['e_entry'] -segments = bl31.num_segments() -for i in range(segments): -seg = bl31.get_segment(i) -if seg.__getitem__(ELF_SEG_P_TYPE) == 'PT_LOAD': -paddr = seg.__getitem__(ELF_SEG_P_PADDR) -append_bl31_node(fit_file, i + 1, paddr, elf_entry) +segments = unpack_elf(bl31_file_name) +for i, (entry, paddr, data) in enumerate(segments): +append_bl31_node(fit_file, i + 1, paddr, entry) append_fdt_node(fit_file, dtbs_file_name) fit_file.write(DT_IMAGES_NODE_END) -append_conf_node(fit_file, dtbs_file_name, segments) +append_conf_node(fit_file, dtbs_file_name, len(segments)) def generate_atf_fit_dts(fit_file_name, bl31_file_name, uboot_file_name, dtbs_file_name): # Generate FIT script for ATF image. @@ -162,17 +139,28 @@ def generate_atf_fit_dts(fit_file_name, bl31_file_name, uboot_file_name, dtbs_fi fit_file.close() def generate_atf_binary(bl31_file_name): -with open(bl31_file_name, 'rb') as bl31_file: -bl31 = ELFFile(bl31_file) - -num = bl31.num_segments() -for i in range(num): -seg = bl31.get_segment(i) -if seg.__getitem__(ELF_SEG_P_TYPE) == 'PT_LOAD': -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()) +for entry, paddr, data in unpack_elf(bl31_file_name): +file_name = 'bl31_0x%08x.bin' % paddr +with open(file_name, "wb") as atf: +atf.write(data) + +def unpack_elf(filename): +with open(filename, 'rb') as file: +elf = file.read() +if elf[0:7] != b'\x7fELF\x02\x01\x01' or elf[18:20] != b'\xb7\x00': +raise ValueError("Invalid arm64 ELF file '%s'" % filename) + +e_entry, e_phoff = struct.unpack_from('<2Q', elf, 0x18) +e_phentsize, e_phnum = struct.unpack_from('<2H', elf, 0x36) +segments = [] + +for offset in range(e_phoff, e_phoff + e_phnum*e_phentsize, e_phentsize): +p_type, p_flags, p_offset = struct.unpack_from('https://lists.denx.de/listinfo/u-boot
[U-Boot] [PATCH 0/2] rockchip: make_fit_atf.py Eliminate pyelftools dependency
Building for rockchip, make_fit_atf.py depends on pyelftools, a non-bundled python module that is not used elsewhere in building u-boot or the kernel. We only use pyelftools to pull out PT_LOAD segments. ELF is very simple, so doing this manually is easy and spares users the extra dependency. In fact, a straightforward implementation shrinks make_fit_aft.py rather than adding complexity. Andy Yan's patch https://gitlab.denx.de/u-boot/custodians/u-boot-rockchip/commit/619f002db864ef8caa30863bde62df5c651a7312 is a prerequisite for this. (The new code does not erroneously count GNU_STACK sections and therefore without the above patch, the loadables in the conf section will always be one short, even where GNU_STACK is present.) I have tested this script with python 2 and 3 against all bl31 elf files at https://github.com/rockchip-linux/rkbin/tree/master/bin/rk33 as well as an rk3399 bl31.elf built locally from the master branch of https://github.com/ARM-software/arm-trusted-firmware to which my toolchain added the extra GNU_STACK segment. In each case, identical *.bin files were produced compared to the pyelftools implementation, and a correct .its configuration (without off-by-one error) was emitted, with and without dtbs supplied to the script. ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
Re: [U-Boot] [PATCH v2 00/99] ram: rk3399: Add LPDDR4 support
Jagan Teki writes: > This is the v2 set for supporting LPDDR4 with associated features Sorry for a late follow-up, but I've just tested this series (applied to today's master branch) on Khadas Edge. With these patches, a device tree copied from Linux -next, and a defconfig essentially the same as the Rock Pi 4 one, this rk3399 board boots fine via U-Boot TPL instead of Rockchip idbloader. I have the trivial patch which adds the Khadas Edge device tree and defconfig, but presumably I can't usefully post it before your series is merged. Unless you'd like to pick up that patch too as an additional one in the LPDDR4 series? Best wishes, Chris. ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot