forked from cartesi/image-kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.mk
121 lines (101 loc) · 5.02 KB
/
build.mk
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
TOOLCHAIN_PREFIX := riscv64-cartesi-linux-gnu
OPENSBI_DIR := work/opensbi
OPENSBI_BUILD_DIR := $(OPENSBI_DIR)/build
LINUX_DIR := work/linux
LINUX_TEST_DIR := $(LINUX_DIR)/tools/testing/selftests
JOBS := -j$(shell nproc)
KERNEL_VERSION ?= $(shell make -sC $(LINUX_DIR) kernelversion)
KERNEL_TIMESTAMP ?= $(shell date -Ru)
IMAGE_KERNEL_VERSION?= 0.0.0
HEADERS := artifacts/linux-headers-$(KERNEL_VERSION)-v$(IMAGE_KERNEL_VERSION).tar.xz
IMAGE := artifacts/linux-$(KERNEL_VERSION)-v$(IMAGE_KERNEL_VERSION)-no-opensbi.bin
LINUX := artifacts/linux-$(KERNEL_VERSION)-v$(IMAGE_KERNEL_VERSION).bin
LINUX_ELF := artifacts/linux-$(KERNEL_VERSION)-v$(IMAGE_KERNEL_VERSION).elf
SELFTEST := artifacts/linux-selftest-$(KERNEL_VERSION)-v$(IMAGE_KERNEL_VERSION).ext2
CROSS_DEB_FILENAME := artifacts/linux-libc-dev-riscv64-cross-$(KERNEL_VERSION)-v$(IMAGE_KERNEL_VERSION).deb
NATIVE_DEB_FILENAME := artifacts/linux-libc-dev-$(KERNEL_VERSION)-v$(IMAGE_KERNEL_VERSION).deb
ARTIFACTS := $(HEADERS) $(IMAGE) $(LINUX) $(SELFTEST)
all: $(ARTIFACTS)
env:
@echo KBUILD_BUILD_TIMESTAMP=\""$(KERNEL_TIMESTAMP)"\"
@echo KBUILD_BUILD_USER=dapp
@echo KBUILD_BUILD_HOST=cartesi
@echo HEADERS="$(HEADERS)"
@echo IMAGE="$(IMAGE)"
@echo LINUX="$(LINUX)"
@echo LINUX_ELF="$(LINUX_ELF)"
@echo SELFTEST="$(SELFTEST)"
@echo CROSS_DEB_FILENAME="$(CROSS_DEB_FILENAME)"
@echo NATIVE_DEB_FILENAME="$(NATIVE_DEB_FILENAME)"
# build linux
# ------------------------------------------------------------------------------
LINUX_OPTS=$(JOBS) ARCH=riscv CROSS_COMPILE=$(TOOLCHAIN_PREFIX)- KBUILD_BUILD_TIMESTAMP="$(KERNEL_TIMESTAMP)" KBUILD_BUILD_USER=dapp KBUILD_BUILD_HOST=cartesi
$(LINUX_DIR)/vmlinux $(IMAGE) $(HEADERS) &: $(LINUX_DIR)/.config
mkdir -p artifacts
$(MAKE) -rC $(LINUX_DIR) $(LINUX_OPTS) olddefconfig
$(MAKE) -rC $(LINUX_DIR) $(LINUX_OPTS) vmlinux Image
$(MAKE) -rC $(LINUX_DIR) $(LINUX_OPTS) headers_install \
INSTALL_HDR_PATH=$(abspath work/linux-headers)
tar --sort=name --mtime="$(KERNEL_TIMESTAMP)" --owner=1000 --group=1000 --numeric-owner -cJf $(HEADERS) -C $(abspath work/linux-headers) .
cp work/linux/arch/riscv/boot/Image $(IMAGE)
cp $(LINUX_DIR)/vmlinux $(LINUX_ELF)
$(LINUX_DIR)/.config:
$(MAKE) -rC $(LINUX_DIR) $(LINUX_OPTS) cartesi_defconfig
cross-deb: # TARGET == riscv64
mkdir -p $(DESTDIR)/DEBIAN
cat tools/template/cross-control.template | sed 's|ARG_KERNEL_VERSION|$(KERNEL_VERSION)|g' > $(DESTDIR)/DEBIAN/control
$(MAKE) -rC $(LINUX_DIR) $(LINUX_OPTS) headers_install \
INSTALL_HDR_PATH=$(abspath $(DESTDIR))/usr/riscv64-linux-gnu
find $(DESTDIR) -exec touch -d "$(KERNEL_TIMESTAMP)" {} \;
SOURCE_DATE_EPOCH="1" dpkg-deb -Zxz --root-owner-group --build $(DESTDIR) $(CROSS_DEB_FILENAME)
native-deb: # HOST == riscv64
mkdir -p $(DESTDIR)/DEBIAN
cat tools/template/native-control.template | sed 's|ARG_KERNEL_VERSION|$(KERNEL_VERSION)|g' > $(DESTDIR)/DEBIAN/control
$(MAKE) -rC $(LINUX_DIR) $(LINUX_OPTS) headers_install \
INSTALL_HDR_PATH=$(abspath $(DESTDIR))/usr
find $(DESTDIR) -exec touch -d "$(KERNEL_TIMESTAMP)" {} \;
SOURCE_DATE_EPOCH="1" dpkg-deb -Zxz --root-owner-group --build $(DESTDIR) $(NATIVE_DEB_FILENAME)
# build linux w/ opensbi
# ------------------------------------------------------------------------------
OPENSBI_OPTS=$(JOBS) FW_PAYLOAD_PATH=$(abspath $(IMAGE)) FW_PAYLOAD=y FW_OPTIONS=0x01 PLATFORM=cartesi CROSS_COMPILE=$(TOOLCHAIN_PREFIX)-
$(LINUX): $(IMAGE)
@mkdir -p artifacts
$(MAKE) -rC $(OPENSBI_DIR) $(OPENSBI_OPTS)
@cp $(OPENSBI_BUILD_DIR)/platform/cartesi/firmware/fw_payload.bin $@
# build linux tests
# ------------------------------------------------------------------------------
TAR := $(shell mktemp)
$(SELFTEST):
mkdir -p artifacts
$(MAKE) $(JOBS) -rC $(LINUX_TEST_DIR) $(LINUX_OPTS) \
TARGETS=drivers/cartesi install
tar --sort=name --mtime="$(KERNEL_TIMESTAMP)" --owner=1000 --group=1000 --numeric-owner -cf $(TAR) --directory=$(LINUX_TEST_DIR)/kselftest_install .
xgenext2fs -f -i 4096 -b 1024 -a $(TAR) $@
rm $(TAR)
clean:
$(MAKE) -rC $(LINUX_DIR) $(LINUX_OPTS) clean
$(MAKE) $(JOBS) -rC $(OPENSBI_DIR) clean
@rm -rf $(OPENSBI_BUILD_DIR)
run-selftest:
cartesi-machine.lua --rollup \
--append-rom-bootargs=debug \
--remote-address=localhost:5001 \
--checkin-address=localhost:5002 \
--ram-image=`realpath $(LINUX)` \
--flash-drive=label:selftest,filename:`realpath $(SELFTEST)` \
-- $(CMD)
# clone (for non CI environment)
# ------------------------------------------------------------------------------
clone: LINUX_BRANCH ?= linux-6.5.9-ctsi-y
clone: OPENSBI_BRANCH ?= opensbi-1.3.1-ctsi-y
clone:
git clone --depth 1 --branch $(LINUX_BRANCH) \
[email protected]:cartesi/linux.git $(LINUX_DIR) || \
cd $(LINUX_DIR) && git pull
git clone --depth 1 --branch $(OPENSBI_BRANCH) \
[email protected]:cartesi/opensbi.git $(OPENSBI_DIR) || \
cd $(OPENSBI_DIR) && git pull
run: IMG=cartesi/toolchain:devel
run:
$(MAKE) run IMG=$(IMG)
.PHONY: $(OPENSBI_BUILD_DIR)/Makefile $(LINUX_DIR)/vmlinux $(ARTIFACTS)