zephyr/arch/common/Makefile.gen_isr_tables
Andrew Boie 174f301147 build: simplfy how extra build steps are specified
For various reasons its often necessary to generate certain
complex data structures at build-time by separate tools outside
of the C compiler. Data is populated to these tools by way of
special binary sections not intended to be included in the final
binary. We currently do this to generate interrupt tables, forthcoming
work will also use this to generate MMU page tables.

The way we have been doing this is to generatea "kernel_prebuilt.elf",
extract the metadata sections with objcopy, run the tool, and then
re-link the kernel with the extra data *and* use objcopy to pull
out the unwanted sections.

This doesn't scale well if multiple post-build steps are needed.
Now this is much simpler; in any Makefile, a special
GENERATED_KERNEL_OBJECT_FILES variable may be appended to containing
the filenames to the generated object files, which will be generated
by Make in the usual fashion.

Instead of using objcopy to pull out, we now create a linker-pass2.cmd
which additionally defines LINKER_PASS2. The source linker script
can #ifdef around this to use the special /DISCARD/ section target
to not include metadata sections in the final binary.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-05-13 14:07:09 -04:00

41 lines
1.0 KiB
Makefile

GEN_ISR_TABLE := $(srctree)/arch/common/gen_isr_tables.py
OUTPUT_SRC := isr_tables.c
OUTPUT_OBJ := isr_tables.o
ifeq ($(ARCH),riscv32)
OUTPUT_FORMAT := elf32-littleriscv
else
OUTPUT_FORMAT := elf32-little$(ARCH)
endif
GEN_ISR_TABLE_EXTRA_ARGS :=
ifeq ($(KBUILD_VERBOSE),1)
GEN_ISR_TABLE_EXTRA_ARGS += --debug
endif
ifeq ($(CONFIG_GEN_SW_ISR_TABLE),y)
GEN_ISR_TABLE_EXTRA_ARGS += --sw-isr-table
endif
ifeq ($(CONFIG_GEN_IRQ_VECTOR_TABLE),y)
GEN_ISR_TABLE_EXTRA_ARGS += --vector-table
endif
# Rule to extract the .intList section from the $(PREBUILT_KERNEL) binary
# and create the source file $(OUTPUT_SRC). This is a C file which contains
# the interrupt tables.
quiet_cmd_gen_irq = IRQ $@
cmd_gen_irq = \
( \
$(OBJCOPY) -I $(OUTPUT_FORMAT) -O binary --only-section=.intList \
$< isrList.bin && \
$(GEN_ISR_TABLE) --output-source $@ \
--intlist isrList.bin $(GEN_ISR_TABLE_EXTRA_ARGS) \
)
$(OUTPUT_SRC): $(PREBUILT_KERNEL) $(GEN_ISR_TABLE)
$(call cmd,gen_irq)
GENERATED_KERNEL_OBJECT_FILES += $(OUTPUT_OBJ)