build: do not use link-zephyr
Use makefile targets to build and link final binary. This removes dependency on a shell script which is not portable and imporves dependency tracking when building. Change-Id: Ib75f162cdb1dde35ccaf980658bfe70daaf581b6 Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
parent
204b66d150
commit
06e78de681
120
Makefile
120
Makefile
|
@ -330,8 +330,9 @@ ARCH = $(subst $(DQUOTE),,$(CONFIG_ARCH))
|
|||
BOARD_NAME = $(subst $(DQUOTE),,$(CONFIG_BOARD))
|
||||
KERNEL_NAME = $(subst $(DQUOTE),,$(CONFIG_KERNEL_BIN_NAME))
|
||||
KERNEL_ELF_NAME = $(KERNEL_NAME).elf
|
||||
KERNEL_BIN_NAME = $(KERNEL_NAME).bin
|
||||
|
||||
export SOC_NAME BOARD_NAME ARCH KERNEL_NAME KERNEL_ELF_NAME
|
||||
export SOC_NAME BOARD_NAME ARCH KERNEL_NAME KERNEL_ELF_NAME KERNEL_BIN_NAME
|
||||
# Use ZEPHYRINCLUDE when you must reference the include/ directory.
|
||||
# Needed to be compatible with the O= option
|
||||
ZEPHYRINCLUDE = \
|
||||
|
@ -560,7 +561,6 @@ QEMU = $(QEMU_BIN_PATH)/$(QEMU_$(ARCH))
|
|||
# Defaults to zephyr, but the arch makefile usually adds further targets
|
||||
all: zephyr
|
||||
|
||||
|
||||
ifdef CONFIG_READABLE_ASM
|
||||
# Disable optimizations that make assembler listings hard to read.
|
||||
# reorder blocks reorders the control in the function
|
||||
|
@ -619,7 +619,7 @@ endif
|
|||
|
||||
KBUILD_CFLAGS += $(subst $(DQUOTE),,$(CONFIG_COMPILER_OPT))
|
||||
|
||||
export LDFLAG_LINKERCMD OUTPUT_FORMAT OUTPUT_ARCH
|
||||
export LDFLAG_LINKERCMD
|
||||
|
||||
include arch/$(ARCH)/Makefile
|
||||
|
||||
|
@ -706,6 +706,12 @@ endif
|
|||
|
||||
export LD_TOOLCHAIN KBUILD_LDS
|
||||
|
||||
# The all: target is the default when no target is given on the
|
||||
# command line.
|
||||
# This allow a user to issue only 'make' to build a kernel including modules
|
||||
# Defaults to zephyr, but the arch makefile usually adds further targets
|
||||
all: $(KERNEL_BIN_NAME)
|
||||
|
||||
# Default kernel image to build when no specific target is given.
|
||||
# KBUILD_IMAGE may be overruled on the command line or
|
||||
# set in the environment
|
||||
|
@ -726,7 +732,6 @@ libs-y1 := $(patsubst %/, %/lib.a, $(libs-y))
|
|||
libs-y2 := $(patsubst %/, %/built-in.o, $(libs-y))
|
||||
libs-y := $(libs-y1) $(libs-y2)
|
||||
|
||||
# Externally visible symbols (used by link-zephyr.sh)
|
||||
export KBUILD_ZEPHYR_MAIN := $(drivers-y) $(core-y) $(libs-y) $(app-y)
|
||||
export LDFLAGS_zephyr
|
||||
|
||||
|
@ -735,21 +740,94 @@ zephyr-deps := $(KBUILD_LDS) $(KBUILD_ZEPHYR_MAIN)
|
|||
ALL_LIBS += $(TOOLCHAIN_LIBS)
|
||||
export ALL_LIBS
|
||||
|
||||
# Final link of zephyr
|
||||
cmd_link-zephyr = $(CONFIG_SHELL) $< $(LD) $(LDFLAGS) $(LDFLAGS_zephyr) $(LIB_INCLUDE_DIR) $(ALL_LIBS)
|
||||
quiet_cmd_link-zephyr = LINK $@
|
||||
LINK_LIBS := $(foreach l,$(ALL_LIBS), -l$(l))
|
||||
|
||||
# Include targets which we want to
|
||||
# execute if the rest of the kernel build went well.
|
||||
zephyr: scripts/link-zephyr.sh $(zephyr-deps) $(KBUILD_ZEPHYR_APP) FORCE
|
||||
@touch zephyr
|
||||
ifdef CONFIG_HEADERS_CHECK
|
||||
$(Q)$(MAKE) -f $(srctree)/Makefile headers_check
|
||||
OUTPUT_FORMAT ?= elf32-i386
|
||||
OUTPUT_ARCH ?= i386
|
||||
|
||||
quiet_cmd_create-lnk = LINK $@
|
||||
cmd_create-lnk = \
|
||||
( \
|
||||
echo $(LDFLAGS_zephyr); \
|
||||
echo "-Map ./$(KERNEL_NAME).map"; \
|
||||
echo "-L $(objtree)/include/generated"; \
|
||||
echo "-u _OffsetAbsSyms -u _ConfigAbsSyms"; \
|
||||
echo "-e __start"; \
|
||||
echo "--start-group"; \
|
||||
echo "$(KBUILD_ZEPHYR_MAIN)"; \
|
||||
echo "$(objtree)/arch/$(ARCH)/core/offsets/offsets.o"; \
|
||||
echo "--end-group"; \
|
||||
echo "$(LIB_INCLUDE_DIR) $(LINK_LIBS)"; \
|
||||
) > $@
|
||||
|
||||
$(KERNEL_NAME).lnk:
|
||||
$(call cmd,create-lnk)
|
||||
|
||||
linker.cmd:
|
||||
$(Q)$(CC) -x assembler-with-cpp -nostdinc -undef -E -P \
|
||||
$(LDFLAG_LINKERCMD) $(LD_TOOLCHAIN) -I$(srctree)/include \
|
||||
-I$(objtree)/include/generated $(KBUILD_LDS) -o $@
|
||||
|
||||
final-linker.cmd:
|
||||
$(Q)$(CC) -x assembler-with-cpp -nostdinc -undef -E -P \
|
||||
$(LDFLAG_LINKERCMD) $(LD_TOOLCHAIN) -DFINAL_LINK -I$(srctree)/include \
|
||||
-I$(objtree)/include/generated $(KBUILD_LDS) -o $@
|
||||
|
||||
TMP_ELF = .tmp_$(KERNEL_NAME).prebuilt
|
||||
|
||||
$(TMP_ELF): $(KBUILD_ZEPHYR_APP) linker.cmd $(KERNEL_NAME).lnk
|
||||
$(Q)$(LD) -T linker.cmd @$(KERNEL_NAME).lnk -o $@
|
||||
|
||||
quiet_cmd_gen_idt = SIDT $@
|
||||
cmd_gen_idt = \
|
||||
( \
|
||||
$(OBJCOPY) -I $(OUTPUT_FORMAT) -O binary -j intList $< isrList.bin; \
|
||||
$(GENIDT) -i isrList.bin -n $(CONFIG_IDT_NUM_VECTORS) -o staticIdt.bin \
|
||||
-b int_vector_alloc.bin -m irq_int_vector_map.bin; \
|
||||
$(OBJCOPY) -I binary -B $(OUTPUT_ARCH) -O $(OUTPUT_FORMAT) \
|
||||
--rename-section .data=staticIdt staticIdt.bin staticIdt.o; \
|
||||
$(OBJCOPY) -I binary -B $(OUTPUT_ARCH) -O $(OUTPUT_FORMAT) \
|
||||
--rename-section .data=int_vector_alloc int_vector_alloc.bin int_vector_alloc.o;\
|
||||
$(OBJCOPY) -I binary -B $(OUTPUT_ARCH) -O $(OUTPUT_FORMAT) \
|
||||
--rename-section .data=irq_int_vector_map irq_int_vector_map.bin \
|
||||
irq_int_vector_map.o; \
|
||||
rm staticIdt.bin irq_int_vector_map.bin int_vector_alloc.bin isrList.bin \
|
||||
)
|
||||
|
||||
staticIdt.o: $(TMP_ELF)
|
||||
$(call cmd,gen_idt)
|
||||
|
||||
quiet_cmd_lnk_elf = LINK $@
|
||||
cmd_lnk_elf = \
|
||||
( \
|
||||
$(LD) -T final-linker.cmd @$(KERNEL_NAME).lnk staticIdt.o int_vector_alloc.o \
|
||||
irq_int_vector_map.o -o $@; \
|
||||
$(OBJCOPY) --set-section-flags intList=noload $@ elf.tmp; \
|
||||
$(OBJCOPY) -R intList elf.tmp $@; \
|
||||
rm elf.tmp \
|
||||
)
|
||||
|
||||
ifeq ($(ARCH),x86)
|
||||
$(KERNEL_ELF_NAME): staticIdt.o final-linker.cmd
|
||||
$(call cmd,lnk_elf)
|
||||
else
|
||||
$(KERNEL_ELF_NAME): $(TMP_ELF)
|
||||
@mv $(TMP_ELF) $(KERNEL_ELF_NAME)
|
||||
endif
|
||||
|
||||
ifneq ($(strip $(PROJECT)),)
|
||||
+$(call if_changed,link-zephyr)
|
||||
endif
|
||||
|
||||
quiet_cmd_gen_bin = BIN $@
|
||||
cmd_gen_bin = \
|
||||
( \
|
||||
$(OBJDUMP) -S $< > $(KERNEL_NAME).lst; \
|
||||
$(OBJCOPY) -S -O binary -R .note -R .comment -R COMMON -R .eh_frame $< $@; \
|
||||
$(STRIP) -s -o $(KERNEL_NAME).strip $<; \
|
||||
)
|
||||
|
||||
$(KERNEL_BIN_NAME): $(KERNEL_ELF_NAME)
|
||||
$(call cmd,gen_bin)
|
||||
|
||||
zephyr: $(zephyr-deps) $(KERNEL_BIN_NAME)
|
||||
|
||||
# The actual objects are generated when descending,
|
||||
# make sure no implicit rule kicks in
|
||||
|
@ -863,7 +941,10 @@ CLEAN_DIRS += $(MODVERDIR)
|
|||
|
||||
CLEAN_FILES += misc/generated/sysgen/kernel_main.c \
|
||||
misc/generated/sysgen/sysgen.h \
|
||||
misc/generated/sysgen/prj.mdef
|
||||
misc/generated/sysgen/prj.mdef \
|
||||
.old_version .tmp_System.map .tmp_version \
|
||||
.tmp_* System.map *.lnk *.map *.elf *.lst \
|
||||
*.bin *.strip staticIdt.o linker.cmd final-linker.cmd
|
||||
|
||||
# Directories & files removed with 'make mrproper'
|
||||
MRPROPER_DIRS += include/config usr/include include/generated \
|
||||
|
@ -884,10 +965,7 @@ PHONY += $(clean-dirs) clean archclean zephyrclean
|
|||
$(clean-dirs):
|
||||
$(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
|
||||
|
||||
zephyrclean:
|
||||
$(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-zephyr.sh clean
|
||||
|
||||
clean: archclean zephyrclean
|
||||
clean: archclean
|
||||
|
||||
# mrproper - Delete all generated files, including .config
|
||||
#
|
||||
|
|
|
@ -1,203 +0,0 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# link the kernel
|
||||
#
|
||||
# The kernel is linked from the objects selected by $(KBUILD_ZEPHYR_MAIN).
|
||||
# Most are built-in.o files from top-level directories
|
||||
# in the kernel tree, others are specified in arch/$(ARCH)/Makefile.
|
||||
#
|
||||
# microkernel/nanokernel
|
||||
# ^
|
||||
# +--< $(KBUILD_ZEPHYR_MAIN)
|
||||
# +--< drivers/built-in.o + more
|
||||
|
||||
# Error out on error
|
||||
set -e
|
||||
|
||||
# Nice output in kbuild format
|
||||
# Will be supressed by "make -s"
|
||||
info()
|
||||
{
|
||||
if [ "${quiet}" != "silent_" ]; then
|
||||
printf " %-7s %s\n" ${1} ${2}
|
||||
fi
|
||||
}
|
||||
|
||||
# Creates linker parameters.
|
||||
# {1} output file
|
||||
# {2} symbol map file
|
||||
linker_params()
|
||||
{
|
||||
LIBS=""
|
||||
for tcl in ${ALL_LIBS}; do LIBS="${LIBS} -l${tcl}"; done
|
||||
echo "${LDFLAGS_zephyr}" > ${1}
|
||||
echo "-Map ./${2}" >> ${1}
|
||||
echo "-L ${objtree}/include/generated" >> ${1}
|
||||
echo "-u _OffsetAbsSyms -u _ConfigAbsSyms" >> ${1}
|
||||
echo "-e __start" >> ${1}
|
||||
if [ -n "${CONFIG_LINK_WHOLE_ARCHIVE}" -a -n "${KBUILD_ZEPHYR_APP}" ]; then
|
||||
echo "--whole-archive ${KBUILD_ZEPHYR_APP} --no-whole-archive" >> ${1}
|
||||
fi
|
||||
echo "--start-group ${KBUILD_ZEPHYR_MAIN} ${KBUILD_ZEPHYR_APP}" >> ${1}
|
||||
echo "${objtree}/arch/${ARCH}/core/offsets/offsets.o" >> ${1}
|
||||
echo "--end-group" >> ${1}
|
||||
echo "${LIB_INCLUDE_DIR} ${LIBS}" >> ${1}
|
||||
}
|
||||
|
||||
#Creates linker command file
|
||||
# {1} output file
|
||||
# {2} optional additional link parameters
|
||||
linker_command()
|
||||
{
|
||||
${CC} -x assembler-with-cpp -nostdinc -undef -E -P \
|
||||
${LDFLAG_LINKERCMD} \
|
||||
${LD_TOOLCHAIN} ${2} \
|
||||
-I${srctree}/include -I${objtree}/include/generated \
|
||||
${KBUILD_LDS} \
|
||||
-o ${1}
|
||||
}
|
||||
|
||||
# Link of ${KERNEL_NAME}.o used for section mismatch analysis
|
||||
# ${1} output file
|
||||
# ${2} linker parameters file
|
||||
# ${3} linker command file
|
||||
initial_link()
|
||||
{
|
||||
${LD} -T ${3} @${2} -o ${1}
|
||||
}
|
||||
|
||||
#Generates IDT and merge them into final binary
|
||||
# ${1} input file (${KERNEL_NAME}.elf)
|
||||
# ${2} output file (staticIdt.o)
|
||||
# ${3} output file (int_vector_alloc)
|
||||
# ${4} output file (irq_int_vector_map)
|
||||
gen_idt()
|
||||
{
|
||||
test -z $OUTPUT_FORMAT && OUTPUT_FORMAT=elf32-i386
|
||||
test -z $OUTPUT_ARCH && OUTPUT_ARCH=i386
|
||||
${OBJCOPY} -I $OUTPUT_FORMAT -O binary -j intList ${1} isrList.bin
|
||||
${GENIDT} -i isrList.bin -n ${CONFIG_IDT_NUM_VECTORS:-256} \
|
||||
-o staticIdt.bin -b ${3}.bin -m ${4}.bin
|
||||
${OBJCOPY} -I binary -B $OUTPUT_ARCH -O $OUTPUT_FORMAT \
|
||||
--rename-section .data=staticIdt staticIdt.bin ${2}
|
||||
${OBJCOPY} -I binary -B $OUTPUT_ARCH -O $OUTPUT_FORMAT \
|
||||
--rename-section .data=${3} ${3}.bin ${3}.o
|
||||
${OBJCOPY} -I binary -B $OUTPUT_ARCH -O $OUTPUT_FORMAT \
|
||||
--rename-section .data=${4} ${4}.bin ${4}.o
|
||||
rm -f staticIdt.bin
|
||||
rm -f ${3}.bin
|
||||
rm -f ${4}.bin
|
||||
rm -f isrList.bin
|
||||
}
|
||||
|
||||
# Linking the kernel
|
||||
# ${1} - linker params file (${KERNEL_NAME}.lnk)
|
||||
# ${2} - linker command file (final-linker.cmd)
|
||||
# ${3} - input file (staticIdt.o)
|
||||
# ${4} - output file
|
||||
# ${5} - additional input file if applicable
|
||||
# ${6} - additional input file if applicable
|
||||
zephyr_link()
|
||||
{
|
||||
${LD} -T ${2} @${1} ${3} ${5} ${6} -o ${4}
|
||||
${OBJCOPY} --set-section-flags intList=noload ${4} elf.tmp
|
||||
${OBJCOPY} -R intList elf.tmp ${4}
|
||||
rm elf.tmp
|
||||
}
|
||||
|
||||
zephyr_bin_strip()
|
||||
{
|
||||
${OBJDUMP} -S ${1} >${2}
|
||||
${OBJCOPY} -S -O binary -R .note -R .comment -R COMMON -R .eh_frame ${1} ${3}
|
||||
${STRIP} -s -o ${4} ${1}
|
||||
}
|
||||
|
||||
|
||||
# Create map file with all symbols from ${1}
|
||||
# See mksymap for additional details
|
||||
mksysmap()
|
||||
{
|
||||
${CONFIG_SHELL} "${srctree}/scripts/mksysmap" ${1} ${2}
|
||||
}
|
||||
|
||||
sortextable()
|
||||
{
|
||||
${objtree}/scripts/sortextable ${1}
|
||||
}
|
||||
|
||||
# Delete output files in case of error
|
||||
trap cleanup SIGHUP SIGINT SIGQUIT SIGTERM ERR
|
||||
cleanup()
|
||||
{
|
||||
rm -f .old_version
|
||||
rm -f .tmp_System.map
|
||||
rm -f .tmp_version
|
||||
rm -f .tmp_*
|
||||
rm -f System.map
|
||||
rm -f *.lnk
|
||||
rm -f *.map
|
||||
rm -f *.elf
|
||||
rm -f *.lst
|
||||
rm -f *.bin
|
||||
rm -f *.strip
|
||||
rm -f staticIdt.o
|
||||
rm -f linker.cmd
|
||||
rm -f final-linker.cmd
|
||||
}
|
||||
|
||||
#
|
||||
#
|
||||
# Use "make V=1" to debug this script
|
||||
case "${KBUILD_VERBOSE}" in
|
||||
*1*)
|
||||
set -x
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ "$1" = "clean" ]; then
|
||||
cleanup
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# We need access to CONFIG_ symbols
|
||||
case "${KCONFIG_CONFIG}" in
|
||||
*/*)
|
||||
. "${KCONFIG_CONFIG}"
|
||||
;;
|
||||
*)
|
||||
# Force using a file from the current directory
|
||||
. "./${KCONFIG_CONFIG}"
|
||||
esac
|
||||
|
||||
#link ${KERNEL_NAME}.o
|
||||
info LD ${KERNEL_NAME}.elf
|
||||
linker_params ${KERNEL_NAME}.lnk ${KERNEL_NAME}.map
|
||||
linker_command linker.cmd
|
||||
initial_link ${KERNEL_NAME}.elf ${KERNEL_NAME}.lnk linker.cmd
|
||||
|
||||
# Update version
|
||||
info GEN .version
|
||||
if [ ! -r .version ]; then
|
||||
rm -f .version;
|
||||
echo 1 >.version;
|
||||
else
|
||||
mv .version .old_version;
|
||||
expr 0$(cat .old_version) + 1 >.version;
|
||||
fi;
|
||||
|
||||
if [ "${ARCH}" = "x86" ]; then
|
||||
info SIDT ${KERNEL_ELF_NAME}
|
||||
gen_idt ${KERNEL_ELF_NAME} staticIdt.o int_vector_alloc irq_int_vector_map
|
||||
linker_command final-linker.cmd -DFINAL_LINK
|
||||
zephyr_link ${KERNEL_NAME}.lnk final-linker.cmd staticIdt.o \
|
||||
${KERNEL_NAME}.elf int_vector_alloc.o irq_int_vector_map.o
|
||||
fi
|
||||
|
||||
info BIN ${KERNEL_NAME}.bin
|
||||
zephyr_bin_strip ${KERNEL_NAME}.elf ${KERNEL_NAME}.lst ${KERNEL_NAME}.bin ${KERNEL_NAME}.strip
|
||||
|
||||
info SYSMAP System.map
|
||||
mksysmap ${KERNEL_NAME}.elf System.map
|
||||
|
||||
# We made a new kernel - delete old version file
|
||||
rm -f .old_version
|
Loading…
Reference in a new issue