2021-09-16 06:42:05 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
#
|
|
|
|
|
# Kali Linux ARM build-script for NanoPC-T3/T4 (64-bit)
|
2021-10-12 22:10:32 +01:00
|
|
|
# Source: https://gitlab.com/kalilinux/build-scripts/kali-arm
|
2021-09-16 06:42:05 +01:00
|
|
|
#
|
2021-10-12 22:10:32 +01:00
|
|
|
# This is a supported device - which you can find pre-generated images on: https://www.kali.org/get-kali/
|
2021-09-16 06:42:05 +01:00
|
|
|
# More information: https://www.kali.org/docs/arm/nanopc-t3/
|
|
|
|
|
#
|
|
|
|
|
|
2021-08-30 15:10:20 -05:00
|
|
|
# Hardware model
|
2021-09-16 19:53:57 +01:00
|
|
|
hw_model=${hw_model:-"nanopc-t"}
|
2020-07-21 00:44:37 -05:00
|
|
|
# Architecture
|
|
|
|
|
architecture=${architecture:-"arm64"}
|
2021-08-30 15:10:20 -05:00
|
|
|
# Desktop manager (xfce, gnome, i3, kde, lxde, mate, e17 or none)
|
|
|
|
|
desktop=${desktop:-"xfce"}
|
|
|
|
|
|
2021-10-12 20:56:41 +00:00
|
|
|
# Load default base_image configs
|
|
|
|
|
source ./common.d/base_image.sh
|
|
|
|
|
|
2021-08-30 15:10:20 -05:00
|
|
|
# Network configs
|
|
|
|
|
add_interface eth0
|
2021-09-07 13:43:29 -05:00
|
|
|
#add_interface wlan0
|
2021-09-17 16:02:12 +01:00
|
|
|
|
2020-07-21 00:44:37 -05:00
|
|
|
# Third stage
|
2021-10-12 20:56:41 +00:00
|
|
|
cat <<EOF >> "${work_dir}"/third-stage
|
|
|
|
|
status_stage3 'Enable login over serial (No password)'
|
2021-08-30 15:10:20 -05:00
|
|
|
echo "T0:23:respawn:/sbin/agetty -L ttyAMA0 115200 vt100" >> /etc/inittab
|
2021-10-13 20:10:29 -05:00
|
|
|
|
|
|
|
|
status_stage3 'Fixup wireless-regdb signature'
|
|
|
|
|
update-alternatives --set regulatory.db /lib/firmware/regulatory.db-upstream
|
2017-09-20 13:23:36 -05:00
|
|
|
EOF
|
|
|
|
|
|
2020-07-21 00:44:37 -05:00
|
|
|
# Run third stage
|
2021-10-12 20:56:41 +00:00
|
|
|
include third_stage
|
2017-09-20 13:23:36 -05:00
|
|
|
|
2020-07-21 00:44:37 -05:00
|
|
|
# Clean system
|
2021-08-30 15:10:20 -05:00
|
|
|
include clean_system
|
2017-09-20 13:23:36 -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 section"
|
2020-07-21 00:44:37 -05:00
|
|
|
git clone --depth 1 https://github.com/friendlyarm/linux -b nanopi2-v4.4.y ${work_dir}/usr/src/kernel
|
2021-09-17 16:02:12 +01:00
|
|
|
cd ${work_dir}/usr/src/kernel/
|
2020-07-21 00:44:37 -05:00
|
|
|
git rev-parse HEAD > ${work_dir}/usr/src/kernel-at-commit
|
2017-09-20 13:23:36 -05:00
|
|
|
touch .scmversion
|
2018-07-16 15:10:40 -05:00
|
|
|
export ARCH=arm64
|
2021-09-19 10:11:39 +01:00
|
|
|
#export CROSS_COMPILE="${base_dir}"/gcc-arm-linux-gnueabihf-4.7/bin/arm-linux-gnueabihf-
|
2018-07-16 15:10:40 -05:00
|
|
|
export CROSS_COMPILE=aarch64-linux-gnu-
|
2021-10-12 17:04:33 -05:00
|
|
|
patch -p1 --no-backup-if-mismatch < ${repo_dir}/patches/kali-wifi-injection-4.4.patch
|
2018-07-16 15:10:40 -05:00
|
|
|
make nanopi3_linux_defconfig
|
2017-09-20 13:23:36 -05:00
|
|
|
make -j $(grep -c processor /proc/cpuinfo)
|
2020-07-21 00:44:37 -05:00
|
|
|
make modules_install INSTALL_MOD_PATH=${work_dir}
|
|
|
|
|
cp arch/arm64/boot/Image ${work_dir}/boot
|
|
|
|
|
cp arch/arm64/boot/dts/nexell/*.dtb ${work_dir}/boot/
|
2017-09-20 13:23:36 -05:00
|
|
|
make mrproper
|
2018-07-16 15:10:40 -05:00
|
|
|
make nanopi3_linux_defconfig
|
2021-10-12 17:04:33 -05:00
|
|
|
cd "${repo_dir}/"
|
2017-09-20 13:23:36 -05:00
|
|
|
|
2021-09-16 06:58:38 +01:00
|
|
|
# Copy over the firmware for the nanopi3 wifi
|
2018-06-25 19:07:00 -05:00
|
|
|
# At some point, nexmon could work for the device, but the support would need to
|
2021-09-16 06:58:38 +01:00
|
|
|
# be added to nexmon
|
2021-09-19 10:56:45 +01:00
|
|
|
status "WiFi firmware"
|
2020-07-21 00:44:37 -05:00
|
|
|
mkdir -p ${work_dir}/lib/firmware/ap6212/
|
|
|
|
|
wget https://raw.githubusercontent.com/friendlyarm/android_vendor_broadcom_nanopi2/nanopi2-lollipop-mr1/proprietary/nvram_ap6212.txt -O ${work_dir}/lib/firmware/ap6212/nvram.txt
|
|
|
|
|
wget https://raw.githubusercontent.com/friendlyarm/android_vendor_broadcom_nanopi2/nanopi2-lollipop-mr1/proprietary/nvram_ap6212a.txt -O ${work_dir}/lib/firmware/ap6212/nvram_ap6212.txt
|
|
|
|
|
wget https://raw.githubusercontent.com/friendlyarm/android_vendor_broadcom_nanopi2/nanopi2-lollipop-mr1/proprietary/fw_bcm43438a0.bin -O ${work_dir}/lib/firmware/ap6212/fw_bcm43438a0.bin
|
|
|
|
|
wget https://raw.githubusercontent.com/friendlyarm/android_vendor_broadcom_nanopi2/nanopi2-lollipop-mr1/proprietary/fw_bcm43438a1.bin -O ${work_dir}/lib/firmware/ap6212/fw_bcm43438a1.bin
|
|
|
|
|
wget https://raw.githubusercontent.com/friendlyarm/android_vendor_broadcom_nanopi2/nanopi2-lollipop-mr1/proprietary/fw_bcm43438a0_apsta.bin -O ${work_dir}/lib/firmware/ap6212/fw_bcm43438a0_apsta.bin
|
|
|
|
|
wget https://raw.githubusercontent.com/friendlyarm/android_vendor_broadcom_nanopi2/nanopi2-lollipop-mr1/proprietary/bcm43438a0.hcd -O ${work_dir}/lib/firmware/ap6212/bcm43438a0.hcd
|
|
|
|
|
wget https://raw.githubusercontent.com/friendlyarm/android_vendor_broadcom_nanopi2/nanopi2-lollipop-mr1/proprietary/bcm43438a1.hcd -O ${work_dir}/lib/firmware/ap6212/bcm43438a1.hcd
|
|
|
|
|
wget https://raw.githubusercontent.com/friendlyarm/android_vendor_broadcom_nanopi2/nanopi2-lollipop-mr1/proprietary/config_ap6212.txt -O ${work_dir}/lib/firmware/ap6212/config.txt
|
2021-10-12 17:04:33 -05:00
|
|
|
cd "${repo_dir}/"
|
2017-09-20 13:23:36 -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
|
2021-09-19 10:56:45 +01:00
|
|
|
status "building external modules"
|
2020-07-21 00:44:37 -05:00
|
|
|
kernver=$(ls ${work_dir}/lib/modules/)
|
2021-09-17 16:02:12 +01:00
|
|
|
cd ${work_dir}/lib/modules/${kernver}/
|
2017-09-20 13:23:36 -05:00
|
|
|
rm build
|
|
|
|
|
rm source
|
|
|
|
|
ln -s /usr/src/kernel build
|
|
|
|
|
ln -s /usr/src/kernel source
|
2021-10-12 17:04:33 -05:00
|
|
|
cd "${repo_dir}/"
|
2020-07-21 00:44:37 -05:00
|
|
|
|
2021-09-16 06:58:38 +01:00
|
|
|
# Calculate the space to create the image and create
|
2021-08-30 15:10:20 -05:00
|
|
|
make_image
|
2018-07-16 18:58:19 -05:00
|
|
|
|
2021-09-17 16:02:12 +01:00
|
|
|
# Create the disk partitions
|
2021-09-19 10:56:45 +01:00
|
|
|
status "Create the disk partitions"
|
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 ext3 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:10:20 -05:00
|
|
|
bootp="${loopdevice}p1"
|
|
|
|
|
rootp="${loopdevice}p2"
|
2018-07-06 18:03:37 -05:00
|
|
|
|
|
|
|
|
# Create file systems
|
2021-11-06 14:00:40 +01:00
|
|
|
mkfs_partitions
|
2021-11-04 15:35:07 +01:00
|
|
|
# Make fstab.
|
|
|
|
|
make_fstab
|
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"
|
2021-09-19 10:11:39 +01:00
|
|
|
mkdir -p "${base_dir}"/root/
|
|
|
|
|
mount "${rootp}" "${base_dir}"/root
|
|
|
|
|
mkdir -p "${base_dir}"/root/boot
|
|
|
|
|
mount "${bootp}" "${base_dir}"/root/boot
|
2021-08-30 15:10:20 -05:00
|
|
|
|
2021-09-19 10:56:45 +01:00
|
|
|
status "Rsyncing rootfs into image file"
|
2021-09-19 10:11:39 +01:00
|
|
|
rsync -HPavz -q "${work_dir}"/ "${base_dir}"/root/
|
2018-07-06 18:03:37 -05:00
|
|
|
sync
|
2017-09-20 13:23:36 -05:00
|
|
|
|
2021-09-16 06:58:38 +01:00
|
|
|
# Samsung bootloaders must be signed
|
2017-09-20 13:23:36 -05:00
|
|
|
# These are the same steps that are done by
|
|
|
|
|
# https://github.com/friendlyarm/sd-fuse_nanopi2/blob/master/fusing.sh
|
2021-09-19 10:56:45 +01:00
|
|
|
status "Samsung bootloaders"
|
2021-09-19 10:11:39 +01:00
|
|
|
mkdir -p "${base_dir}"/bootloader/
|
|
|
|
|
cd "${base_dir}"/bootloader/
|
|
|
|
|
wget 'https://github.com/friendlyarm/sd-fuse_s5p6818/blob/master/prebuilt/bl1-mmcboot.bin?raw=true' -O "${base_dir}"/bootloader/bl1-mmcboot.bin
|
|
|
|
|
wget 'https://github.com/friendlyarm/sd-fuse_s5p6818/blob/master/prebuilt/fip-loader.img?raw=true' -O "${base_dir}"/bootloader/fip-loader.img
|
|
|
|
|
wget 'https://github.com/friendlyarm/sd-fuse_s5p6818/blob/master/prebuilt/fip-secure.img?raw=true' -O "${base_dir}"/bootloader/fip-secure.img
|
|
|
|
|
wget 'https://github.com/friendlyarm/sd-fuse_s5p6818/blob/master/prebuilt/fip-nonsecure.img?raw=true' -O "${base_dir}"/bootloader/fip-nonsecure.img
|
|
|
|
|
wget 'https://github.com/friendlyarm/sd-fuse_s5p6818/blob/master/tools/fw_printenv?raw=true' -O "${base_dir}"/bootloader/fw_printenv
|
|
|
|
|
chmod 0755 "${base_dir}"/bootloader/fw_printenv
|
|
|
|
|
ln -s "${base_dir}"/bootloader/fw_printenv "${base_dir}"/bootloader/fw_setenv
|
|
|
|
|
|
|
|
|
|
dd if="${base_dir}"/bootloader/bl1-mmcboot.bin of=${loopdevice} bs=512 seek=1
|
|
|
|
|
dd if="${base_dir}"/bootloader/fip-loader.img of=${loopdevice} bs=512 seek=129
|
|
|
|
|
dd if="${base_dir}"/bootloader/fip-secure.img of=${loopdevice} bs=512 seek=769
|
|
|
|
|
dd if="${base_dir}"/bootloader/fip-nonsecure.img of=${loopdevice} bs=512 seek=3841
|
|
|
|
|
|
|
|
|
|
cat << EOF > "${base_dir}"/bootloader/env.conf
|
2018-07-16 23:16:45 -05:00
|
|
|
# U-Boot environment for Debian, Ubuntu
|
|
|
|
|
#
|
2021-09-16 06:58:38 +01:00
|
|
|
# Copyright (C) Guangzhou FriendlyARM Computer Tech. Co., Ltd
|
2018-07-16 23:16:45 -05:00
|
|
|
# (http://www.friendlyarm.com)
|
|
|
|
|
#
|
|
|
|
|
|
2020-07-26 17:40:50 -05:00
|
|
|
bootargs console=ttySAC0,115200n8 root=/dev/mmcblk0p2 rootfstype=$fstype rootwait rw consoleblank=0 net.ifnames=0
|
2018-07-16 23:16:45 -05:00
|
|
|
bootdelay 1
|
|
|
|
|
EOF
|
|
|
|
|
|
2021-09-05 19:38:44 -05:00
|
|
|
./fw_setenv ${loopdevice} -s env.conf
|
2018-07-16 23:16:45 -05:00
|
|
|
sync
|
|
|
|
|
|
2021-10-13 13:58:07 -05:00
|
|
|
cd "${repo_dir}/"
|
|
|
|
|
|
2018-06-25 19:07:00 -05:00
|
|
|
# It should be possible to build your own u-boot, as part of this, if you
|
2021-09-16 06:58:38 +01:00
|
|
|
# prefer, it will only generate the fip-nonsecure.img however
|
2018-06-25 19:07:00 -05:00
|
|
|
#git clone https://github.com/friendlyarm/u-boot -b nanopi2-v2016.01
|
|
|
|
|
#cd u-boot
|
|
|
|
|
#make CROSS_COMPILE=aarch64-linux-gnu- s5p6818_nanopi3_defconfig
|
|
|
|
|
#make CROSS_COMPILE=aarch64-linux-gnu-
|
|
|
|
|
#dd if=fip-nonsecure.img of=$loopdevice bs=512 seek=3841
|
2017-09-20 13:23:36 -05:00
|
|
|
|
2021-10-12 20:56:41 +00:00
|
|
|
# Load default finish_image configs
|
|
|
|
|
include finish_image
|