From d00dee2a456f5bfbc180d636f0e55107334aaf8b Mon Sep 17 00:00:00 2001 From: Robert Nelson Date: Mon, 14 Aug 2023 21:33:46 -0500 Subject: [PATCH] generate basic rootfs Signed-off-by: Robert Nelson --- .gitignore | 2 + 05_generate_payload.bin.sh | 3 ++ create_sdcard_img.sh | 13 +++++- deploy/genimage.cfg | 2 +- generate_debian_console_root.sh | 76 +++++++++++++++++++++++++++++++++ 5 files changed, 94 insertions(+), 2 deletions(-) create mode 100755 generate_debian_console_root.sh diff --git a/.gitignore b/.gitignore index 26cd0b5..53856f1 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,8 @@ deploy/.modules deploy/*-modules.tar.gz deploy/Image deploy/*.dtb +deploy/debian* +ignore/ mirror/ riscv-toolchain/ hart-software-services/ diff --git a/05_generate_payload.bin.sh b/05_generate_payload.bin.sh index 9c692a0..3b5c641 100755 --- a/05_generate_payload.bin.sh +++ b/05_generate_payload.bin.sh @@ -4,6 +4,8 @@ cd ./deploy/ if [ -f ./src.bin ] ; then + tree -s ./ + if [ -f ./input/payload.bin ] ; then rm -rf ./input/payload.bin || true fi @@ -12,6 +14,7 @@ if [ -f ./src.bin ] ; then ./hss-payload-generator -vv -c config.yaml ./input/payload.bin + date unset test_var test_var=$(strings ./u-boot.bin | grep 'U-Boot 20' | head -n1 || true) if [ ! "x${test_var}" = "x" ] ; then diff --git a/create_sdcard_img.sh b/create_sdcard_img.sh index 5358c2d..3d65eff 100755 --- a/create_sdcard_img.sh +++ b/create_sdcard_img.sh @@ -1,9 +1,20 @@ #!/bin/bash +if ! id | grep -q root; then + echo "./create_sdcard_img.sh must be run as root:" + echo "sudo ./create_sdcard_img.sh" + exit +fi + cd ./deploy/ if [ ! -d ./root/ ] ; then mkdir ./root/ || true fi -sudo genimage --config genimage.cfg + +if [ -d ./tmp ] ; then + rm -rf ./tmp || true +fi + +genimage --config genimage.cfg # diff --git a/deploy/genimage.cfg b/deploy/genimage.cfg index 15fab71..95a2f38 100644 --- a/deploy/genimage.cfg +++ b/deploy/genimage.cfg @@ -31,6 +31,6 @@ image sdcard.img { partition root { partition-type-uuid = 0FC63DAF-8483-4772-8E79-3D69D8477DE4 - image = "rootfs.cpio" + image = "root.ext4" } } diff --git a/generate_debian_console_root.sh b/generate_debian_console_root.sh new file mode 100755 index 0000000..55eff67 --- /dev/null +++ b/generate_debian_console_root.sh @@ -0,0 +1,76 @@ +#!/bin/bash + +if ! id | grep -q root; then + echo "./generate_debian_console_root.sh must be run as root:" + echo "sudo ./generate_debian_console_root.sh" + exit +fi + +wdir=`pwd` + +if [ -f /tmp/latest ] ; then + rm -rf /tmp/latest | true +fi +wget --quiet --directory-prefix=/tmp/ https://rcn-ee.net/rootfs/debian-riscv64-sid-minimal/latest || true +if [ -f /tmp/latest ] ; then + latest_rootfs=$(cat "/tmp/latest") + datestamp=$(cat "/tmp/latest" | awk -F 'riscv64-' '{print $2}' | awk -F '.' '{print $1}') + + if [ ! -f ./deploy/debian-sid-console-riscv64-${datestamp}/riscv64-rootfs-debian-sid.tar ] ; then + wget -c --directory-prefix=./deploy https://rcn-ee.net/rootfs/debian-riscv64-sid-minimal/${datestamp}/${latest_rootfs} + cd ./deploy/ + tar xf ${latest_rootfs} + cd ../ + fi +else + echo "Failure: getting image" + exit 2 +fi + +if [ -d ./ignore/.root ] ; then + rm -rf ./ignore/.root || true +fi +mkdir -p ./ignore/.root + +tar xfp ./deploy/debian-sid-console-riscv64-${datestamp}/riscv64-rootfs-*.tar -C ./ignore/.root +sync + +mkdir -p ./ignore/.root/boot/firmware/ || true + +echo '/dev/mmcblk0p2 /boot/firmware/ auto defaults 0 2' >> ./ignore/.root/etc/fstab +echo '/dev/mmcblk0p3 / auto errors=remount-ro 0 1' >> ./ignore/.root/etc/fstab +echo 'debugfs /sys/kernel/debug debugfs mode=755,uid=root,gid=gpio,defaults 0 0' >> ./ignore/.root/etc/fstab + +rm -rf ./ignore/.root/usr/lib/systemd/system/bb-usb-gadgets.service || true +rm -rf ./ignore/.root/etc/systemd/system/getty.target.wants/serial-getty@ttyGS0.service || true +rm -rf ./ignore/.root/etc/systemd/network/usb0.network || true +rm -rf ./ignore/.root/etc/systemd/network/usb1.network || true + +rm -rf ./ignore/.root/usr/lib/systemd/system/grow_partition.service || true +cd ./ignore/.root/ +ln -L -f -s -v /lib/systemd/system/resize_filesystem.service --target-directory=./etc/systemd/system/multi-user.target.wants/ +cd ../../ + +cp -v ./ignore/.root/etc/bbb.io/templates/eth0-DHCP.network ./ignore/.root/etc/systemd/network/eth0.network || true + +# setuid root ping+ping6 +chmod u+s ./ignore/.root/usr/bin/ping ./ignore/.root/usr/bin/ping6 + +if [ -f ./deploy/.modules ] ; then + version=$(cat ./deploy/.modules || true) + if [ -f ./deploy/${version}-modules.tar.gz ] ; then + tar xf ./deploy/${version}-modules.tar.gz -C ./ignore/.root/usr/ + fi +fi + +echo '---------------------' +echo 'File Size' +du -sh ignore/.root/ || true +echo '---------------------' + +dd if=/dev/zero of=./deploy/input/root.ext4 bs=1 count=0 seek=4000M +mkfs.ext4 -F ./deploy/input/root.ext4 -d ./ignore/.root + +if [ -f ./.06_generate_root.sh ] ; then + rm -f ./.06_generate_root.sh || true +fi