Skip to content
Snippets Groups Projects
Commit 04d249c0 authored by Armin Luntzer's avatar Armin Luntzer
Browse files

add option to embed modules image in kernel binary

parent ce1a4190
No related branches found
No related tags found
No related merge requests found
......@@ -730,7 +730,11 @@ ifdef CONFIG_MODULES
# By default, build modules as well
ifeq ($(CONFIG_EMBED_MODULES_IMAGE), y)
all: modules_embed_image
else
all: modules
endif
# Build modules
#
......@@ -751,6 +755,12 @@ modules.builtin: $(leanos-dirs:%=%/modules.builtin)
$(Q)$(MAKE) $(modbuiltin)=$*
PHONY += modules_embed_image
modules_embed_image: modules
@$(kecho) ' Embedding module image, stage 3.';
$(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-leanos.sh embed
# Target to prepare building external modules
PHONY += modules_prepare
modules_prepare: prepare scripts
......
......@@ -69,13 +69,12 @@ menuconfig MODULES
if MODULES
config MODULE_UNLOAD
bool "Module unloading"
config EMBED_MODULES_IMAGE
bool "Embed an image with all generated loadable modules"
help
Without this option you will not be able to unload any
modules (note that some modules may not be unloadable
anyway), which makes your kernel smaller, faster
and simpler. If unsure, say Y.
Enable this option in order to embed an image containing all
generated modules into the final kernel binary.
This is a convenience option, if unsure, say Y.
endif # MODULES
......
obj-y += main.o
obj-$(CONFIG_EMBED_MODULES_IMAGE) += modules-image.o
/**
* linker references to embedded modules.image
*/
extern unsigned char _binary_modules_image_start;
extern unsigned char _binary_modules_image_end;
extern unsigned char _binary_modules_image_size;
......@@ -358,7 +358,7 @@ endif # builtin-target
modorder-cmds = \
$(foreach m, $(modorder), \
$(if $(filter %/modules.order, $m), \
cat $m;, echo kernel/$m;))
cat $m;, echo $m;))
$(modorder-target): $(subdir-ym) FORCE
$(Q)(cat /dev/null; $(modorder-cmds)) > $@
......
......@@ -76,6 +76,7 @@ modpost_link()
# Link of leanos
# ${1} - optional extra .o files
# ${2} - output file
# ${3} - extra flags
leanos_link()
{
local lds="${objtree}/${KBUILD_LDS}"
......@@ -84,7 +85,7 @@ leanos_link()
# since we link against the BCC libc at this time, we'll just
# call $CC instead of LD
${CC} ${LDFLAGS} ${LDFLAGS_leanos} -o ${2} \
${CC} ${LDFLAGS} ${LDFLAGS_leanos} ${3} -o ${2} \
${KBUILD_LEANOS_INIT} ${KBUILD_LEANOS_MAIN} ${1}
# if [ -n "${CONFIG_THIN_ARCHIVES}" ]; then
......@@ -289,5 +290,25 @@ if [ -n "${CONFIG_KALLSYMS}" ]; then
fi
fi
# this is a 3rd pass option, we need modules.order beforehand
if [ "$1" = "embed" ]; then
if [ ! -s ${srctree}/modules.order ]; then
echo >&2
echo >&2 modules.order empty or nonexistant, cannot embed image.
echo >&2 Maybe you have no loadable modules configured?
echo >&2 Kernel image unchanged.
echo >&2
exit
fi
embedflags="-Wl,--format=binary -Wl,modules.image -Wl,--format=default"
rm -f modules.image
${AR} rcs ${srctree}/modules.image $(tr '\n' ' ' < ${srctree}/modules.order)
leanos_link "${kallsymso}" leanos "${embedflags}"
exit
fi
# We made a new kernel - delete old version file
rm -f .old_version
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment