1
0
mirror of https://github.com/RedPill-TTG/redpill-lkm.git synced 2024-02-16 18:08:21 +08:00

Add dev tools

This commit is contained in:
The Thor Group
-
parent dffcf018ce
commit 4ccf42fa6d
3 changed files with 106 additions and 0 deletions

5
tools/README.md Normal file
View File

@ -0,0 +1,5 @@
# Dev Tools
This directory contains some tools we use during development. They're not
normally used with the module in any way. They're messy, buggy, quick and
dirty but often helpful ;)

72
tools/inject_rp_ko.sh Normal file
View File

@ -0,0 +1,72 @@
#!/usr/bin/env bash
# Injects RedPill LKM file into a ramdisk inside of an existing image (so you can test new LKM without constant full image
# rebuild & transfer)
#
# Internally we use it something like this with Proxmox pointing to /dev/loop0 as the USB source:
# rm redpill.ko ; wget https://buildsrv/redpill.ko ; \
# IRP_LEAVE_ATTACHED=1 ./inject_rp_ko.sh rp-3615-v6.img redpill.ko ; losetup ; \
# qm stop 101 ; sleep 1 ; qm start 101 ; qm terminal 101 -iface serial1
self=${0##*/}
img="$(realpath $1 2> /dev/null)"
lkm="$(realpath $2 2> /dev/null)"
if [ $# -ne 2 -o ! -f "$img" -o ! -f "$lkm" ]
then
echo "Usage: $self <rp-load-img> <redpill.ko>"
exit 2
fi
echo "Detaching $img from all loopdevs"
losetup -j "$img" | grep -E -o '^/dev/loop[0-9]+' | \
while read -r loopdev; do
losetup -d "$loopdev"
echo "Detached $loopdev"
done
losetup -j "$img" | grep -E -q '^/dev/loop[0-9]+'
if [ $? -eq 0 ]; then
echo "$img is still attached to some loop devs!"
exit 1
fi
set -euo pipefail
LODEV="$(losetup --show -f -P "$img")"
UNIQ_BASE="$PWD/__inject_rp_$(date '+%s')"
echo "Making directories in $UNIQ_BASE"
TMP_MNT_DIR="$UNIQ_BASE/img-mnt"
TMP_RDU_DIR="$UNIQ_BASE/rd-unpacked"
mkdir -p "$TMP_MNT_DIR"
mkdir -p "$TMP_RDU_DIR"
echo "Mounting in $TMP_MNT_DIR"
mount "${LODEV}p1" "$TMP_MNT_DIR"
echo "Unpacking $TMP_MNT_DIR/rd.gz"
cd "$TMP_RDU_DIR"
if file "$TMP_MNT_DIR/rd.gz" | grep -q 'cpio archive'; then # special case: uncompressed rd
IRP_FLAT_RD=1
cat "$TMP_MNT_DIR/rd.gz" | cpio -idmv
else
xz -dc < "$TMP_MNT_DIR/rd.gz" | cpio -idmv
fi
echo "Copying $lkm"
cp "$lkm" "$TMP_RDU_DIR/usr/lib/modules/rp.ko"
echo "Repacking $TMP_MNT_DIR/rd.gz"
if [[ ! -z "${IRP_FLAT_RD}" ]]; then # special case: uncompressed rd
find . 2>/dev/null | cpio -o -H newc -R root:root > "$TMP_MNT_DIR/rd.gz"
else
find . 2>/dev/null | cpio -o -H newc -R root:root | xz -9 --format=lzma > "$TMP_MNT_DIR/rd.gz"
fi
echo "Unmounting & detaching (if requested)"
sync
umount "$TMP_MNT_DIR"
if [[ -z "${IRP_LEAVE_ATTACHED}" ]]; then
losetup -d "$LODEV"
fi
echo "Cleaning up $UNIQ_BASE"
rm -rf "$UNIQ_BASE"

29
tools/make_all.sh Executable file
View File

@ -0,0 +1,29 @@
#!/usr/bin/env bash
# Makes all permutations of the LKM and copies them to RedPill Load directory so that we can easily rebuild all images
# Yes, it has all the paths hardcoded - change it to fit your environment.
# When you are executing this script do it from the root of the LKM dir like ./tools/make_all.sh
LINUX_SRC_ROOT="$PWD/.."
RP_LOAD_ROOT="$HOME/build/redpill-load"
set -euo pipefail
# Build for v6 for 3615xs
make LINUX_SRC="$LINUX_SRC_ROOT/linux-3.10.x-bromolow-25426" clean
make LINUX_SRC="$LINUX_SRC_ROOT/linux-3.10.x-bromolow-25426"
cp redpill.ko "$RP_LOAD_ROOT/ext/rp-lkm/redpill-linux-v3.10.105.ko"
# Build for v7 for 3615xs
make LINUX_SRC="$LINUX_SRC_ROOT/bromolow-DSM-7.0-toolkit/build" clean
make LINUX_SRC="$LINUX_SRC_ROOT/bromolow-DSM-7.0-toolkit/build"
cp redpill.ko "$RP_LOAD_ROOT/ext/rp-lkm/redpill-linux-v3.10.108.ko"
# Build for v6 for 918+
make LINUX_SRC="$LINUX_SRC_ROOT/linux-4.4.x-apollolake-25426" clean
make LINUX_SRC="$LINUX_SRC_ROOT/linux-4.4.x-apollolake-25426"
cp redpill.ko "$RP_LOAD_ROOT/ext/rp-lkm/redpill-linux-v4.4.59+.ko"
# Build for v7 for 918+
make LINUX_SRC="$LINUX_SRC_ROOT/apollolake-DS-7.0-toolkit/build" clean
make LINUX_SRC="$LINUX_SRC_ROOT/apollolake-DS-7.0-toolkit/build"
cp redpill.ko "$RP_LOAD_ROOT/ext/rp-lkm/redpill-linux-v4.4.180+.ko"