Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scripts: build: gen_isr_tables: Cleanup access to ".intList" #63282

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1239,20 +1239,13 @@ if(CONFIG_GEN_ISR_TABLES)
# isr_tables.c is generated from ${ZEPHYR_LINK_STAGE_EXECUTABLE} by
# gen_isr_tables.py
add_custom_command(
OUTPUT isr_tables.c isrList.bin
COMMAND $<TARGET_PROPERTY:bintools,elfconvert_command>
$<TARGET_PROPERTY:bintools,elfconvert_flag>
$<TARGET_PROPERTY:bintools,elfconvert_flag_intarget>${OUTPUT_FORMAT}
$<TARGET_PROPERTY:bintools,elfconvert_flag_outtarget>binary
$<TARGET_PROPERTY:bintools,elfconvert_flag_section_only>.intList
$<TARGET_PROPERTY:bintools,elfconvert_flag_infile>$<TARGET_FILE:${ZEPHYR_LINK_STAGE_EXECUTABLE}>
$<TARGET_PROPERTY:bintools,elfconvert_flag_outfile>isrList.bin
$<TARGET_PROPERTY:bintools,elfconvert_flag_final>
OUTPUT isr_tables.c
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proposed change fails with armclang:

$ ninja -C build 
ninja: Entering directory `build'
[1/134] Preparing syscall dependency handling

[2/134] Generating include/generated/version.h
-- Zephyr version: 3.4.99 (/projects/github/ncs/zephyr), build: zephyr-v3.4.0-4679-g2327fc53e19d
[131/134] Generating isr_tables.c
FAILED: zephyr/isr_tables.c /projects/github/ncs/zephyr/build/zephyr/isr_tables.c 
cd /projects/github/ncs/zephyr/build/zephyr && /usr/bin/python3 /projects/github/ncs/zephyr/scripts/build/gen_isr_tables.py --output-source isr_tables.c --kernel /projects/github/ncs/zephyr/build/zephyr/zephyr_pre0.elf --sw-isr-table --vector-table
gen_isr_tables.py: error: Empty ".intList" section!

ninja: build stopped: subcommand failed.

Copy link
Collaborator Author

@rakons rakons Oct 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generated linker_zephyr_pre0.cmd file for armclang contains:

IDT_LIST 0x20040000 NOCOMPRESS 0x800
{

  intList 0x20040000
  {
    *.o(.irq_info, +First)
    *.o(.intList)
  }
}

The section name is without a dot, it should be ".intList".
Fix proposals:

  • Update linker script to contain a do in intList section name
  • Update the python script to accept ".intList" or "intList" section names.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to go with the second answer. The section names preceded with dots should not be used as user sections. They are not strictly forbidden but they should be avoided and they are making trouble for clang. So updating clang scripts it not an option.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

COMMAND ${PYTHON_EXECUTABLE}
${ZEPHYR_BASE}/scripts/build/gen_isr_tables.py
--output-source isr_tables.c
--kernel $<TARGET_FILE:${ZEPHYR_LINK_STAGE_EXECUTABLE}>
--intlist isrList.bin
--intlist-section .intList
--intlist-section intList
$<$<BOOL:${CONFIG_BIG_ENDIAN}>:--big-endian>
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--debug>
${GEN_ISR_TABLE_EXTRA_ARG}
Expand Down
23 changes: 16 additions & 7 deletions scripts/build/gen_isr_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def endian_prefix():
else:
return "<"

def read_intlist(intlist_path, syms):
def read_intlist(elfobj, syms, snames):
"""read a binary file containing the contents of the kernel's .intList
section. This is an instance of a header created by
include/zephyr/linker/intlist.ld:
Expand All @@ -66,7 +66,7 @@ def read_intlist(intlist_path, syms):
const void *param;
};
"""

intList_sect = None
intlist = {}

prefix = endian_prefix()
Expand All @@ -77,8 +77,16 @@ def read_intlist(intlist_path, syms):
else:
intlist_entry_fmt = prefix + "iiII"

with open(intlist_path, "rb") as fp:
intdata = fp.read()
for sname in snames:
intList_sect = elfobj.get_section_by_name(sname)
if intList_sect is not None:
debug("Found intlist section: \"{}\"".format(sname))
break

if intList_sect is None:
error("Cannot find the intlist section!")

intdata = intList_sect.data()

header_sz = struct.calcsize(intlist_header_fmt)
header = struct.unpack_from(intlist_header_fmt, intdata, 0)
Expand Down Expand Up @@ -122,8 +130,9 @@ def parse_args():
help="Generate SW ISR table")
parser.add_argument("-V", "--vector-table", action="store_true",
help="Generate vector table")
parser.add_argument("-i", "--intlist", required=True,
help="Zephyr intlist binary for intList extraction")
parser.add_argument("-i", "--intlist-section", action="append", required=True,
help="The name of the section to search for the interrupt data. "
"This is accumulative argument. The first section found would be used.")

args = parser.parse_args()

Expand Down Expand Up @@ -286,6 +295,7 @@ def main():
with open(args.kernel, "rb") as fp:
kernel = ELFFile(fp)
syms = get_symbols(kernel)
intlist = read_intlist(kernel, syms, args.intlist_section)

if "CONFIG_MULTI_LEVEL_INTERRUPTS" in syms:
max_irq_per = syms["CONFIG_MAX_IRQ_PER_AGGREGATOR"]
Expand Down Expand Up @@ -313,7 +323,6 @@ def main():

debug('3rd level offsets: {}'.format(list_3rd_lvl_offsets))

intlist = read_intlist(args.intlist, syms)
nvec = intlist["num_vectors"]
offset = intlist["offset"]

Expand Down
Loading