diff options
| author | John Ogness <john.ogness@linutronix.de> | 2018-04-05 09:27:36 +0200 |
|---|---|---|
| committer | John Ogness <john.ogness@linutronix.de> | 2018-04-05 09:27:36 +0200 |
| commit | 74f93d82fc36156602164b540349c1c83fe4e2b6 (patch) | |
| tree | ec084c58eabb06b0538700c38e911a405c027d77 | |
| parent | 674363214075c751df862ae87a9cd5ab28194cce (diff) | |
add rootfs_basic scripts
These scripts are provided to participants after the training to
allow them to quickly/easily reproduce the many steps of creating
a simple root filesystem from scratch.
These scripts also serve as an excellent reference for trainers
to follow during the live excercises.
Signed-off-by: John Ogness <john.ogness@linutronix.de>
11 files changed, 161 insertions, 0 deletions
diff --git a/schulung_tools/rootfs_basic/scripts/README b/schulung_tools/rootfs_basic/scripts/README new file mode 100755 index 0000000..dcfdec3 --- /dev/null +++ b/schulung_tools/rootfs_basic/scripts/README @@ -0,0 +1,24 @@ +#!/bin/sh +set -e + +# download linux/busybox tarballs +./download_kernel.sh +./download_busybox.sh + +# unpack tarballs +./unpack_kernel.sh +./unpack_busybox.sh + +# build linux/busybox/hello +./build_kernel.sh +./build_busybox.sh +./build_hello.sh + +# create root filesystem +./create_rootfs.sh + +# configure/start nfs server +./setup_nfs_server.sh + +# start arm emulator +./start_vm.sh diff --git a/schulung_tools/rootfs_basic/scripts/build_busybox.sh b/schulung_tools/rootfs_basic/scripts/build_busybox.sh new file mode 100755 index 0000000..6beaf3b --- /dev/null +++ b/schulung_tools/rootfs_basic/scripts/build_busybox.sh @@ -0,0 +1,13 @@ +#!/bin/sh +set -e + +export CROSS_COMPILE=/opt/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf- + +cd busybox-1.28.1 + +make defconfig +make -j 4 +make install + +# check dependencies +${CROSS_COMPILE}objdump -x busybox | grep NEEDED diff --git a/schulung_tools/rootfs_basic/scripts/build_hello.sh b/schulung_tools/rootfs_basic/scripts/build_hello.sh new file mode 100755 index 0000000..c9a06ff --- /dev/null +++ b/schulung_tools/rootfs_basic/scripts/build_hello.sh @@ -0,0 +1,14 @@ +#!/bin/sh +set -e + +export CROSS_COMPILE=/opt/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf- + +cd ../src/hello + +${CROSS_COMPILE}gcc -c -fPIC file1.c file2.c +${CROSS_COMPILE}gcc -shared -Wl,-soname,libhello.so.0 -olibhello.so.0.0.1 file1.o file2.o +ln -sf libhello.so.0.0.1 libhello.so +${CROSS_COMPILE}gcc -ohello hello.c -L. -lhello + +# check dependencies +${CROSS_COMPILE}objdump -x hello | grep NEEDED diff --git a/schulung_tools/rootfs_basic/scripts/build_kernel.sh b/schulung_tools/rootfs_basic/scripts/build_kernel.sh new file mode 100755 index 0000000..427a56e --- /dev/null +++ b/schulung_tools/rootfs_basic/scripts/build_kernel.sh @@ -0,0 +1,12 @@ +#!/bin/sh +set -e + +export CROSS_COMPILE=/opt/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf- +export ARCH=arm + +cd linux-4.15.5 + +make vexpress_defconfig +make -j 4 zImage +make -j 4 modules +make vexpress-v2p-ca9.dtb diff --git a/schulung_tools/rootfs_basic/scripts/create_rootfs.sh b/schulung_tools/rootfs_basic/scripts/create_rootfs.sh new file mode 100755 index 0000000..1ba104a --- /dev/null +++ b/schulung_tools/rootfs_basic/scripts/create_rootfs.sh @@ -0,0 +1,55 @@ +#!/bin/sh +set -e + +CROSS_BASE=/opt/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf +CROSS_LIBC=$CROSS_BASE/arm-linux-gnueabihf/libc + +# create directories +mkdir -p nfsroot/dev +mkdir -p nfsroot/proc +mkdir -p nfsroot/sys +mkdir -p nfsroot/lib +mkdir -p nfsroot/bin +mkdir -p nfsroot/etc/ld.so.conf.d +mkdir -p nfsroot/opt/acme/lib + +# copy dependencies +cp $CROSS_LIBC/lib/ld-2.23.so nfsroot/lib/ +cp $CROSS_LIBC/lib/libc-2.23.so nfsroot/lib/ +cp $CROSS_LIBC/lib/libm-2.23.so nfsroot/lib/ + +# copy busybox + links +cp -a busybox-1.28.1/_install/* nfsroot/ + +# copy gdbserver +cp $CROSS_BASE/bin/gdbserver nfsroot/bin/ + +# copy hello/libfunc +cp ../src/hello/hello nfsroot/bin/ +cp ../src/hello/libhello.so.0.0.1 nfsroot/opt/acme/lib/ + +# create ldconfig configuration files +echo 'include /etc/ld.so.conf.d/*.conf' > nfsroot/etc/ld.so.conf +echo '/opt/acme/lib' > nfsroot/etc/ld.so.conf.d/acme.conf + +# create dynamic loader cache +qemu-arm $CROSS_LIBC/sbin/ldconfig -r nfsroot +qemu-arm $CROSS_LIBC/sbin/ldconfig -r nfsroot -p + +# create init configuation +cat > nfsroot/etc/inittab << 'EOF' +::sysinit:/etc/rcS +::askfirst:-/bin/sh +EOF + +# create start script +cat > nfsroot/etc/rcS << 'EOF' +#!/bin/sh + +mount -t proc proc /proc +mount -t sysfs sys /sys +mount -t tmpfs tmpfs /dev +mdev -s +echo /sbin/mdev > /proc/sys/kernel/hotplug +EOF +chmod 0755 nfsroot/etc/rcS diff --git a/schulung_tools/rootfs_basic/scripts/download_busybox.sh b/schulung_tools/rootfs_basic/scripts/download_busybox.sh new file mode 100755 index 0000000..20e1bf7 --- /dev/null +++ b/schulung_tools/rootfs_basic/scripts/download_busybox.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -e + +wget --continue http://busybox.net/downloads/busybox-1.28.1.tar.bz2 diff --git a/schulung_tools/rootfs_basic/scripts/download_kernel.sh b/schulung_tools/rootfs_basic/scripts/download_kernel.sh new file mode 100755 index 0000000..d729d2a --- /dev/null +++ b/schulung_tools/rootfs_basic/scripts/download_kernel.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -e + +wget --continue https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.15.5.tar.xz diff --git a/schulung_tools/rootfs_basic/scripts/setup_nfs_server.sh b/schulung_tools/rootfs_basic/scripts/setup_nfs_server.sh new file mode 100755 index 0000000..6b7d7ee --- /dev/null +++ b/schulung_tools/rootfs_basic/scripts/setup_nfs_server.sh @@ -0,0 +1,9 @@ +#!/bin/sh +set -e + +ROOTDIR="`pwd`/nfsroot" + +echo "$ROOTDIR 127.0.0.1(rw,sync,no_subtree_check,no_root_squash,insecure)" | sudo tee -a /etc/exports +# sudo rpcinfo +sudo systemctl restart nfs-kernel-server.service +# sudo exportfs -ra diff --git a/schulung_tools/rootfs_basic/scripts/start_vm.sh b/schulung_tools/rootfs_basic/scripts/start_vm.sh new file mode 100755 index 0000000..bd41b2f --- /dev/null +++ b/schulung_tools/rootfs_basic/scripts/start_vm.sh @@ -0,0 +1,18 @@ +#!/bin/sh +set -e + +export QEMU_AUDIO_DRV="none" + +BOOTPATH="`pwd`/linux-4.15.5/arch/arm/boot" + +# port forwarding rule for gdb +GDB_FWD="hostfwd=tcp::2345-:2345" + +exec qemu-system-arm \ + -M vexpress-a9 \ + -m 128 \ + -nographic \ + -net nic -net user,$GDB_FWD \ + -kernel $BOOTPATH/zImage \ + -dtb $BOOTPATH/dts/vexpress-v2p-ca9.dtb \ + -append "loglevel=7 console=ttyAMA0,115200 ip=dhcp root=/dev/nfs nfsroot=`pwd`/nfsroot,v3 rw" diff --git a/schulung_tools/rootfs_basic/scripts/unpack_busybox.sh b/schulung_tools/rootfs_basic/scripts/unpack_busybox.sh new file mode 100755 index 0000000..988a805 --- /dev/null +++ b/schulung_tools/rootfs_basic/scripts/unpack_busybox.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -e + +cat busybox-1.28.1.tar.bz2 | bzip2 -dc | tar -x -f - diff --git a/schulung_tools/rootfs_basic/scripts/unpack_kernel.sh b/schulung_tools/rootfs_basic/scripts/unpack_kernel.sh new file mode 100755 index 0000000..398ca5f --- /dev/null +++ b/schulung_tools/rootfs_basic/scripts/unpack_kernel.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -e + +cat linux-4.15.5.tar.xz | xz -d -c | tar -x -f - |
