USE_LLVM := 0 CROSS_GCC := aarch64-none-linux-gnu- ifeq ($(USE_LLVM),1) COMPILER := LLVM=1 else COMPILER := CROSS_COMPILE=$(CROSS_GCC) endif build_dir := $(CURDIR)/build-aarch64 output_dir := $(HOME) output_nfs := /mnt/storage/nfsroot/aarch64 rootfs := $(HOME)/rootfs-aarch64.cpio rootfsbase := $(shell basename $(rootfs)) config_file := $(build_dir)/.config makejobs := $(shell grep '^processor' /proc/cpuinfo | sort -u | wc -l) makethreads := $(shell dc -e "$(makejobs) 1 + p") tftproot := /var/lib/tftpboot make_options := -f Makefile \ -j$(makethreads) -l$(makejobs) \ ARCH=arm64 \ $(COMPILER) \ KBUILD_OUTPUT=$(build_dir) .PHONY: help help: @echo "**** Common Makefile ****" @echo "make config - configure for aarch64" @echo "make build - build the kernel with initramfs" .PHONY: have-rootfs have-rootfs: @if [ ! -f $(rootfs) ] ; then \ echo "ERROR: no rootfs at $(rootfs)" ; \ echo "This is needed to boot the system." ; \ echo "ABORTING." ; \ exit 1 ; \ else \ echo "Rootfs available at $(rootfs)" ; \ fi .PHONY: have-crosscompiler have-crosscompiler: @if [ $(USE_LLVM) -eq 1 ] ; then \ echo "LLVM OK" ; \ else \ echo -n "Check that $(CROSS_COMPILE)gcc is available..." ; \ which $(CROSS_COMPILE)gcc > /dev/null ; \ if [ ! $$? -eq 0 ] ; then \ echo "ERROR: cross-compiler $(CROSS_COMPILE)gcc not in PATH=$$PATH!" ; \ echo "ABORTING." ; \ exit 1 ; \ else \ echo "OK" ;\ fi \ fi # Config options needed to bring up rootfs on distros config-distro: config-base $(CURDIR)/scripts/config --file $(config_file) \ --enable PARTITION_ADVANCED \ --enable LDM_PARTITION \ --enable MSDOS_PARTITION \ --enable DEVTMPFS \ --enable CGROUPS \ --enable CGROUP_FREEZER \ --enable CGROUP_DEVICE \ --enable CPUSETS \ --enable PROC_PID_CPUSET \ --enable CGROUP_CPUACCT \ --enable RESOURCE_COUNTERS \ --enable CGROUP_MEM_RES_CTLR \ --enable CGROUP_MEM_RES_CTLR_DISABLED \ --enable CGROUP_MEM_RES_CTLR_SWAP \ --enable CGROUP_SCHED \ --enable FAIR_GROUP_SCHED \ --enable BLK_CGROUP \ --enable NAMESPACES \ --enable SCHED_AUTOGROUP \ --enable FHANDLE \ --enable SWAP \ --enable AUTOFS4_FS \ --enable BSD_PROCESS_ACCT \ --enable BSD_PROCESS_ACCT_V3 \ --enable TASKSTATS \ --enable TASK_DELAY_ACCT \ --enable TASK_XACCT \ --enable TASK_IO_ACCOUNTING \ --enable BUILD_BIN2C \ --enable IKCONFIG \ --enable IKCONFIG_PROC \ --enable PAGE_COUNTER \ --enable MEMCG \ --enable MEMCG_SWAP \ --enable MEMCG_SWAP_ENABLED \ --enable MEMCG_KMEM \ --enable CGROUP_PERF \ --enable CGROUP_WRITEBACK \ --enable USER_NS \ --enable BLK_DEV_BSG \ --enable BLK_DEV_BSGLIB \ --enable BLK_DEV_INTEGRITY \ --enable NET_INGRESS \ --enable IP_ADVANCED_ROUTER \ --set-str UEVENT_HELPER_PATH "" \ --enable WANT_DEV_COREDUMP \ --enable DEV_COREDUMP \ --enable CHR_DEV_SG \ --enable KEYS \ --enable ENCRYPTED_KEYS \ --enable SECURITY \ --enable SECURITYFS \ --enable SECURITY_NETWORK \ --enable SECURITY_NETWORK_XFRM \ --enable SECURITY_PATH \ --enable INTEGRITY \ --enable CRYPTO_USER_API \ --enable CRYPTO_USER_API_HASH \ --enable CRYPTO_USER_API_SKCIPHER \ --enable CRYPTO_USER_API_AEAD \ --enable ARM_CRYPTO \ --enable CRYPTO_SHA1_ARM \ --enable CRYPTO_SHA256_ARM \ --enable CRYPTO_SHA512_ARM \ --enable CRYPTO_AES_ARM \ --enable BINARY_PRINTF \ --enable MD \ --enable BLK_DEV_DM_BUILTIN \ --enable BLK_DEV_DM \ --enable DM_CRYPT \ --enable DM_UEVENT config-base: FORCE @mkdir -p $(build_dir) $(MAKE) $(make_options) defconfig config-mtd: config-base $(CURDIR)/scripts/config --file $(config_file) \ --enable MTD \ --enable MTD_CFI \ --enable MTD_PHYSMAP \ --enable MTD_PHYSMAP_OF \ --enable MTD_CFI_INTELEXT \ --enable MTD_AFS_PARTS \ --enable DEBUG_FS config-initramfs: have-rootfs config-base @cp $(rootfs) $(build_dir)/$(rootfsbase) # Configure in the initramfs $(CURDIR)/scripts/config --file $(config_file) \ --enable BLK_DEV_INITRD \ --set-str INITRAMFS_SOURCE $(rootfsbase) \ --enable RD_GZIP \ --enable INITRAMFS_COMPRESSION_GZIP config-earlydebug: config-base $(CURDIR)/scripts/config --file $(config_file) \ --enable DEBUG_KERNEL \ --enable DEBUG_LL \ --enable EARLY_PRINTK \ --set-str CMDLINE "earlyprintk" config-kasan: config-base $(CURDIR)/scripts/config --file $(config_file) \ --enable KASAN \ --enable KASAN_OUTLINE \ --enable STACKTRACE \ --enable SLUB_DEBUG_ON \ --enable TEST_KASAN config: config-base config-distro config-initramfs yes "" | make $(make_options) oldconfig $(CURDIR)/scripts/config --file $(config_file) \ --disable RANDOMIZE_BASE \ --enable INPUT_KEYBOARD \ --enable KEYBOARD_GPIO menuconfig: FORCE if [ ! -d $(build_dir) ] ; then \ echo "no build dir" ; \ exit 1 ; \ fi $(MAKE) $(make_options) menuconfig $(MAKE) $(make_options) savedefconfig saveconfig: FORCE $(MAKE) $(make_options) savedefconfig cp $(build_dir)/defconfig arch/arm64/configs/defconfig saveconfig-bfq: config-base $(CURDIR)/scripts/config --file $(config_file) \ --enable IOSCHED_BFQ $(MAKE) $(make_options) savedefconfig cp $(build_dir)/defconfig arch/arm64/configs/defconfig build-dtbs: FORCE $(MAKE) $(make_options) dtbs @echo "Copy Juno DTB to $(output_dir)/juno.dtb" @cp -f $(build_dir)/arch/arm64/boot/dts/arm/juno.dtb $(output_dir)/juno.dtb @cp -f $(build_dir)/arch/arm64/boot/dts/arm/foundation-v8.dtb $(output_dir)/foundation-v8.dtb # If we have a TFTP boot directory if [ -w $(tftproot) ] ; then \ cp -f $(build_dir)/arch/arm64/boot/dts/arm/juno.dtb $(tftproot) ; \ fi check-bindings: FORCE $(MAKE) $(make_options) dt_binding_check -k $(make_flags) $(MAKE) $(make_options) dtbs_check -k $(make_flags) build-zimage: have-crosscompiler FORCE $(MAKE) $(make_options) Image build: have-crosscompiler build-dtbs build-zimage FORCE @echo "Copy vmlinux to $(output_dir)/vmlinux" @cp -f $(build_dir)/vmlinux $(output_dir)/vmlinux @echo "Copy Image to $(output_dir)/Image" @cp -f $(build_dir)/arch/arm64/boot/Image $(output_dir)/Image @which fnord > /dev/null ; \ if [ ! $$? -eq 0 ] ; then \ echo "mkimage not in PATH=$$PATH" ; \ echo "This tool creates the uImage and comes from the uboot tools" ; \ echo "On Ubuntu/Debian sudo apt-get install uboot-mkimage" ; \ echo "SKIPPING uImage GENERATION" ; \ else \ mkimage \ -A arm64 \ -O linux \ -T kernel \ -C none \ -a 0x80080000 \ -e 0x80080000 \ -n "AARCH64 kernel" \ -d $(output_dir)/Image \ $(output_dir)/uImage ; \ fi # If we have a TFTP boot directory if [ -w $(tftproot) ] ; then \ cp $(output_dir)/vmlinux $(tftproot) ; \ cp $(output_dir)/Image $(tftproot) ; \ fi if [ -w $(output_nfs) ]; then \ echo "Copying to NFS root $(output_nfs)" ; \ cp -f $(output_dir)/vmlinux $(output_nfs) ; \ cp -f $(output_dir)/Image $(output_nfs) ; \ fi @echo "TFTP boot:" @echo "setenv bootargs console=ttyAMA0,115200n8 root=/dev/sda1 rw rootwait rootfstype=ext4 init=/sbin/init ; set serverip 192.168.1.124 ; set ipaddr 192.168.1.35 ; tftpboot 0x80000000 Image ; tftpboot 0x83000000 juno.dtb ; booti 0x80000000 - 0x83000000" clean: $(MAKE) -f Makefile clean rm -rf $(build_dir) FORCE: