forked from nasa/cFS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom-rules.mk
More file actions
153 lines (125 loc) · 7.06 KB
/
custom-rules.mk
File metadata and controls
153 lines (125 loc) · 7.06 KB
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
# This converts the staging directory from "make install" into a virtual
# filesystem that can be mounted in a VM or container
YOCTO_SANDBOX_REPO = ghcr.io/core-flight-system
YOCTO_SANDBOX_TAG = latest
PARTED_CMD ?= /usr/sbin/parted
IMAGE_TYPE ?= qcow2
IMAGE_LABEL ?= cFS
IMAGE_SIZE ?= 128M
DEPLOY_DIR ?= $(O)/deploy
QEMU_YOCTO_DEPLOY_DIR = $(O_qemu_yocto_linux)/deploy
QEMU_PC686_RTEMS_DEPLOY_DIR = $(O_pc686_rtems5)/deploy
CFS_IMAGE_BASENAME = cfs-$(CPUNAME)
QEMU_MACADDR = 52:54:00$(shell head -c 3 /dev/urandom | hexdump -v -e '/1 ":%02X"')
QEMU_HOSTFWD = udp::1234-:1234,hostfwd=tcp::2222-:22
QEMU_NET_OPTS += -device $(QEMU_NETDEV_TYPE),netdev=net0,mac=$(QEMU_MACADDR)
QEMU_NET_OPTS += -netdev user,id=net0,hostfwd=$(QEMU_HOSTFWD)
ifeq ($(IMAGE_TYPE),qcow2)
IMAGE_FORMAT ?= qcow2
else
IMAGE_FORMAT ?= raw
endif
QEMU_DEVICE_OPTS += -object rng-random,filename=/dev/urandom,id=rng0
QEMU_DEVICE_OPTS += -device virtio-rng-pci,rng=rng0
QEMU_DEVICE_OPTS += -display none
QEMU_DEVICE_OPTS += -serial stdio
RTEMS5_APPEND_OPTS += --console=/dev/com1
RTEMS5_APPEND_OPTS += --batch-mode
$(QEMU_YOCTO_DEPLOY_DIR)/fetch_yocto_rootfs.cpu1.stamp: $(QEMU_YOCTO_DEPLOY_DIR)/extract_yocto_rootfs.qemuriscv64.stamp
#SYSTEM_CONTAINER = yocto-image-qemuriscv64
$(QEMU_YOCTO_DEPLOY_DIR)/fetch_yocto_rootfs.cpu2.stamp: $(QEMU_YOCTO_DEPLOY_DIR)/extract_yocto_rootfs.qemumips.stamp
#SYSTEM_CONTAINER = yocto-image-qemumips
$(DEPLOY_DIR)/extract_yocto_rootfs.%.stamp:
/bin/bash -x ./create_yocto_rootfs.sh $(DEPLOY_DIR) $(YOCTO_SANDBOX_REPO)/yocto-image-$(*):$(YOCTO_SANDBOX_TAG)
touch "$(@)"
$(DEPLOY_DIR)/fetch_yocto_rootfs.cpu1.stamp:
cp -Lv -t $(DEPLOY_DIR)/cpu1 $(DEPLOY_DIR)/images/qemuriscv64/core-image-cfecfs-qemuriscv64.rootfs.ext4
cp -Lv -t $(DEPLOY_DIR)/cpu1 $(DEPLOY_DIR)/images/qemuriscv64/fw_jump.elf
cp -Lv -t $(DEPLOY_DIR)/cpu1 $(DEPLOY_DIR)/images/qemuriscv64/Image
touch "$(@)"
$(DEPLOY_DIR)/fetch_yocto_rootfs.cpu2.stamp:
cp -Lv -t $(DEPLOY_DIR)/cpu2 $(DEPLOY_DIR)/images/qemumips/core-image-cfecfs-qemumips.rootfs.ext4
cp -Lv -t $(DEPLOY_DIR)/cpu2 $(DEPLOY_DIR)/images/qemumips/vmlinux
touch "$(@)"
# generic rule for creating a CFS tarball
# this uses "fakeroot" so the files in the resulting tarball have root:root ownership
%.tar.xz: $(O)/stamp.install
mkdir -p "$(dir $(@))"
rm -f "$(@)"
tar Jc --owner=root --group=root -f "$(abspath $(@)).tmp" -C $(O)/exe/$(CPUNAME) .
mv -v "$(@).tmp" "$(@)"
# generic rule for creating an ext4 image from the build
# This is intended for linux so it includes everything including the cfs executable
%.ext4: $(O)/stamp.install
mkdir -p "$(dir $(@))"
rm -f "$(@)"
fakeroot /usr/sbin/mke2fs -t ext4 -L "$(IMAGE_LABEL)" -d "$(O)/exe/$(CPUNAME)" "$(@).tmp" $(IMAGE_SIZE)
mv -v "$(@).tmp" "$(@)"
# generic rule for creating a qcow overlay image from an ext4 image
%.qcow2: %.ext4
mkdir -p "$(dir $(@))"
rm -f "$(@)"
cd "$(dir $(<))" && qemu-img create -o backing_file="$(notdir $(<))",backing_fmt=raw -f qcow2 "$(notdir $(@)).tmp"
mv -v "$(@).tmp" "$(@)"
# generic rule for creating a fat filesystem image from the build
# Note that this does NOT include the cfs executable itself, just the eeprom dir
%.fat: $(O)/stamp.install
mkdir -p "$(dir $(@))"
truncate -s $(IMAGE_SIZE) $(@).tmp
/usr/sbin/mkfs.fat "$(@).tmp"
(cd $(O)/exe/$(CPUNAME) && mcopy -sv -i "$(abspath $(@).tmp)" eeprom ::)
mv -v "$(@).tmp" "$(@)"
# generic rule for creating a disk image from a fat filesystem image
# The disk image needs to be exactly 63 512-byte sectors larger than the fat FS
# This is the traditional size of the MS-DOS partition table
%.diskimg: FS_SIZE = $(shell stat --printf="%s" "$(<)")
%.diskimg: %.fat
mkdir -p "$(dir $(@))"
truncate -s $$(($(FS_SIZE) + 32256)) $(@).tmp
$(PARTED_CMD) -s $(@).tmp -- mklabel msdos
$(PARTED_CMD) -a none -s $(@).tmp -- mkpart primary fat32 63s -1s
dd if=$(<) of=$(@).tmp bs=512 seek=63
mv -v "$(@).tmp" "$(@)"
%/rtems-cfs.exe: $(O)/stamp.install
mkdir -p "$(dir $(@))"
cp -v "$(O)/exe/$(CPUNAME)/core-$(CPUNAME).exe" "$(@)"
$(QEMU_YOCTO_DEPLOY_DIR)/cpu1/container-start: CPUNAME = cpu1
$(QEMU_YOCTO_DEPLOY_DIR)/cpu1/container-start: QEMU_HYPERVISOR = qemu-system-riscv64 -M virt -m 512M -smp 4 -bios fw_jump.elf
$(QEMU_YOCTO_DEPLOY_DIR)/cpu1/container-start: QEMU_KERNEL = -kernel Image -append 'root=/dev/vda mem=512M earlycon=sbi swiotlb=0'
$(QEMU_YOCTO_DEPLOY_DIR)/cpu1/container-start: ROOTFS_IMAGE_BASENAME = core-image-cfecfs-qemuriscv64.rootfs
$(QEMU_YOCTO_DEPLOY_DIR)/cpu1/container-start: QEMU_NETDEV_TYPE = virtio-net-device
$(QEMU_YOCTO_DEPLOY_DIR)/cpu1/container-start: $(QEMU_YOCTO_DEPLOY_DIR)/cpu1/core-image-cfecfs-qemuriscv64.rootfs.$(IMAGE_TYPE)
$(QEMU_YOCTO_DEPLOY_DIR)/cpu1/container-start: $(QEMU_YOCTO_DEPLOY_DIR)/cpu1/cfs-cpu1.$(IMAGE_TYPE)
$(QEMU_YOCTO_DEPLOY_DIR)/cpu1/container-start: $(QEMU_YOCTO_DEPLOY_DIR)/fetch_yocto_rootfs.cpu1.stamp
$(QEMU_YOCTO_DEPLOY_DIR)/cpu2/container-start: CPUNAME = cpu2
$(QEMU_YOCTO_DEPLOY_DIR)/cpu2/container-start: QEMU_HYPERVISOR = qemu-system-mips -M malta -cpu 34Kf -m 256M
$(QEMU_YOCTO_DEPLOY_DIR)/cpu2/container-start: QEMU_KERNEL = -kernel vmlinux
$(QEMU_YOCTO_DEPLOY_DIR)/cpu2/container-start: ROOTFS_IMAGE_BASENAME = core-image-cfecfs-qemumips.rootfs
$(QEMU_YOCTO_DEPLOY_DIR)/cpu2/container-start: QEMU_NETDEV_TYPE = virtio-net-pci
$(QEMU_YOCTO_DEPLOY_DIR)/cpu2/container-start: $(QEMU_YOCTO_DEPLOY_DIR)/cpu2/core-image-cfecfs-qemumips.rootfs.$(IMAGE_TYPE)
$(QEMU_YOCTO_DEPLOY_DIR)/cpu2/container-start: $(QEMU_YOCTO_DEPLOY_DIR)/cpu2/cfs-cpu2.$(IMAGE_TYPE)
$(QEMU_YOCTO_DEPLOY_DIR)/cpu2/container-start: $(QEMU_YOCTO_DEPLOY_DIR)/fetch_yocto_rootfs.cpu2.stamp
$(QEMU_PC686_RTEMS_DEPLOY_DIR)/cpu1/container-start: CPUNAME = cpu1
$(QEMU_PC686_RTEMS_DEPLOY_DIR)/cpu1/container-start: QEMU_KERNEL = -kernel rtems-cfs.exe -append '$(RTEMS5_APPEND_OPTS)'
$(QEMU_PC686_RTEMS_DEPLOY_DIR)/cpu1/container-start: $(QEMU_PC686_RTEMS_DEPLOY_DIR)/cpu1/rtems-cfs.exe
$(QEMU_PC686_RTEMS_DEPLOY_DIR)/cpu1/container-start: $(QEMU_PC686_RTEMS_DEPLOY_DIR)/cpu1/cfs-cpu1.diskimg
%/container-start: custom-rules.mk
truncate -s 0 "$(@)"
echo -n "$(QEMU_HYPERVISOR) " >> "$(@)"
echo -n "$(QEMU_NET_OPTS) " >> "$(@)"
echo -n "$(QEMU_DISK_OPTS) " >> "$(@)"
echo -n "$(QEMU_DEVICE_OPTS) " >> "$(@)"
echo -n "$(QEMU_KERNEL) " >> "$(@)"
echo "" >> "$(@)"
chmod +x "$(@)"
$(O_qemu_yocto_linux)/stamp.image: QEMU_DISK_OPTS += -drive id=disk0,file=$(ROOTFS_IMAGE_BASENAME).$(IMAGE_TYPE),format=$(IMAGE_FORMAT)
$(O_qemu_yocto_linux)/stamp.image: QEMU_DISK_OPTS += -drive id=disk1,file=$(CFS_IMAGE_BASENAME).$(IMAGE_TYPE),format=$(IMAGE_FORMAT)
# Disabled until the workflow issues can be fixed
#$(O_qemu_yocto_linux)/stamp.image: $(QEMU_YOCTO_DEPLOY_DIR)/cpu1/container-start
#$(O_qemu_yocto_linux)/stamp.image: $(QEMU_YOCTO_DEPLOY_DIR)/cpu2/container-start
$(O_pc686_rtems5)/stamp.image: QEMU_HYPERVISOR = qemu-system-i386 -m 128M -no-reboot
$(O_pc686_rtems5)/stamp.image: QEMU_NETDEV_TYPE = i82557b
$(O_pc686_rtems5)/stamp.image: QEMU_DISK_OPTS += -drive id=disk0,file=$(CFS_IMAGE_BASENAME).diskimg,format=raw
$(O_pc686_rtems5)/stamp.image: $(QEMU_PC686_RTEMS_DEPLOY_DIR)/cpu1/container-start
# do not auto-delete these artifacts
.PRECIOUS: %.ext4 %.qcow2