1 # Common kernel file included by the targets
3 KERNEL_BASE_DIR ?= linux-$(KERNEL_VERSION)
5 KERNEL_DIR=$(BUILD_DIR)/kernel
6 KERNEL_SRC_DIR=$(KERNEL_DIR)/$(KERNEL_BASE_DIR)
7 KERNEL_STAMP_DIR=$(KERNEL_DIR)/stamps
8 KERNEL_LOG_DIR=$(KERNEL_DIR)/logs
10 ifeq ($(CONFIG_TARGET_64BIT),y)
11 KERNEL_BZIMAGE=$(KERNEL_SRC_DIR)/arch/x86_64/boot/bzImage
12 KERNEL_BUILD_ARCH=x86_64
14 KERNEL_BZIMAGE=$(KERNEL_SRC_DIR)/arch/i386/boot/bzImage
15 KERNEL_BUILD_ARCH=i386
18 ifeq ($(findstring defconfig,$(KERNEL_CONFIG)),defconfig)
19 ifeq ($(shell if [ -f $(PACKAGE_DIR)/kernel/conf/customconfig--$(PAYLOAD)--$(KERNEL_BUILD_ARCH)--$(COREBOOT_VENDOR)-$(COREBOOT_BOARD) ]; then echo 1; fi),1)
20 KERNEL_CONFIG = $(PACKAGE_DIR)/kernel/conf/customconfig--$(PAYLOAD)--$(KERNEL_BUILD_ARCH)--$(COREBOOT_VENDOR)-$(COREBOOT_BOARD)
24 ifeq ($(CONFIG_VERBOSE),y)
25 KERNEL_FETCH_LOG=/dev/stdout
26 KERNEL_BUILD_LOG=/dev/stdout
27 KERNEL_INSTALL_LOG=/dev/stdout
29 KERNEL_FETCH_LOG=$(KERNEL_LOG_DIR)/fetch.log
30 KERNEL_BUILD_LOG=$(KERNEL_LOG_DIR)/build.log
31 KERNEL_INSTALL_LOG=$(KERNEL_LOG_DIR)/install.log
34 $(KERNEL_STAMP_DIR)/.unpacked-$(KERNEL_VERSION): $(SOURCE_DIR)/$(KERNEL_SOURCE) | $(KERNEL_STAMP_DIR)
35 @ mkdir -p $(KERNEL_DIR)
36 @ echo "Unpacking kernel ($(KERNEL_VERSION))..."
37 @ tar -C $(KERNEL_DIR) -jxf $(SOURCE_DIR)/$(KERNEL_SOURCE)
40 $(KERNEL_STAMP_DIR)/.unpacked-tiny: $(SOURCE_DIR)/$(TINY_SOURCE)
41 @ mkdir -p $(KERNEL_DIR)
42 @ mkdir -p $(KERNEL_DIR)/tiny
43 @ echo "Unpacking tiny patches..."
44 @ tar -C $(KERNEL_DIR)/tiny -xzf $(SOURCE_DIR)/$(TINY_SOURCE)
47 ifneq ($(TINY_SOURCE),)
48 $(KERNEL_STAMP_DIR)/.patched: $(KERNEL_STAMP_DIR)/.unpacked-$(KERNEL_VERSION) $(KERNEL_STAMP_DIR)/.unpacked-tiny
50 $(KERNEL_STAMP_DIR)/.patched: $(KERNEL_STAMP_DIR)/.unpacked-$(KERNEL_VERSION)
52 @ echo "Patching kernel..."
53 @ $(BIN_DIR)/doquilt.sh $(KERNEL_SRC_DIR) $(KERNEL_PATCHES)
56 $(KERNEL_SRC_DIR)/.config: $(KERNEL_STAMP_DIR)/.patched
57 @ cat $(KERNEL_CONFIG) | sed -e s:^CONFIG_LOCALVERSION=.*:CONFIG_LOCALVERSION=\"$(ROM_VERSION)\": > $(KERNEL_SRC_DIR)/.config
59 $(KERNEL_BZIMAGE): $(KERNEL_SRC_DIR)/.config | $(KERNEL_LOG_DIR)
60 @ echo "Building kernel..."
61 ifneq ($(findstring defconfig,$(KERNEL_CONFIG)),defconfig)
62 @ echo "Using custom kernel config $(KERNEL_CONFIG)"
64 @ $(MAKE) $(PARALLEL_MAKE) -C $(KERNEL_SRC_DIR) ARCH=$(KERNEL_BUILD_ARCH) \
65 KERNEL_CC="$(CC)" KERNEL_LD="$(LD)" > $(KERNEL_BUILD_LOG) 2>&1
66 @ mkdir -p $(OUTPUT_DIR)/config/kernel
67 @ cp $(KERNEL_SRC_DIR)/.config $(OUTPUT_DIR)/config/kernel/
69 $(OUTPUT_DIR)/bzImage: $(KERNEL_BZIMAGE)
70 @ install -d $(OUTPUT_DIR)
71 @ install -m 0644 $< $@
73 $(OUTPUT_DIR)/vmlinux: $(KERNEL_BZIMAGE)
74 @ install -d $(OUTPUT_DIR)
75 @ install -m 0644 $(KERNEL_SRC_DIR)/vmlinux $@
77 $(KERNEL_STAMP_DIR)/.headers: $(KERNEL_SRC_DIR)/.config $(STAGING_DIR)/host/bin/unifdef | $(KERNEL_LOG_DIR)
78 @ echo "Installing kernel headers..."
79 @( export PATH=$(PATH):$(STAGING_DIR)/host/bin; \
80 $(MAKE) -C $(KERNEL_SRC_DIR) ARCH=$(KERNEL_BUILD_ARCH) \
81 INSTALL_HDR_PATH=$(STAGING_DIR)/ headers_install > $(KERNEL_INSTALL_LOG) 2>&1)
84 $(KERNEL_STAMP_DIR) $(KERNEL_LOG_DIR):
87 generic-kernel: $(OUTPUT_DIR)/bzImage $(OUTPUT_DIR)/vmlinux $(KERNEL_STAMP_DIR)/.headers
90 @ echo "Cleaning kernel..."
91 @ rm -f $(KERNEL_STAMP_DIR)/.headers
92 ifneq ($(wildcard $(KERNEL_SRC_DIR)/Makefile),)
93 $(MAKE) -C $(KERNEL_SRC_DIR) clean > /dev/null 2>&1;
96 generic-kernel-distclean:
97 @ rm -rf $(KERNEL_DIR)
99 kernel-extract: $(KERNEL_STAMP_DIR)/.patched
101 kernel-config: | $(KERNEL_SRC_DIR)/.config
102 ifeq ($(shell if [ -f $(PACKAGE_DIR)/kernel/conf/customconfig--$(PAYLOAD)--$(KERNEL_BUILD_ARCH)--$(COREBOOT_VENDOR)-$(COREBOOT_BOARD) ]; then echo 1; fi),1)
103 @ cp -f $(PACKAGE_DIR)/kernel/conf/customconfig--$(PAYLOAD)--$(KERNEL_BUILD_ARCH)--$(COREBOOT_VENDOR)-$(COREBOOT_BOARD) $(KERNEL_SRC_DIR)/.config
105 ifeq (kernel,$(filter kernel,$(PAYLOAD-y)))
106 @ echo "Configure kernel..."
107 @ $(MAKE) -C $(KERNEL_SRC_DIR) ARCH=$(KERNEL_BUILD_ARCH) menuconfig
109 ifeq ($(shell if [ -f $(PACKAGE_DIR)/kernel/conf/customconfig--$(PAYLOAD)--$(KERNEL_BUILD_ARCH)--$(COREBOOT_VENDOR)-$(COREBOOT_BOARD) ]; then echo 1; fi),1)
110 @ echo "Found an existing custom configuration file:"
111 @ echo " $(PACKAGE_DIR)/kernel/conf/customconfig--$(PAYLOAD)--$(KERNEL_BUILD_ARCH)--$(COREBOOT_VENDOR)-$(COREBOOT_BOARD)"
112 @ echo "I've copied it back to the source directory for modification."
113 @ echo "Remove the above file and re-run this command if you want to create a new custom configuration from scratch for this payload/board."
116 @ cp -f $(KERNEL_SRC_DIR)/.config $(PACKAGE_DIR)/kernel/conf/customconfig--$(PAYLOAD)--$(KERNEL_BUILD_ARCH)--$(COREBOOT_VENDOR)-$(COREBOOT_BOARD)
117 @ echo "Your custom kernel config file has been saved as $(PACKAGE_DIR)/kernel/conf/customconfig--$(PAYLOAD)--$(KERNEL_BUILD_ARCH)--$(COREBOOT_VENDOR)-$(COREBOOT_BOARD)."
120 @ echo "Your payload does not require a kernel."