Files
kali-arm/odroid-xu3.sh

338 lines
11 KiB
Bash
Raw Normal View History

2021-09-16 06:42:05 +01:00
#!/usr/bin/env bash
#
# Kali Linux ARM build-script for ODROID-XU3 (32-bit)
2021-09-27 10:51:02 +01:00
# Source: https://gitlab.com/kalilinux/build-scripts/kali-arm
2021-09-16 06:42:05 +01:00
#
2021-09-27 10:51:02 +01:00
# This is a supported device - which you can find pre-generated images for: https://www.kali.org/get-kali/
2021-09-16 06:42:05 +01:00
# More information: https://www.kali.org/docs/arm/odroid-xu3/
#
# Stop on error
set -e
2014-09-21 20:22:00 -05:00
2021-08-30 15:07:22 -05:00
# shellcheck disable=SC2154
# Load general functions
# shellcheck source=/dev/null
source ./common.d/functions.sh
2014-09-21 20:22:00 -05:00
2021-08-30 15:07:22 -05:00
# Hardware model
hw_model=${hw_model:-"odroid-xu3"}
2020-07-21 15:16:41 -05:00
# Architecture
architecture=${architecture:-"armhf"}
2021-08-30 15:07:22 -05:00
# Variant name for image and dir build
variant=${variant:-"${architecture}"}
# Desktop manager (xfce, gnome, i3, kde, lxde, mate, e17 or none)
desktop=${desktop:-"xfce"}
# Load common variables
include variables
2021-09-16 06:58:38 +01:00
# Checks script environment
2021-08-30 15:07:22 -05:00
include check
# Packages build list
include packages
# Execute initial debootstrap
debootstrap_exec http://http.kali.org/kali
# Enable eatmydata in compilation
include eatmydata
2020-07-21 15:16:41 -05:00
# debootstrap second stage
2020-08-02 00:14:21 -05:00
systemd-nspawn_exec eatmydata /debootstrap/debootstrap --second-stage
2021-08-30 15:07:22 -05:00
# Define sources.list
include sources.list
# APT options
include apt_options
2020-07-21 15:16:41 -05:00
# So X doesn't complain, we add kali to hosts
2021-08-30 15:07:22 -05:00
include hosts
# Set hostname
set_hostname "${hostname}"
# Network configs
include network
add_interface eth0
2021-09-16 06:58:38 +01:00
# Copy directory bsp into build dir
2021-09-19 10:56:45 +01:00
status "Copy directory bsp into build dir"
2021-08-30 15:07:22 -05:00
cp -rp bsp "${work_dir}"
2014-09-21 20:22:00 -05:00
2021-09-16 06:58:38 +01:00
# Disable RESUME (suspend/resume is currently broken anyway!) which speeds up boot massively
2021-08-30 15:07:22 -05:00
mkdir -p ${work_dir}/etc/initramfs-tools/conf.d/
cat << EOF > ${work_dir}/etc/initramfs-tools/conf.d/resume
RESUME=none
EOF
2014-09-21 20:22:00 -05:00
2020-07-21 15:16:41 -05:00
# Third stage
2021-09-19 20:03:59 +01:00
cat <<EOF > "${work_dir}"/third-stage
#!/usr/bin/env bash
set -e
2021-09-19 10:56:45 +01:00
status_3i=0
2021-09-19 11:34:26 +01:00
status_3t=\$(grep '^status_stage3 ' \$0 | wc -l)
2014-09-21 20:22:00 -05:00
2021-09-19 10:56:45 +01:00
status_stage3() {
status_3i=\$((status_3i+1))
echo " [i] Stage 3 (\${status_3i}/\${status_3t}): \$1"
}
status_stage3 'Update apt'
2021-08-30 15:07:22 -05:00
export DEBIAN_FRONTEND=noninteractive
2020-08-02 00:14:21 -05:00
eatmydata apt-get update
2021-09-19 10:56:45 +01:00
status_stage3 'Install core packages'
2021-08-30 15:07:22 -05:00
eatmydata apt-get -y install ${third_stage_pkgs}
2014-09-21 20:22:00 -05:00
2021-09-19 10:56:45 +01:00
status_stage3 'Install packages'
2021-08-30 15:07:22 -05:00
eatmydata apt-get install -y ${packages} || eatmydata apt-get install -y --fix-broken
2021-09-19 10:56:45 +01:00
status_stage3 'Install desktop packages'
2021-08-30 15:07:22 -05:00
eatmydata apt-get install -y ${desktop_pkgs} ${extra} || eatmydata apt-get install -y --fix-broken
2020-07-21 15:16:41 -05:00
status_stage3 'ntp doesn't always sync the date, but systemd's timesyncd does, so we remove ntp and reinstall it with this'
eatmydata apt-get install -y systemd-timesyncd --autoremove
2021-09-19 10:56:45 +01:00
status_stage3 'Clean up'
2021-08-30 15:07:22 -05:00
eatmydata apt-get -y --purge autoremove
2020-07-21 15:16:41 -05:00
2021-09-19 10:56:45 +01:00
status_stage3 'Linux console/keyboard configuration'
2020-07-21 15:16:41 -05:00
echo 'console-common console-data/keymap/policy select Select keymap from full list' | debconf-set-selections
echo 'console-common console-data/keymap/full select en-latin1-nodeadkeys' | debconf-set-selections
2021-09-19 10:56:45 +01:00
status_stage3 'Copy all services'
2020-07-21 15:16:41 -05:00
cp -p /bsp/services/all/*.service /etc/systemd/system/
2014-09-21 20:22:00 -05:00
2021-09-19 10:56:45 +01:00
status_stage3 'Copy script rpi-resizerootfs'
2021-08-30 15:07:22 -05:00
install -m755 /bsp/scripts/rpi-resizerootfs /usr/sbin/
install -m755 /bsp/scripts/growpart /usr/local/bin/
2021-08-30 15:07:22 -05:00
2021-09-19 10:56:45 +01:00
status_stage3 'Enable rpi-resizerootfs first boot'
2021-08-30 15:07:22 -05:00
systemctl enable rpi-resizerootfs
2021-09-19 10:56:45 +01:00
status_stage3 'Generate SSH host keys on first run'
systemctl enable regenerate_ssh_host_keys
status_stage3 'Enable ssh'
systemctl enable ssh
2021-09-19 10:56:45 +01:00
status_stage3 'Allow users to use NetworkManager over ssh'
install -m644 /bsp/polkit/10-NetworkManager.pkla /var/lib/polkit-1/localauthority/50-local.d
2021-09-19 10:56:45 +01:00
status_stage3 'Set a REGDOMAIN'
2020-07-21 15:16:41 -05:00
sed -i -e 's/REGDOM.*/REGDOMAIN=00/g' /etc/default/crda
2020-05-07 16:57:01 -05:00
2021-09-19 10:56:45 +01:00
status_stage3 'Enable login over serial'
2021-08-30 15:07:22 -05:00
echo "T0:23:respawn:/sbin/agetty -L ttySAC2 115200 vt100" >> /etc/inittab
2014-09-21 20:22:00 -05:00
2021-09-19 10:56:45 +01:00
status_stage3 'Try and make the console a bit nicer. Set the terminus font for a bit nicer display'
2020-07-21 15:16:41 -05:00
sed -i -e 's/FONTFACE=.*/FONTFACE="Terminus"/' /etc/default/console-setup
sed -i -e 's/FONTSIZE=.*/FONTSIZE="6x12"/' /etc/default/console-setup
2014-09-21 20:22:00 -05:00
2021-09-19 10:56:45 +01:00
status_stage3 'Fix startup time from 5 minutes to 15 secs on raise interface wlan0'
2020-07-21 15:16:41 -05:00
sed -i 's/^TimeoutStartSec=5min/TimeoutStartSec=15/g' "/usr/lib/systemd/system/networking.service"
2020-08-02 00:14:21 -05:00
2021-08-30 15:07:22 -05:00
cat << __EOF__ >> /etc/udev/links.conf
M ttySAC2 c 5 1
__EOF__
cat << _EOF_ >> /etc/securetty
ttySAC0
ttySAC1
ttySAC2
_EOF_
2021-09-19 10:56:45 +01:00
status_stage3 'Serial console settings'
2021-08-30 15:07:22 -05:00
# (Auto login on serial console)
#T1:12345:respawn:/sbin/agetty 115200 ttySAC2 vt100 >> /etc/inittab
# (No auto login)
#T1:12345:respawn:/bin/login -f root ttySAC2 /dev/ttySAC2 2>&1' >> /etc/inittab
2021-09-16 06:58:38 +01:00
# Make sure ttySACX is in root/etc/securetty so root can login on serial console below
2021-08-30 15:07:22 -05:00
echo 'T1:12345:respawn:/bin/login -f root ttySAC2 /dev/ttySAC2 2>&1' >> /etc/inittab
2021-09-19 10:56:45 +01:00
status_stage3 'Enable runonce'
2021-08-30 15:07:22 -05:00
install -m755 /bsp/scripts/runonce /usr/sbin/
cp -rf /bsp/runonce.d /etc
systemctl enable runonce
2021-09-19 10:56:45 +01:00
status_stage3 'Clean up dpkg.eatmydata'
2020-08-02 00:14:21 -05:00
rm -f /usr/bin/dpkg
2021-08-30 15:07:22 -05:00
dpkg-divert --remove --rename /usr/bin/dpkg
2014-09-21 20:22:00 -05:00
EOF
2020-07-21 15:16:41 -05:00
# Run third stage
2021-09-17 10:42:05 +01:00
chmod 0755 "${work_dir}"/third-stage
2021-09-19 10:56:45 +01:00
status "Run third stage"
2020-07-21 15:16:41 -05:00
systemd-nspawn_exec /third-stage
2014-09-21 20:22:00 -05:00
2020-07-21 15:16:41 -05:00
# Clean system
2021-08-30 15:07:22 -05:00
include clean_system
2021-09-17 16:47:51 +01:00
trap clean_build ERR SIGTERM SIGINT
2014-09-21 20:22:00 -05:00
# Kernel section. If you want to use a custom kernel, or configuration, replace
2021-09-16 06:58:38 +01:00
# them in this section
2021-09-19 10:56:45 +01:00
status "Kernel stuff"
git clone --depth 1 -b odroidxu4-4.14.y https://github.com/hardkernel/linux.git ${work_dir}/usr/src/kernel
2020-07-21 15:16:41 -05:00
cd ${work_dir}/usr/src/kernel
git rev-parse HEAD > ${work_dir}/usr/src/kernel-at-commit
patch -p1 --no-backup-if-mismatch < ${current_dir}/patches/kali-wifi-injection-4.14.patch
patch -p1 --no-backup-if-mismatch < ${current_dir}/patches/0001-wireless-carl9170-Enable-sniffer-mode-promisc-flag-t.patch
2014-09-21 20:22:00 -05:00
touch .scmversion
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabihf-
2021-08-30 15:07:22 -05:00
cp ${current_dir}/kernel-configs/odroid-xu3.config .config
cp ${current_dir}/kernel-configs/odroid-xu3.config ../odroid-xu3.config
2014-09-21 20:22:00 -05:00
make -j $(grep -c processor /proc/cpuinfo)
2020-07-21 15:16:41 -05:00
make modules_install INSTALL_MOD_PATH=${work_dir}
cp arch/arm/boot/zImage ${work_dir}/boot
cp arch/arm/boot/dts/exynos5422-odroidxu3.dtb ${work_dir}/boot
cp arch/arm/boot/dts/exynos5422-odroidxu3-lite.dtb ${work_dir}/boot
cp arch/arm/boot/dts/exynos5422-odroidxu4.dtb ${work_dir}/boot
cp arch/arm/boot/dts/exynos5422-odroidxu4-kvm.dtb ${work_dir}/boot
make mrproper
2021-08-30 15:07:22 -05:00
cp ${current_dir}/kernel-configs/odroid-xu3.config .config
cp ${current_dir}/kernel-configs/odroid-xu3.config ../odroid-xu3.config
cd "${base_dir}"
2014-09-21 20:22:00 -05:00
2017-09-20 17:42:31 -05:00
# Fix up the symlink for building external modules
# kernver is used so we don't need to keep track of what the current compiled
# version is
2020-07-21 15:16:41 -05:00
kernver=$(ls ${work_dir}/lib/modules/)
cd ${work_dir}/lib/modules/${kernver}
2017-09-20 17:42:31 -05:00
rm build
rm source
ln -s /usr/src/kernel build
ln -s /usr/src/kernel source
2021-09-19 10:56:45 +01:00
status "/boot/boot.ini"
2020-07-21 15:16:41 -05:00
cat << EOF > ${work_dir}/boot/boot.ini
2014-09-21 20:22:00 -05:00
ODROIDXU-UBOOT-CONFIG
# U-Boot Parameters
setenv initrd_high "0xffffffff"
setenv fdt_high "0xffffffff"
# Mac address configuration
setenv macaddr "00:1e:06:61:7a:39"
#------------------------------------------------------------------------------------------------------
2021-09-16 06:58:38 +01:00
# Basic Ubuntu Setup. Don't touch unless you know what you are doing
2014-09-21 20:22:00 -05:00
# --------------------------------
setenv bootrootfs "console=tty1 console=ttySAC2,115200n8 root=/dev/mmcblk0p2 rootwait rootfstype=$fstype net.ifnames=0 rw"
2014-09-21 20:22:00 -05:00
# boot commands
2018-06-16 23:07:36 -05:00
# Uncomment the following if you use an initrd
#setenv bootcmd "fatload mmc 0:1 0x40008000 zImage; fatload mmc 0:1 0x42000000 uInitrd; fatload mmc 0:1 0x44000000 exynos5422-odroidxu3.dtb; bootz 0x40008000 0x42000000 0x44000000"
# Uncomment the following if you do NOT use an initrd
setenv bootcmd "fatload mmc 0:1 0x40008000 zImage; fatload mmc 0:1 0x42000000 uInitrd; fatload mmc 0:1 0x44000000 exynos5422-odroidxu3.dtb; bootz 0x40008000 - 0x44000000"
2014-09-21 20:22:00 -05:00
2018-12-29 19:20:05 -06:00
# --- Screen Configuration for HDMI --- #
2014-09-21 20:22:00 -05:00
# ---------------------------------------
2021-09-16 06:58:38 +01:00
# Uncomment only ONE line! Leave all commented for automatic selection
2014-09-21 20:22:00 -05:00
# Uncomment only the setenv line!
# ---------------------------------------
# ODROID-VU forced resolution
# setenv videoconfig "video=HDMI-A-1:1280x800@60"
# -----------------------------------------------
# 1920x1080 (1080P) with monitor provided EDID information. (1080p-edid)
# setenv videoconfig "video=HDMI-A-1:1920x1080@60"
# -----------------------------------------------
# 1920x1080 (1080P) without monitor data using generic information (1080p-noedid)
# setenv videoconfig "drm_kms_helper.edid_firmware=edid/1920x1080.bin"
# -----------------------------------------------
# 1280x720 (720P) with monitor provided EDID information. (720p-edid)
# setenv videoconfig "video=HDMI-A-1:1280x720@60"
# -----------------------------------------------
# 1280x720 (720P) without monitor data using generic information (720p-noedid)
# setenv videoconfig "drm_kms_helper.edid_firmware=edid/1280x720.bin"
# -----------------------------------------------
# 1024x768 without monitor data using generic information
# setenv videoconfig "drm_kms_helper.edid_firmware=edid/1024x768.bin"
# final boot args
setenv bootargs "\${bootrootfs} \${videoconfig} smsc95xx.macaddr=\${macaddr}"
# drm.debug=0xff
# Boot the board
boot
EOF
cd "${current_dir}/"
2021-08-30 15:07:22 -05:00
2021-09-16 06:58:38 +01:00
# Calculate the space to create the image and create
2021-08-30 15:07:22 -05:00
make_image
2018-07-06 18:03:37 -05:00
# Create the disk and partition it
echo "Creating image file ${image_name}.img"
2021-09-19 13:45:29 +01:00
parted -s "${image_dir}/${image_name}.img" mklabel msdos
parted -s "${image_dir}/${image_name}.img" mkpart primary fat32 4MiB ${bootsize}MiB
parted -s -a minimal "${image_dir}/${image_name}.img" mkpart primary $fstype ${bootsize}MiB 100%
2018-07-06 18:03:37 -05:00
# Set the partition variables
2021-09-19 13:45:29 +01:00
loopdevice=$(losetup --show -fP "${image_dir}/${image_name}.img")
2021-08-30 15:07:22 -05:00
bootp="${loopdevice}p1"
rootp="${loopdevice}p2"
2018-07-06 18:03:37 -05:00
# Create file systems
2021-09-19 10:56:45 +01:00
status "Formatting partitions"
2021-08-30 15:07:22 -05:00
if [[ "$fstype" == "ext4" ]]; then
features="^64bit,^metadata_csum"
elif [[ "$fstype" == "ext3" ]]; then
features="^64bit"
fi
2021-08-30 15:07:22 -05:00
mkfs -O "$features" -t "$fstype" -L BOOT "${bootp}"
mkfs -O "$features" -t "$fstype" -L ROOTFS "${rootp}"
2018-07-06 18:03:37 -05:00
# Create the dirs for the partitions and mount them
2021-09-19 10:56:45 +01:00
status "Create the dirs for the partitions and mount them"
mkdir -p "${base_dir}"/root/
mount "${rootp}" "${base_dir}"/root
mkdir -p "${base_dir}"/root/boot
mount "${bootp}" "${base_dir}"/root/boot
2018-07-06 18:03:37 -05:00
2021-09-16 06:58:38 +01:00
# We do this down here to get rid of the build system's resolv.conf after running through the build
echo "nameserver ${nameserver}" > "${work_dir}"/etc/resolv.conf
2018-07-06 18:03:37 -05:00
2021-09-16 06:58:38 +01:00
# Create an fstab so that we don't mount / read-only
2021-09-19 10:56:45 +01:00
status "/etc/fstab"
UUID=$(blkid -s UUID -o value ${rootp})
echo "UUID=$UUID / $fstype errors=remount-ro 0 1" >> ${work_dir}/etc/fstab
2021-09-19 10:56:45 +01:00
status "Rsyncing rootfs into image file"
rsync -HPavz -q "${work_dir}"/ "${base_dir}"/root/
2021-08-30 15:07:22 -05:00
sync
2014-09-21 20:22:00 -05:00
2021-09-16 06:58:38 +01:00
# Write the signed u-boot binary to the image so that it will boot
2021-09-19 10:56:45 +01:00
status "u-Boot"
cd "${base_dir}"
git clone --depth 1 -b odroidxu4-v2017.05 https://github.com/hardkernel/u-boot.git
cd "${base_dir}"/u-boot
2018-08-03 15:04:07 -05:00
make odroid-xu4_defconfig
make
cd sd_fuse
2018-07-06 18:03:37 -05:00
sh sd_fusing.sh ${loopdevice}
2014-09-21 20:22:00 -05:00
cd "${current_dir}/"
2021-08-30 15:07:22 -05:00
2021-09-19 10:56:45 +01:00
# Flush buffers and bytes - this is nicked from the Devuan arm-sdk
2021-09-17 09:46:40 -05:00
blockdev --flushbufs "${loopdevice}"
python3 -c 'import os; os.fsync(open("'${loopdevice}'", "r+b"))'
2021-09-17 09:46:40 -05:00
2021-09-19 10:56:45 +01:00
# Unmount filesystem
status "Unmount filesystem"
2021-08-30 15:07:22 -05:00
umount -l "${rootp}"
# Check filesystem
2021-09-19 10:56:45 +01:00
status "Check filesystem"
2021-09-19 10:59:35 +01:00
e2fsck -y -f "${rootp}"
2021-08-30 15:07:22 -05:00
# Remove loop devices
2021-09-19 10:56:45 +01:00
status "Remove loop devices"
kpartx -dv "${loopdevice}"
2021-08-30 15:07:22 -05:00
losetup -d "${loopdevice}"
# Compress image compilation
include compress_img
2018-06-30 17:03:58 -05:00
2021-09-16 06:58:38 +01:00
# Clean up all the temporary build stuff and remove the directories
# Comment this out to keep things around if you want to see what may have gone wrong
clean_build
2021-09-27 10:51:08 +01:00
# Quit
log "Done" green
exit 0