From: Michal Sojka Date: Fri, 24 Aug 2018 08:28:09 +0000 (+0200) Subject: Allow building a Debian package from the repository X-Git-Url: https://rtime.felk.cvut.cz/gitweb/hercules2020/jailhouse-build.git/commitdiff_plain/533252183356da625b3cfc68a63268e0b32057c8 Allow building a Debian package from the repository --- diff --git a/README b/README index b74d1b6..e8eac01 100644 --- a/README +++ b/README @@ -1,7 +1,8 @@ Repository with Jailhouse build configuration for Jetson TX2 Building --------- +======== + wget https://debian.pengutronix.de/debian/pool/main/o/oselas.toolchain/oselas.toolchain-2014.12.2-aarch64-v8a-linux-gnu-gcc-4.9.2-glibc-2.20-binutils-2.24-kernel-3.16-sanitized_2014.12.2_amd64.deb sudo dpkg -i oselas.toolchain-2014.12.2-aarch64-v8a-linux-gnu-gcc-4.9.2-glibc-2.20-binutils-2.24-kernel-3.16-sanitized_2014.12.2_amd64.deb @@ -12,18 +13,37 @@ Building The above croscompiles the following: Linux kernel, Jailhouse and simple root filesystem. -Building on TX2 ---------------- +Building on TX2 (only Jailhouse and Linux) +------------------------------------------ make jailhouse CROSS_COMPILE= Booting -------- +======= + +Network book +------------ We use novaboot tool (https://github.com/wentasah/novaboot) to boot -the resulting images over network. Use build/boot to boot Jailhouse or -build/boot-linux to boot plain Linux without starting Jailhouse. +the resulting images over network. Use the `build/boot` script to boot +Jailhouse or `build/boot-linux` to boot plain Linux without starting +Jailhouse. + +Flash/SD card boot +------------------ + +To boot Linux and Jailhouse without novaboot, create a Debian package +by running: + + cd build + make deb + +Copy the resulting .deb package to the board and install it with + + dpkg -i jailhouse_*.deb + +Then, after rebooting choose "prem kernel and jailhouse" entry from +the extlinux boot menu. Jailhouse will start automatically during the +boot. You can use `systemctl` command to see its status, stop it etc.: -To boot without novaboot, copy linux-4.4/arch/arm64/boot/Image and -files from rootfs-overlay to your board. If needed, we will provide -deailed instructions later. + systemctl {status|start|stop} jailhouse diff --git a/build/.gitignore b/build/.gitignore index 7096827..aa8f91f 100644 --- a/build/.gitignore +++ b/build/.gitignore @@ -1,5 +1,7 @@ +/_install.deb/ /display/ /jailhouse-install/ +/jailhouse_*_arm64.deb /kernel-4.4/ /nvgpu/ /nvhost/ diff --git a/build/Makefile b/build/Makefile index 6e6050b..b609ecc 100644 --- a/build/Makefile +++ b/build/Makefile @@ -7,7 +7,8 @@ image.fit: buildroot/images/rootfs.cpio.uboot kernel-4.4/vmlinux mkimage -f auto -d kernel-4.4/arch/arm64/boot/Image -i buildroot/images/rootfs.cpio.uboot -b kernel-4.4/arch/arm64/boot/dts/tegra186-quill-p3310-1000-c03-00-base.dtb image.fit buildroot/images/rootfs.cpio.uboot: ./buildroot/.config -buildroot/images/rootfs.cpio.uboot: rootfs-overlay/lib/firmware/jailhouse.bin rootfs-overlay/lib/modules/4.4.38+/modules.dep +buildroot/images/rootfs.cpio.uboot: rootfs-overlay/lib/firmware/jailhouse.bin +buildroot/images/rootfs.cpio.uboot: modules_install buildroot/images/rootfs.cpio.uboot: $(shell find rootfs-overlay) buildroot/images/rootfs.cpio.uboot: rootfs-overlay/bin/prem-test $(MAKE) -j1 -C buildroot ROOTFS_CPIO_COMPRESS_CMD="gzip --fast -c" @@ -21,14 +22,14 @@ rootfs-overlay/lib/firmware/jailhouse.bin: $(wildcard ../jailhouse/configs/arm64 jailhouse: ../jailhouse/hypervisor/jailhouse.bin -JAILHOUSE_DESTDIR=$(CURDIR)/rootfs-overlay +DESTDIR=$(CURDIR)/rootfs-overlay jailhouse-install: FORCE - $(MAKE) -C ../jailhouse -j$(NPROC) install KDIR=$(CURDIR)/kernel-4.4 ARCH=arm64 DESTDIR=$(abspath $(JAILHOUSE_DESTDIR)) prefix=/usr - mkdir -p $(JAILHOUSE_DESTDIR)/jailhouse/configs/ $(JAILHOUSE_DESTDIR)/jailhouse/demos/ + $(MAKE) -C ../jailhouse -j$(NPROC) install KDIR=$(CURDIR)/kernel-4.4 ARCH=arm64 DESTDIR=$(abspath $(DESTDIR)) prefix=/usr + mkdir -p $(DESTDIR)/jailhouse/configs/ $(DESTDIR)/jailhouse/demos/ # cp ../jailhouse/inmates/demos/arm64/my-demo.bin rootfs-overlay/jailhouse/demos/ - cp ../jailhouse/configs/arm64/jetson-tx2.cell $(JAILHOUSE_DESTDIR)/jailhouse/configs/ - cp ../jailhouse/configs/arm64/jetson-tx2-demo.cell $(JAILHOUSE_DESTDIR)/jailhouse/configs/ + cp ../jailhouse/configs/arm64/jetson-tx2.cell $(DESTDIR)/jailhouse/configs/ + cp ../jailhouse/configs/arm64/jetson-tx2-demo.cell $(DESTDIR)/jailhouse/demos/ # Add something like this to ~/.ssh/config for # jailhouse-install-remote to work out of the box: @@ -54,12 +55,15 @@ jailhouse-install-remote: jailhouse-install echo '#define CONFIG_MACH_JETSON_TX2 1' >> $@.tmp mv --update $@.tmp $@ -rootfs-overlay/lib/modules/4.4.38+/modules.dep: kernel-4.4/vmlinux - $(MAKE) -C kernel-4.4 -j$(NPROC) modules_install INSTALL_MOD_PATH=$(CURDIR)/rootfs-overlay - kernel-4.4/vmlinux: $(MAKE) -C $(@D) -j$(NPROC) +linux_install: kernel-4.4/vmlinux + install -m644 -D kernel-4.4/arch/arm64/boot/Image $(DESTDIR)/boot/Image-prem + +modules_install: kernel-4.4/vmlinux + $(MAKE) -C kernel-4.4 -j$(NPROC) modules_install INSTALL_MOD_PATH=$(DESTDIR) + .PHONY: FORCE ../test/prem-test: FORCE @@ -73,3 +77,53 @@ deploy: ../test/prem-test scp ../test/prem-test tx2:/bin # scp ../jailhouse/hypervisor/jailhouse.bin tx2:/lib/firmware ssh tx2 'sh /etc/init.d/S20jailhouse.sh stop && sh /etc/init.d/S20jailhouse.sh start' + +deb: DESTDIR=$(CURDIR)/_install.deb +deb: jailhouse-install linux_install modules_install DEBIAN_DIR + $(file >$(DESTDIR)/DEBIAN/control,$(deb_control)) + $(file >$(DESTDIR)/DEBIAN/postinst,$(deb_postinst)) + $(file >$(DESTDIR)/DEBIAN/prerm,$(deb_prerm)) + chmod +x $(DESTDIR)/DEBIAN/postinst $(DESTDIR)/DEBIAN/prerm + rm -f _install.deb/lib/modules/*/source _install.deb/lib/modules/*/build + install -D ./rootfs-overlay/etc/init.d/S20jailhouse.sh $(DESTDIR)/etc/init.d/jailhouse + install -m644 -D ./rootfs-overlay/etc/systemd/system/jailhouse.service $(DESTDIR)/lib/systemd/system/jailhouse.service + install -d $(DESTDIR)/lib/systemd/system/multi-user.target.wants/ + ln -sf ../jailhouse.service $(DESTDIR)/lib/systemd/system/multi-user.target.wants/jailhouse.service +# Note: --root-owner-group requires dpkg version 1.19.0+ + dpkg-deb --root-owner-group --build $(DESTDIR) . + +DEBIAN_DIR: + install -d $(DESTDIR)/DEBIAN + + +define deb_control +Package: jailhouse +Essential: no +Priority: optional +Section: admin +Maintainer: Michal Sojka +Architecture: arm64 +Version: $(shell git describe --always --dirty) +Description: Jailhouse hypervisor and the Linux kernel for the HERCULES project. +endef + +define deb_postinst +#!/bin/sh +set -e +if ! grep -q Image-prem /boot/extlinux/extlinux.conf; then +cat >>/boot/extlinux/extlinux.conf <<'EOF' +LABEL prem + MENU LABEL prem kernel and jailhouse + LINUX /boot/Image-prem + APPEND $${cbootargs} root=/dev/mmcblk0p1 rw rootwait rootfstype=ext4 mem=7808M vmalloc=512M jailhouse +EOF +fi +endef + +define deb_prerm +#!/bin/sh +set -e +if grep -q Image-prem /boot/extlinux/extlinux.conf; then + . # TODO +fi +endef diff --git a/build/rootfs-overlay/etc/init.d/S20jailhouse.sh b/build/rootfs-overlay/etc/init.d/S20jailhouse.sh index c415e86..dea92ce 100644 --- a/build/rootfs-overlay/etc/init.d/S20jailhouse.sh +++ b/build/rootfs-overlay/etc/init.d/S20jailhouse.sh @@ -1,15 +1,17 @@ +#!/bin/sh + if ! grep -q -w jailhouse /proc/cmdline; then echo "Jailhouse not enabled" - return + return 1 fi case "$1" in start) printf "Starting Jailhouse: " /sbin/modprobe jailhouse - # Switch on Denver cores - echo 1 > /sys/devices/system/cpu/cpu1/online - echo 1 > /sys/devices/system/cpu/cpu2/online + # Switch off Denver cores + echo 0 > /sys/devices/system/cpu/cpu1/online + echo 0 > /sys/devices/system/cpu/cpu2/online /usr/sbin/jailhouse enable /jailhouse/configs/jetson-tx2.cell [ $? = 0 ] && echo "OK" || echo "FAIL" ;; diff --git a/build/rootfs-overlay/etc/systemd/system/jailhouse.service b/build/rootfs-overlay/etc/systemd/system/jailhouse.service new file mode 100644 index 0000000..71afd1e --- /dev/null +++ b/build/rootfs-overlay/etc/systemd/system/jailhouse.service @@ -0,0 +1,12 @@ +[Unit] +Description=Jailhouse hypervisor +ConditionKernelCommandLine=jailhouse + +[Service] +Type=oneshot +RemainAfterExit=true +ExecStart=/etc/init.d/jailhouse start +ExecStop=/etc/init.d/jailhouse stop + +[Install] +WantedBy=multi-user.target