From 5aa4326cbff6e2e8422bc84387b46b1d709ba628 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Tue, 16 Jul 2019 17:13:09 +0200 Subject: Extended Makefile to load kernel modules Already built kernel modules can be load in an out-of-tree build with the load_modules target into the kernel. The correct loading order of the modules is preserved by this Makefile target. Furthermore, the modules can be unloaded with the target unload_modules later on. --- Makefile | 25 ++++++++++++++++++++++++- implementation/loop | 2 +- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 9ac1860..b009bb6 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,7 @@ # Global configuration (file paths and config) #------------------------------------------------------------------------------ KERNEL_SRC_DIR := $(shell pwd)/implementation/loop +KERNEL_MOD_PATH := drivers/block/loop/ KERNEL_HDR_DIR := /lib/modules/$(shell uname -r)/build LOSETUP_SRC_DIR := $(shell pwd)/implementation/losetup KERNEL_MOD_CONFIG := $(shell pwd)/config/kernel-qcow2_x86-64_module.config @@ -19,7 +20,7 @@ LOCAL_MOD_CONFIG += CONFIG_BLK_DEV_LOOP_FILE_FMT_QCOW=m BUILD ?= vanilla KERNEL_DIR ?= $(KERNEL_SRC_DIR) CONFIG ?= KCONFIG_CONFIG=$(KERNEL_MOD_CONFIG) -TARGET_PATH_PREFX ?= drivers/block/loop/ +TARGET_PATH_PREFX ?= $(KERNEL_MOD_PATH) ifeq ($(BUILD),out-of-tree) PATCH = patch @@ -73,6 +74,28 @@ clean_losetup: @cd $(LOSETUP_SRC_DIR) && \ $(MAKE) --no-print-directory clean +ifeq ($(BUILD),out-of-tree) +loop.load: loop.ko +loop_file_fmt_raw.load: loop_file_fmt_raw.ko loop.load +loop_file_fmt_qcow.load: loop_file_fmt_qcow.ko loop.load + +loop.unload: loop_file_fmt_raw.unload loop_file_fmt_qcow.unload +loop_file_fmt_raw.unload: +loop_file_fmt_qcow.unload: + +load_modules: loop.load loop_file_fmt_raw.load loop_file_fmt_qcow.load + +unload_modules: loop_file_fmt_qcow.unload loop_file_fmt_raw.unload loop.unload + +%.load: + $(call print_heading,"Load kernel module $(basename $@)") + sudo insmod $(KERNEL_SRC_DIR)/$(KERNEL_MOD_PATH)$(basename $@).ko + +%.unload: + $(call print_heading,"Unload kernel module $(basename $@)") + sudo rmmod $(basename $@) +endif + #------------------------------------------------------------------------------ # Function definitions #------------------------------------------------------------------------------ diff --git a/implementation/loop b/implementation/loop index 6f5dc67..b9562e4 160000 --- a/implementation/loop +++ b/implementation/loop @@ -1 +1 @@ -Subproject commit 6f5dc67946313ced450de6546fc7f28e0afdf1a6 +Subproject commit b9562e46df0f2ddfbd01b99a44a3c4eaa3f32fe0 -- cgit v1.2.3-55-g7522