2020-09-22 02:48:37 +00:00
# SPDX-License-Identifier: GPL-2.0-only
2009-08-16 05:35:34 +00:00
#
2020-09-22 02:48:37 +00:00
# Copyright (C) 2006-2020 OpenWrt.org
2007-03-24 13:42:54 +00:00
2009-08-08 14:22:04 +00:00
i f d e f C O N F I G _ S T R I P _ K E R N E L _ E X P O R T S
2021-02-17 12:49:14 +00:00
KERNEL_MAKEOPTS_IMAGE += \
2009-08-08 14:22:04 +00:00
EXTRA_LDSFLAGS = " -I $( KERNEL_BUILD_DIR) -include symtab.h "
e n d i f
2007-10-23 06:23:29 +00:00
INITRAMFS_EXTRA_FILES ?= $( GENERIC_PLATFORM_DIR) /image/initramfs-base-files.txt
2007-10-23 06:23:23 +00:00
i f n e q ( , $( KERNEL_CC ) )
KERNEL_MAKEOPTS += CC = " $( KERNEL_CC) "
e n d i f
2011-07-02 06:49:56 +00:00
export HOST_EXTRACFLAGS = -I$( STAGING_DIR_HOST) /include
2007-06-03 08:28:05 +00:00
# defined in quilt.mk
Kernel/Patch : =$( Kernel /Patch /Default )
2014-06-02 12:45:19 +00:00
2018-12-03 08:16:23 +00:00
i f n e q ( , $( findstring .xz ,$ ( LINUX_SOURCE ) ) )
LINUX_CAT:= xzcat
e l s e
2020-11-26 15:12:12 +00:00
LINUX_CAT:= gzip -dc
2018-12-03 08:16:23 +00:00
e n d i f
2007-11-20 13:21:01 +00:00
i f e q ( $( strip $ ( CONFIG_EXTERNAL_KERNEL_TREE ) ) , "" )
2008-10-10 10:07:45 +00:00
ifeq ( $( strip $( CONFIG_KERNEL_GIT_CLONE_URI) ) ,"" )
define Kernel/Prepare/Default
2018-12-03 08:16:23 +00:00
$( LINUX_CAT) $( DL_DIR) /$( LINUX_SOURCE) | $( TAR) -C $( KERNEL_BUILD_DIR) $( TAR_OPTIONS)
2007-06-03 08:28:05 +00:00
$( Kernel/Patch)
2016-08-05 12:08:47 +00:00
$( if $( QUILT) ,touch $( LINUX_DIR) /.quilt_used)
2008-10-10 10:07:45 +00:00
endef
else
2014-06-02 12:45:16 +00:00
define Kernel/Prepare/Default
2018-12-03 08:16:23 +00:00
$( LINUX_CAT) $( DL_DIR) /$( LINUX_SOURCE) | $( TAR) -C $( KERNEL_BUILD_DIR) $( TAR_OPTIONS)
2014-06-02 12:45:16 +00:00
endef
2008-10-10 10:07:45 +00:00
endif
e l s e
define Kernel/Prepare/Default
2007-11-20 13:21:01 +00:00
mkdir -p $( KERNEL_BUILD_DIR)
if [ -d $( LINUX_DIR) ] ; then \
rmdir $( LINUX_DIR) ; \
fi
ln -s $( CONFIG_EXTERNAL_KERNEL_TREE) $( LINUX_DIR)
2020-09-13 00:09:53 +00:00
$( _SINGLE) [ -d $( LINUX_DIR) /user_headers ] && rm -rf $( LINUX_DIR) /user_headers
2008-10-10 10:07:45 +00:00
endef
2007-11-20 13:21:01 +00:00
e n d i f
2007-03-24 13:42:54 +00:00
2010-06-26 20:42:38 +00:00
i f e q ( $( CONFIG_TARGET_ROOTFS_INITRAMFS ) , y )
2021-02-28 23:58:10 +00:00
ifeq ( $( CONFIG_TARGET_ROOTFS_INITRAMFS_SEPARATE) ,y)
2021-02-21 14:19:26 +00:00
define Kernel/SetInitramfs/PreConfigure
grep -v -e CONFIG_BLK_DEV_INITRD $( LINUX_DIR) /.config.old > $( LINUX_DIR) /.config
echo 'CONFIG_BLK_DEV_INITRD=y' >> $( LINUX_DIR) /.config
echo 'CONFIG_INITRAMFS_SOURCE=""' >> $( LINUX_DIR) /.config
endef
else
2012-04-05 14:33:04 +00:00
ifeq ( $( strip $( CONFIG_EXTERNAL_CPIO) ) ,"" )
2012-10-31 17:32:37 +00:00
define Kernel/SetInitramfs/PreConfigure
grep -v -e INITRAMFS -e CONFIG_RD_ -e CONFIG_BLK_DEV_INITRD $( LINUX_DIR) /.config.old > $( LINUX_DIR) /.config
echo 'CONFIG_BLK_DEV_INITRD=y' >> $( LINUX_DIR) /.config
echo 'CONFIG_INITRAMFS_SOURCE="$(strip $(TARGET_DIR) $(INITRAMFS_EXTRA_FILES))"' >> $( LINUX_DIR) /.config
2008-07-05 22:11:22 +00:00
endef
else
2012-10-31 17:32:37 +00:00
define Kernel/SetInitramfs/PreConfigure
grep -v INITRAMFS $( LINUX_DIR) /.config.old > $( LINUX_DIR) /.config
echo 'CONFIG_INITRAMFS_SOURCE="$(call qstrip,$(CONFIG_EXTERNAL_CPIO))"' >> $( LINUX_DIR) /.config
2012-04-05 14:33:04 +00:00
endef
endif
2021-02-21 14:19:26 +00:00
e n d i f
2012-10-31 17:32:37 +00:00
define Kernel/SetInitramfs
2016-01-06 18:37:42 +00:00
rm -f $( LINUX_DIR) /.config.prev
2012-10-31 17:32:37 +00:00
mv $( LINUX_DIR) /.config $( LINUX_DIR) /.config.old
$( call Kernel/SetInitramfs/PreConfigure)
2021-02-28 23:58:10 +00:00
ifneq ( $( CONFIG_TARGET_ROOTFS_INITRAMFS_SEPARATE) ,y)
2012-10-31 17:32:37 +00:00
echo 'CONFIG_INITRAMFS_ROOT_UID=$(shell id -u)' >> $( LINUX_DIR) /.config
echo 'CONFIG_INITRAMFS_ROOT_GID=$(shell id -g)' >> $( LINUX_DIR) /.config
2018-01-11 11:55:02 +00:00
echo " $( if $( CONFIG_TARGET_INITRAMFS_FORCE) ,CONFIG_INITRAMFS_FORCE= y,# CONFIG_INITRAMFS_FORCE is not set ) " >> $( LINUX_DIR) /.config
2021-02-21 14:19:26 +00:00
else
echo "# CONFIG_INITRAMFS_FORCE is not set" >> $( LINUX_DIR) /.config
endif
2012-10-31 17:32:37 +00:00
echo " $( if $( CONFIG_TARGET_INITRAMFS_COMPRESSION_NONE) ,CONFIG_INITRAMFS_COMPRESSION_NONE= y,# CONFIG_INITRAMFS_COMPRESSION_NONE is not set ) " >> $( LINUX_DIR) /.config
echo -e " $( if $( CONFIG_TARGET_INITRAMFS_COMPRESSION_GZIP) ,CONFIG_INITRAMFS_COMPRESSION_GZIP= y\n CONFIG_RD_GZIP= y,# CONFIG_INITRAMFS_COMPRESSION_GZIP is not set\n # CONFIG_RD_GZIP is not set)" >> $(LINUX_DIR)/.config
echo -e " $( if $( CONFIG_TARGET_INITRAMFS_COMPRESSION_BZIP2) ,CONFIG_INITRAMFS_COMPRESSION_BZIP2= y\n CONFIG_RD_BZIP2= y,# CONFIG_INITRAMFS_COMPRESSION_BZIP2 is not set\n # CONFIG_RD_BZIP2 is not set)" >> $(LINUX_DIR)/.config
echo -e " $( if $( CONFIG_TARGET_INITRAMFS_COMPRESSION_LZMA) ,CONFIG_INITRAMFS_COMPRESSION_LZMA= y\n CONFIG_RD_LZMA= y,# CONFIG_INITRAMFS_COMPRESSION_LZMA is not set\n # CONFIG_RD_LZMA is not set)" >> $(LINUX_DIR)/.config
echo -e " $( if $( CONFIG_TARGET_INITRAMFS_COMPRESSION_LZO) ,CONFIG_INITRAMFS_COMPRESSION_LZO= y\n CONFIG_RD_LZO= y,# CONFIG_INITRAMFS_COMPRESSION_LZO is not set\n # CONFIG_RD_LZO is not set)" >> $(LINUX_DIR)/.config
echo -e " $( if $( CONFIG_TARGET_INITRAMFS_COMPRESSION_XZ) ,CONFIG_INITRAMFS_COMPRESSION_XZ= y\n CONFIG_RD_XZ= y,# CONFIG_INITRAMFS_COMPRESSION_XZ is not set\n # CONFIG_RD_XZ is not set)" >> $(LINUX_DIR)/.config
2013-10-25 01:48:02 +00:00
echo -e " $( if $( CONFIG_TARGET_INITRAMFS_COMPRESSION_LZ4) ,CONFIG_INITRAMFS_COMPRESSION_LZ4= y\n CONFIG_RD_LZ4= y,# CONFIG_INITRAMFS_COMPRESSION_LZ4 is not set\n # CONFIG_RD_LZ4 is not set)" >> $(LINUX_DIR)/.config
2020-10-23 09:48:11 +00:00
echo -e " $( if $( CONFIG_TARGET_INITRAMFS_COMPRESSION_ZSTD) ,CONFIG_INITRAMFS_COMPRESSION_ZSTD= y\n CONFIG_RD_ZSTD= y,# CONFIG_INITRAMFS_COMPRESSION_ZSTD is not set\n # CONFIG_RD_ZSTD is not set)" >> $(LINUX_DIR)/.config
2012-10-31 17:32:37 +00:00
endef
2012-04-05 14:33:04 +00:00
e l s e
2013-06-27 19:58:20 +00:00
e n d i f
d e f i n e K e r n e l / S e t N o I n i t r a m f s
2016-01-06 18:37:42 +00:00
mv $( LINUX_DIR) /.config.set $( LINUX_DIR) /.config.old
grep -v INITRAMFS $( LINUX_DIR) /.config.old > $( LINUX_DIR) /.config.set
echo 'CONFIG_INITRAMFS_SOURCE=""' >> $( LINUX_DIR) /.config.set
2018-01-11 11:55:02 +00:00
echo '# CONFIG_INITRAMFS_FORCE is not set' >> $( LINUX_DIR) /.config.set
2013-06-27 19:58:20 +00:00
e n d e f
2008-07-05 22:11:22 +00:00
2007-03-24 13:42:54 +00:00
d e f i n e K e r n e l / C o n f i g u r e / D e f a u l t
2016-08-17 14:18:04 +00:00
rm -f $( LINUX_DIR) /localversion
2011-04-06 14:48:55 +00:00
$( LINUX_CONF_CMD) > $( LINUX_DIR) /.config.target
2010-04-13 14:07:22 +00:00
# copy CONFIG_KERNEL_* settings over to .config.target
awk '/^(#[[:space:]]+)?CONFIG_KERNEL/{sub("CONFIG_KERNEL_","CONFIG_");print}' $( TOPDIR) /.config >> $( LINUX_DIR) /.config.target
2009-01-20 21:09:04 +00:00
echo "# CONFIG_KALLSYMS_EXTRA_PASS is not set" >> $( LINUX_DIR) /.config.target
2009-02-14 14:10:44 +00:00
echo "# CONFIG_KALLSYMS_ALL is not set" >> $( LINUX_DIR) /.config.target
2016-02-08 18:44:21 +00:00
echo "CONFIG_KALLSYMS_UNCOMPRESSED=y" >> $( LINUX_DIR) /.config.target
2016-05-22 19:31:37 +00:00
$( SCRIPT_DIR) /package-metadata.pl kconfig $( TMP_DIR) /.packageinfo $( TOPDIR) /.config $( KERNEL_PATCHVER) > $( LINUX_DIR) /.config.override
2016-01-06 18:37:42 +00:00
$( SCRIPT_DIR) /kconfig.pl 'm+' '+' $( LINUX_DIR) /.config.target /dev/null $( LINUX_DIR) /.config.override > $( LINUX_DIR) /.config.set
2013-06-27 19:58:20 +00:00
$( call Kernel/SetNoInitramfs)
2007-03-24 17:05:26 +00:00
rm -rf $( KERNEL_BUILD_DIR) /modules
2016-01-06 18:37:42 +00:00
cmp -s $( LINUX_DIR) /.config.set $( LINUX_DIR) /.config.prev || { \
cp $( LINUX_DIR) /.config.set $( LINUX_DIR) /.config; \
cp $( LINUX_DIR) /.config.set $( LINUX_DIR) /.config.prev; \
}
2017-03-16 08:53:30 +00:00
$( _SINGLE) [ -d $( LINUX_DIR) /user_headers ] || $( KERNEL_MAKE) INSTALL_HDR_PATH = $( LINUX_DIR) /user_headers headers_install
2016-12-25 15:40:05 +00:00
grep '=[ym]' $( LINUX_DIR) /.config.set | LC_ALL = C sort | mkhash md5 > $( LINUX_DIR) /.vermagic
2007-03-24 13:42:54 +00:00
e n d e f
2013-06-27 19:58:20 +00:00
d e f i n e K e r n e l / C o n f i g u r e / I n i t r a m f s
$( call Kernel/SetInitramfs)
e n d e f
2007-03-24 13:42:54 +00:00
d e f i n e K e r n e l / C o m p i l e M o d u l e s / D e f a u l t
2007-04-25 22:26:40 +00:00
rm -f $( LINUX_DIR) /vmlinux $( LINUX_DIR) /System.map
2020-10-22 08:29:34 +00:00
+$( KERNEL_MAKE) $( if $( KERNELNAME) ,$( KERNELNAME) ,all) modules
2007-03-24 13:42:54 +00:00
e n d e f
2009-04-27 15:37:58 +00:00
OBJCOPY_STRIP = -R .reginfo -R .notes -R .note -R .comment -R .mdebug -R .note.gnu.build-id
2009-02-02 16:39:28 +00:00
2014-01-07 12:23:35 +00:00
# AMD64 shares the location with x86
i f e q ( $( LINUX_KARCH ) , x 8 6 _ 6 4 )
IMAGES_DIR := ../../x86/boot
e n d i f
2013-06-27 19:58:20 +00:00
d e f i n e K e r n e l / C o p y I m a g e
2016-01-06 18:38:49 +00:00
cmp -s $( LINUX_DIR) /vmlinux $( KERNEL_BUILD_DIR) /vmlinux$( 1) .debug || { \
$( KERNEL_CROSS) objcopy -O binary $( OBJCOPY_STRIP) -S $( LINUX_DIR) /vmlinux $( LINUX_KERNEL) $( 1) ; \
$( KERNEL_CROSS) objcopy $( OBJCOPY_STRIP) -S $( LINUX_DIR) /vmlinux $( KERNEL_BUILD_DIR) /vmlinux$( 1) .elf; \
$( CP) $( LINUX_DIR) /vmlinux $( KERNEL_BUILD_DIR) /vmlinux$( 1) .debug; \
$( foreach k, \
2017-03-17 19:37:52 +00:00
$( if $( KERNEL_IMAGES) ,$( KERNEL_IMAGES) ,$( filter-out vmlinux dtbs,$( KERNELNAME) ) ) , \
2016-01-06 18:38:49 +00:00
$( CP) $( LINUX_DIR) /arch/$( LINUX_KARCH) /boot/$( IMAGES_DIR) /$( k) $( KERNEL_BUILD_DIR) /$( k) $( 1) ; \
) \
}
2013-06-27 19:58:20 +00:00
e n d e f
2007-03-24 13:42:54 +00:00
d e f i n e K e r n e l / C o m p i l e I m a g e / D e f a u l t
2013-07-23 13:11:41 +00:00
rm -f $( TARGET_DIR) /init
2021-02-17 12:49:14 +00:00
+$( KERNEL_MAKE) $( KERNEL_MAKEOPTS_IMAGE) $( if $( KERNELNAME) ,$( KERNELNAME) ,all)
2013-06-27 19:58:20 +00:00
$( call Kernel/CopyImage)
e n d e f
i f n e q ( $( CONFIG_TARGET_ROOTFS_INITRAMFS ) , )
d e f i n e K e r n e l / C o m p i l e I m a g e / I n i t r a m f s
$( call Kernel/Configure/Initramfs)
2017-03-27 09:03:01 +00:00
$( CP) $( GENERIC_PLATFORM_DIR) /other-files/init $( TARGET_DIR) /init
2019-09-30 05:31:52 +00:00
$( if $( SOURCE_DATE_EPOCH) ,touch -hcd " @ $( SOURCE_DATE_EPOCH) " $( TARGET_DIR) /init)
2013-07-02 09:59:17 +00:00
rm -rf $( KERNEL_BUILD_DIR) /linux-$( LINUX_VERSION) /usr/initramfs_data.cpio*
2021-02-28 23:58:10 +00:00
i f e q ( $( CONFIG_TARGET_ROOTFS_INITRAMFS_SEPARATE ) , y )
2021-02-21 14:19:26 +00:00
i f e q ( $( CONFIG_EXTERNAL_CPIO ) , y )
$( CP) $( CONFIG_EXTERNAL_CPIO) $( KERNEL_BUILD_DIR) /initrd.cpio
e l s e
2021-03-03 15:09:04 +00:00
( cd $( TARGET_DIR) ; find . | $( STAGING_DIR_HOST) /bin/cpio -o -H newc -R 0:0 > $( KERNEL_BUILD_DIR) /initrd.cpio )
2021-02-21 14:19:26 +00:00
e n d i f
$( if $( CONFIG_TARGET_INITRAMFS_COMPRESSION_BZIP2) ,bzip2 -9 -c < $( KERNEL_BUILD_DIR) /initrd.cpio > $( KERNEL_BUILD_DIR) /initrd.cpio.bzip2)
$( if $( CONFIG_TARGET_INITRAMFS_COMPRESSION_GZIP) ,gzip -f -S .gzip -9n $( KERNEL_BUILD_DIR) /initrd.cpio)
$( if $( CONFIG_TARGET_INITRAMFS_COMPRESSION_LZMA) ,$( STAGING_DIR_HOST) /bin/lzma e -lc1 -lp2 -pb2 $( KERNEL_BUILD_DIR) /initrd.cpio $( KERNEL_BUILD_DIR) /initrd.cpio.lzma)
# ? $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZO),)
$( if $( CONFIG_TARGET_INITRAMFS_COMPRESSION_XZ) ,$( STAGING_DIR_HOST) /bin/xz -9 -fz --check= crc32 $( KERNEL_BUILD_DIR) /initrd.cpio)
# ? $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZ4),)
$( if $( CONFIG_TARGET_INITRAMFS_COMPRESSION_ZSTD) ,$( STAGING_DIR_HOST) /bin/zstd -T0 -f -o $( KERNEL_BUILD_DIR) /initrd.cpio.zstd $( KERNEL_BUILD_DIR) /initrd.cpio)
e n d i f
2021-02-17 12:49:14 +00:00
+$( KERNEL_MAKE) $( KERNEL_MAKEOPTS_IMAGE) $( if $( KERNELNAME) ,$( KERNELNAME) ,all)
2013-06-27 19:58:20 +00:00
$( call Kernel/CopyImage,-initramfs)
2007-03-24 13:42:54 +00:00
e n d e f
2013-06-27 19:58:20 +00:00
e l s e
d e f i n e K e r n e l / C o m p i l e I m a g e / I n i t r a m f s
e n d e f
e n d i f
2007-03-24 13:42:54 +00:00
d e f i n e K e r n e l / C l e a n / D e f a u l t
rm -f $( KERNEL_BUILD_DIR) /linux-$( LINUX_VERSION) /.configured
rm -f $( LINUX_KERNEL)
2008-08-16 16:59:47 +00:00
$( _SINGLE) $( MAKE) -C $( KERNEL_BUILD_DIR) /linux-$( LINUX_VERSION) clean
2007-03-24 13:42:54 +00:00
e n d e f