History log of /optee_os/scripts/gen_ldelf_hex.py (Results 1 – 8 of 8)
Revision Date Author Comments
# 15e14f8f 09-Nov-2025 Aleksandr Iashchenko <aleksandr.iashchenko@linutronix.de>

scripts/gen_ldelf_hex.py: account for true memsz in last load segment mapping

The pad_size array is used to compute code/data/load mapping sizes for
ldelf by measuring the gaps after each PT_LOAD se

scripts/gen_ldelf_hex.py: account for true memsz in last load segment mapping

The pad_size array is used to compute code/data/load mapping sizes for
ldelf by measuring the gaps after each PT_LOAD segment. The last entry
was hardcoded to 0, effectively ignoring the final segment’s
(p_memsz - p_filesz) - i.e. the BSS portion that exists in memory but
not in the file.

As a result, the RW mapping for ldelf was undersized: the zero-filled
area of the last PT_LOAD was not reserved, which could lead to writes
past the mapped region.

Signed-off-by: Aleksandr Iashchenko <aleksandr.iashchenko@linutronix.de>
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>

show more ...


# 50d680c4 05-May-2020 Jerome Forissier <jerome@forissier.org>

scripts/gen_ldelf_hex.py: do not use f-strings

f-strings were introduced in Python 3.6 [1] and will therefore
cause an error with prior versions:

| File "scripts/gen_ldelf_hex.py", line 68
| prin

scripts/gen_ldelf_hex.py: do not use f-strings

f-strings were introduced in Python 3.6 [1] and will therefore
cause an error with prior versions:

| File "scripts/gen_ldelf_hex.py", line 68
| print(f'RO load segment found after RW one(s) (m={n})')
| ^
| SyntaxError: invalid syntax

For better compatibility use .format() instead.

Link: [1] https://docs.python.org/3/whatsnew/3.6.html#pep-498-formatted-string-literals
Fixes: c706c2449b50 ("scripts/gen_ldelf_hex.py: relax rules for PT_LOAD segments")
Signed-off-by: Jerome Forissier <jerome@forissier.org>
Acked-by: Etienne Carriere <etienne.carriere@linaro.org>

show more ...


# c706c244 21-Apr-2020 Jerome Forissier <jerome@forissier.org>

scripts/gen_ldelf_hex.py: relax rules for PT_LOAD segments

Latest Clang [1] generates the following ldelf.elf:

Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg A

scripts/gen_ldelf_hex.py: relax rules for PT_LOAD segments

Latest Clang [1] generates the following ldelf.elf:

Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x001000 0x00000000 0x00000000 0x04834 0x04834 R E 0x1000
LOAD 0x005838 0x00004838 0x00004838 0x01620 0x01620 R 0x1000
LOAD 0x007000 0x00006000 0x00006000 0x0006c 0x0006c RW 0x1000
LOAD 0x00706c 0x0000606c 0x0000606c 0x00068 0x00078 RW 0x1000
DYNAMIC 0x007000 0x00006000 0x00006000 0x00060 0x00060 RW 0x4
GNU_RELRO 0x007000 0x00006000 0x00006000 0x0006c 0x01000 R 0x1
GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0
EXIDX 0x006800 0x00005800 0x00005800 0x002b8 0x002b8 R 0x4

Nothing wrong with that from a strict ELF compliance point of view, but
it doesn't meet the requirements of our current gen_ldelf_hex.py script
which makes the build fail:

$ scripts/gen_ldelf_hex.py --input out/arm-plat-vexpress/ldelf/ldelf.elf \
--output out/arm-plat-vexpress/core/ldelf_hex.c
Expected load segment to be read/write

I think our script is a bit too strict, what really matters is that
OP-TEE creates two memory mappings for the PT_LOAD segments of ldelf,
one is RX and the other is RW. We can therefore concatenate segments as
long as we have one or more non-writable segments followed by one or
more writable ones.

This commit relaxes the requirements in gen_ldelf_hex.py and implements
the above conditions instead.

[1] clang version 11.0.0 (https://github.com/llvm/llvm-project.git
6b3168f8cdb46656330929877b0b4daab35d30de)

Signed-off-by: Jerome Forissier <jerome@forissier.org>
Tested-by: Jerome Forissier <jerome@forissier.org> (QEMU, GCC 8.3/Clang 10/Clang pre-11)
Tested-by: Jerome Forissier <jerome@forissier.org> (QEMUv8, GCC 8.3/Clang 10)
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>

show more ...


# d5204cce 18-Oct-2019 Jens Wiklander <jens.wiklander@linaro.org>

scripts/gen_ldelf_hex.py: remove unused imports

Removes a few import lines that are not needed.

Reviewed-by: Jerome Forissier <jerome@forissier.org>
Signed-off-by: Jens Wiklander <jens.wiklander@li

scripts/gen_ldelf_hex.py: remove unused imports

Removes a few import lines that are not needed.

Reviewed-by: Jerome Forissier <jerome@forissier.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>

show more ...


# 7ba36df9 01-Aug-2019 Volodymyr Babchuk <volodymyr_babchuk@epam.com>

gen_ldelf_hex.py: print how to obtain elftools module

There is recurring problem when OP-TEE build fails with cryptic
message from this python script. It occurs when user forgets to
install elftools

gen_ldelf_hex.py: print how to obtain elftools module

There is recurring problem when OP-TEE build fails with cryptic
message from this python script. It occurs when user forgets to
install elftools python module.

Print human-readable error message with instructions how to install
it.

This is mere convenience, with no functional changes to the script
itself.

Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>
Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>

show more ...


# d2fb6900 04-Jul-2019 Jerome Forissier <jerome.forissier@linaro.org>

ldelf: scripts/gen_ldelf_hex.py: allow multiple RW load segments

Allow multiple read/write load segments as long as they are contiguous.
This is to support Clang > 8.0.0 which generates this:

Prog

ldelf: scripts/gen_ldelf_hex.py: allow multiple RW load segments

Allow multiple read/write load segments as long as they are contiguous.
This is to support Clang > 8.0.0 which generates this:

Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x001000 0x00000000 0x00000000 0x0a50c 0x0a50c R E 0x1000
LOAD 0x00c000 0x0000b000 0x0000b000 0x0006c 0x0006c RW 0x1000
LOAD 0x00c06c 0x0000b06c 0x0000b06c 0x0006c 0x0007c RW 0x1000
DYNAMIC 0x00c000 0x0000b000 0x0000b000 0x00060 0x00060 RW 0x4
GNU_RELRO 0x00c000 0x0000b000 0x0000b000 0x0006c 0x01000 R 0x1
GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0
EXIDX 0x00b134 0x0000a134 0x0000a134 0x00258 0x00258 R 0x4

Section to Segment mapping:
Segment Sections...
00 .text .rodata .ARM.exidx .gnu.hash .ARM.extab .dynsym .dynstr .hash .rel.dyn
01 .dynamic .got
02 .data .bss
03 .dynamic
04 .dynamic .got .bss
05
06 .ARM.exidx

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>

show more ...


# 84c0da04 02-Jul-2019 Rouven Czerwinski <r.czerwinski@pengutronix.de>

scripts: port gen_ldelf_hex to python3

Simple port for gen_ldelf_hex to python3.

Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>


# b8c97753 23-May-2019 Jens Wiklander <jens.wiklander@linaro.org>

core: embed ldelf into tee core

Embeds the ldelf binary into TEE Core using the new script
scripts/gen_ldelf_hex.py.

Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Signed-off-by: Jens

core: embed ldelf into tee core

Embeds the ldelf binary into TEE Core using the new script
scripts/gen_ldelf_hex.py.

Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>

show more ...