-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
164 lines (139 loc) · 4.9 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# Foothold
# Copyright (c) 2018,2019 Jani Nurminen <[email protected]>
# MIT License, see LICENSE
# SPDX-License-Identifier: MIT
#
# A dual ARM A53 QEMU dev board for a kernel playground, built with Yocto.
#
# This is meant to be a Linux kernel exploration tool.
#
# Quickstart (check README for more):
#
# The kernel is in a Git repository, you can build your kernel manually on the
# side or within Yocto. The rootfs will be built as part of the final image.
#
# Simple usage:
# make prepare
# make image
# make runqemu
#
# To debug the kernel from start, tell QEMU to wait for gdb connection at
# QEMU_GDB_PORT (default: 37777):
# make runqemu-gdb
# gdb -ex 'b start_kernel' -ex 'tar rem localhost:37777'
#
# To do maintenance tasks in full Bitbake environment, use:
# make shell
#
# Use "exit" to get out of that shell.
ROOT_DIR := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
DISTRO = foothold
MACHINE = fharm64
IMAGE = foothold-image
# GDB port
QEMU_GDB_PORT ?= 37777
# The Linux kernel knobs
KERNEL_GIT_DIR ?= $(ROOT_DIR)/kernel
KERNEL_BRANCHOFF_VERSION ?= 5.4.1
KERNEL_BRANCH ?= dev/foothold
BUILD_DIR ?= $(ROOT_DIR)/build
POKY_DIR ?= $(ROOT_DIR)/poky
DL_DIR ?= $(ROOT_DIR)/downloads
TGZ_DIR ?= $(ROOT_DIR)/tgz
IMAGE ?= $(DISTRO)-image
LOCAL_CONF = $(BUILD_DIR)/conf/local.conf
SITE_CONF = $(BUILD_DIR)/conf/site.conf
BBLAYERS_CONF = $(BUILD_DIR)/conf/bblayers.conf
CONF_FILES = $(LOCAL_CONF) $(SITE_CONF) $(BBLAYERS_CONF)
BBLAYERS = $(POKY_DIR)/meta \
$(POKY_DIR)/meta-poky \
$(POKY_DIR)/meta-yocto-bsp \
$(ROOT_DIR)/meta-openembedded/meta-oe \
$(ROOT_DIR)/meta-foothold
define HELP
Usage: $(MAKE) [target] [variables ...]
Targets:
prepare One-time preparation to fetch the kernel sources
image Build the image (incl. kernel)
runqemu Run image under QEMU. Hit Ctrl-A X to exit
runqemu-gdb Run image under QEMU, wait for GDB to attach (port $(QEMU_GDB_PORT))
shell Bitbake shell. Use "exit" to exit
kernel Build the kernel only
clean Remove BUILD_DIR
Variables:
DL_DIR Alternative location for upstream downloads ($(DL_DIR))
You can provide these as arguments to "make" or in a file "site.conf", for example:
DL_DIR = "/mnt/data/downloads"
endef
export HELP
help:
@echo "$$HELP"
$(LOCAL_CONF):
@mkdir -p $(dir $@) $(DL_DIR)
@echo '' > $@
@echo 'MACHINE ?= "$(MACHINE)"' >> $@
@echo 'DISTRO ?= "$(DISTRO)"' >> $@
@echo 'DL_DIR ?= "$(DL_DIR)"' >> $@
@echo 'COMPATIBLE_MACHINE_$(MACHINE) = "$(MACHINE)"' >> $@
@echo '' >> $@
@echo '# All gits are local, http/https are to be in tarballs' >> $@
@echo 'PREMIRRORS_prepend = "\ ' >> $@
@echo 'git://.*/(.*) git://$(KERNEL_GIT_DIR)/\1 \' >> $@
@echo 'http://.*/(.*) file://$(TGZ_DIR)/\1 \' >> $@
@echo 'https://.*/(.*) file://$(TGZ_DIR)/\1 "' >> $@
@echo '' >> $@
@echo '# Use systemd for init' >> $@
@echo 'DISTRO_FEATURES_append = " systemd"' >> $@
@echo 'VIRTUAL-RUNTIME_init_manager = "systemd"' >> $@
@echo 'DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"' >> $@
@echo 'VIRTUAL-RUNTIME_initscripts = ""' >> $@
@echo '' >> $@
@echo 'LINUX_VERSION = "$(KERNEL_BRANCHOFF_VERSION)"' >> $@
@echo 'FH_KBRANCH = "$(KERNEL_BRANCH)"' >> $@
@echo 'MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS += "kernel-modules"' >> $@
@echo '' >> $@
@echo '# PR server' >> $@
@echo 'PRSERV_HOST = "localhost:0"' >> $@
@echo '' >> $@
@echo 'KERNEL_GIT_DIR = "$(KERNEL_GIT_DIR)"' >> $@
@echo '' >> $@
@echo 'OE_TERMINAL_CUSTOMCMD = "tmux"' >> $@
@echo 'OE_TERMINAL = "xterm"' >> $@
@echo '' >> $@
$(SITE_CONF): $(wildcard $(ROOT_DIR)/site.conf)
@for f in $^; do cp $$f $@; done
$(BBLAYERS_CONF):
@mkdir -p $(dir $@)
@echo 'POKY_BBLAYERS_CONF_VERSION = "2"' > $@
@echo 'BBPATH = "$${TOPDIR}"' >> $@
@echo 'BBFILES ?= ""' >> $@
@for L in $(BBLAYERS); do if [ -d "$$L" ]; then echo "BBLAYERS += \"$$L\"" >> $@; fi; done
prepare:
ifneq (,$(wildcard $(KERNEL_GIT_DIR)))
@echo "Already prepared, remove $(KERNEL_GIT_DIR) and re-run"
@exit 1
endif
@echo "One-time preparation: cloning mainline kernel to $(KERNEL_GIT_DIR)/linux.git"
@mkdir $(KERNEL_GIT_DIR)
@git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git $(KERNEL_GIT_DIR)/linux.git
@echo "Checking out $(KERNEL_BRANCHOFF_VERSION)"
@git -C $(KERNEL_GIT_DIR)/linux.git checkout -b $(KERNEL_BRANCH) "v$(KERNEL_BRANCHOFF_VERSION)"
@rm -f images
@ln -s build/tmp/deploy/images/$(MACHINE) images
@echo "One-time prepare done!"
define oe-init-build-env
OEROOT=$(POKY_DIR) . $(POKY_DIR)/oe-init-build-env $(BUILD_DIR)
endef
kernel: $(CONF_FILES)
$(call oe-init-build-env); bitbake virtual/kernel
image: $(CONF_FILES)
$(call oe-init-build-env); bitbake $(IMAGE)
runqemu: image
$(call oe-init-build-env); runqemu nographic $(IMAGE)
runqemu-gdb: image
$(call oe-init-build-env); runqemu nographic $(IMAGE) qemuparams="-gdb tcp::$(QEMU_GDB_PORT) -S"
shell:
$(call oe-init-build-env); exec $(SHELL)
clean:
-rm -rf $(BUILD_DIR)
.PHONY: prepare image runqemu runqemu-gdb kernel shell clean $(CONF_FILES)