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 @ (unset KCONFIG_AUTOHEADER; unset KCONFIG_AUTOCONFIG; \
65 $(MAKE) $(PARALLEL_MAKE) -C $(KERNEL_SRC_DIR) ARCH=$(KERNEL_BUILD_ARCH) \
66 KERNEL_CC="$(CC)" KERNEL_LD="$(LD)" > $(KERNEL_BUILD_LOG) 2>&1)
67 @ mkdir -p $(OUTPUT_DIR)/config/kernel
68 @ cp $(KERNEL_SRC_DIR)/.config $(OUTPUT_DIR)/config/kernel/
70 $(OUTPUT_DIR)/bzImage: $(KERNEL_BZIMAGE)
71 @ install -d $(OUTPUT_DIR)
72 @ install -m 0644 $< $@
74 $(OUTPUT_DIR)/vmlinux: $(KERNEL_BZIMAGE)
75 @ install -d $(OUTPUT_DIR)
76 @ install -m 0644 $(KERNEL_SRC_DIR)/vmlinux $@
78 $(KERNEL_STAMP_DIR)/.headers: $(KERNEL_SRC_DIR)/.config $(STAGING_DIR)/host/bin/unifdef | $(KERNEL_LOG_DIR)
79 @ echo "Installing kernel headers..."
80 @( export PATH=$(PATH):$(STAGING_DIR)/host/bin; \
81 $(MAKE) -C $(KERNEL_SRC_DIR) ARCH=$(KERNEL_BUILD_ARCH) \
82 INSTALL_HDR_PATH=$(STAGING_DIR)/ headers_install > $(KERNEL_INSTALL_LOG) 2>&1)
85 $(KERNEL_STAMP_DIR) $(KERNEL_LOG_DIR):
88 generic-kernel: $(OUTPUT_DIR)/bzImage $(OUTPUT_DIR)/vmlinux $(KERNEL_STAMP_DIR)/.headers
91 @ echo "Cleaning kernel..."
92 @ rm -f $(KERNEL_STAMP_DIR)/.headers
93 ifneq ($(wildcard $(KERNEL_SRC_DIR)/Makefile),)
94 $(MAKE) -C $(KERNEL_SRC_DIR) clean > /dev/null 2>&1;
97 generic-kernel-distclean:
98 @ rm -rf $(KERNEL_DIR)
100 kernel-extract: $(KERNEL_STAMP_DIR)/.patched
102 kernel-config: | $(KERNEL_SRC_DIR)/.config
103 ifeq ($(shell if [ -f $(PACKAGE_DIR)/kernel/conf/customconfig--$(PAYLOAD)--$(KERNEL_BUILD_ARCH)--$(COREBOOT_VENDOR)-$(COREBOOT_BOARD) ]; then echo 1; fi),1)
104 @ cp -f $(PACKAGE_DIR)/kernel/conf/customconfig--$(PAYLOAD)--$(KERNEL_BUILD_ARCH)--$(COREBOOT_VENDOR)-$(COREBOOT_BOARD) $(KERNEL_SRC_DIR)/.config
106 ifeq (kernel,$(filter kernel,$(PAYLOAD-y)))
107 @ echo "Configure kernel..."
108 @ $(MAKE) -C $(KERNEL_SRC_DIR) ARCH=$(KERNEL_BUILD_ARCH) menuconfig
110 ifeq ($(shell if [ -f $(PACKAGE_DIR)/kernel/conf/customconfig--$(PAYLOAD)--$(KERNEL_BUILD_ARCH)--$(COREBOOT_VENDOR)-$(COREBOOT_BOARD) ]; then echo 1; fi),1)
111 @ echo "Found an existing custom configuration file:"
112 @ echo " $(PACKAGE_DIR)/kernel/conf/customconfig--$(PAYLOAD)--$(KERNEL_BUILD_ARCH)--$(COREBOOT_VENDOR)-$(COREBOOT_BOARD)"
113 @ echo "I've copied it back to the source directory for modification."
114 @ 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."
117 @ cp -f $(KERNEL_SRC_DIR)/.config $(PACKAGE_DIR)/kernel/conf/customconfig--$(PAYLOAD)--$(KERNEL_BUILD_ARCH)--$(COREBOOT_VENDOR)-$(COREBOOT_BOARD)
118 @ echo "Your custom kernel config file has been saved as $(PACKAGE_DIR)/kernel/conf/customconfig--$(PAYLOAD)--$(KERNEL_BUILD_ARCH)--$(COREBOOT_VENDOR)-$(COREBOOT_BOARD)."
121 @ echo "Your payload does not require a kernel."