Files
arm-kali/nanopi2.sh

210 lines
8.8 KiB
Bash
Raw Normal View History

2021-09-16 06:42:05 +01:00
#!/usr/bin/env bash
#
2021-09-27 10:51:02 +01:00
# Kali Linux ARM build-script for NanoPi2 (32-bit)
# Source: https://gitlab.com/kalilinux/build-scripts/kali-arm
2021-09-16 06:42:05 +01:00
#
# This is a community script - you will need to generate your own image to use
# More information: https://www.kali.org/docs/arm/nanopi2/
#
2016-01-30 14:18:34 -06:00
# Hardware model
hw_model=${hw_model:-"nanopi2"}
2022-08-22 22:59:39 +03:00
2021-11-07 09:58:04 +01:00
# Architecture
architecture=${architecture:-"armhf"}
2022-08-22 22:59:39 +03:00
# Desktop manager (xfce, gnome, i3, kde, lxde, mate, e17 or none)
desktop=${desktop:-"xfce"}
2021-11-05 19:20:07 +01:00
# Load default base_image configs
source ./common.d/base_image.sh
# Network configs
2021-11-06 15:45:57 +01:00
basic_network
add_interface eth0
2016-01-30 14:18:34 -06:00
2020-07-22 13:52:33 -05:00
# Third stage
2022-08-22 22:59:39 +03:00
cat <<EOF >>"${work_dir}"/third-stage
2021-09-22 16:37:07 +02:00
status_stage3 'Enable login over serial'
2020-07-22 13:52:33 -05:00
echo "T0:23:respawn:/sbin/agetty -L ttyAMA0 115200 vt100" >> /etc/inittab
2016-01-30 14:18:34 -06:00
EOF
2020-07-22 13:52:33 -05:00
# Run third stage
2021-11-05 19:20:07 +01:00
include third_stage
2016-01-30 14:18:34 -06:00
2020-07-22 13:52:33 -05:00
# Clean system
include clean_system
2016-01-30 14:18:34 -06:00
2021-11-05 19:20:07 +01:00
# Calculate the space to create the image and create
make_image
2016-01-30 14:18:34 -06:00
2021-09-16 06:58:38 +01:00
# We need an older gcc because of kernel age
cd "${base_dir}"
git clone --depth 1 https://gitlab.com/kalilinux/packages/gcc-arm-linux-gnueabihf-4-7.git gcc-arm-linux-gnueabihf-4.7
2016-01-30 14:18:34 -06: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
2020-07-22 13:52:33 -05:00
git clone --depth 1 https://github.com/friendlyarm/linux-3.4.y -b nanopi2-lollipop-mr1 ${work_dir}/usr/src/kernel
cd ${work_dir}/usr/src/kernel
2022-08-22 22:59:39 +03:00
git rev-parse HEAD >${work_dir}/usr/src/kernel-at-commit
2016-01-30 14:18:34 -06:00
touch .scmversion
export ARCH=arm
export CROSS_COMPILE="${base_dir}"/gcc-arm-linux-gnueabihf-4.7/bin/arm-linux-gnueabihf-
2022-08-22 22:59:39 +03:00
patch -p1 --no-backup-if-mismatch <${repo_dir}/patches/mac80211.patch
# Ugh, this patch is needed because the ethernet driver uses parts of netdev
# from a newer kernel?
2022-08-22 22:59:39 +03:00
patch -p1 --no-backup-if-mismatch <${repo_dir}/patches/0001-Remove-define.patch
cp ${repo_dir}/kernel-configs/nanopi2* ${work_dir}/usr/src/
cp ../nanopi2-vendor.config .config
2016-01-30 14:18:34 -06:00
make -j $(grep -c processor /proc/cpuinfo)
make uImage
2020-07-22 13:52:33 -05:00
make modules_install INSTALL_MOD_PATH=${work_dir}
2022-08-22 22:59:39 +03:00
2021-09-16 06:58:38 +01:00
# We copy this twice because you can't do symlinks on fat partitions
# Also, the uImage known as uImage.hdmi is used by uboot if hdmi output is
2021-09-16 06:58:38 +01:00
# detected
2020-07-22 13:52:33 -05:00
cp arch/arm/boot/uImage ${work_dir}/boot/uImage-720p
cp arch/arm/boot/uImage ${work_dir}/boot/uImage.hdmi
2022-08-22 22:59:39 +03:00
2021-09-16 06:58:38 +01:00
# Friendlyarm suggests staying at 720p for now
#cp ../nanopi2-1080p.config .config
#make -j $(grep -c processor /proc/cpuinfo)
#make uImage
2020-07-22 13:52:33 -05:00
#cp arch/arm/boot/uImage ${work_dir}/boot/uImage-1080p
#cp ../nanopi2-lcd-hd101.config .config
#make -j $(grep -c processor /proc/cpuinfo)
#make uImage
2020-07-22 13:52:33 -05:00
#cp arch/arm/boot/uImage ${work_dir}/boot/uImage-hd101
#cp ../nanopi2-lcd-hd700.config .config
#make -j $(grep -c processor /proc/cpuinfo)
#make uImage
2020-07-22 13:52:33 -05:00
#cp arch/arm/boot/uImage ${work_dir}/boot/uImage-hd700
#cp ../nanopi2-lcd.config .config
#make -j $(grep -c processor /proc/cpuinfo)
#make uImage
# The default uImage is for lcd usage, so we copy the lcd one twice
2021-09-16 06:58:38 +01:00
# so people have a backup in case they overwrite uImage for some reason
2020-07-22 13:52:33 -05:00
#cp arch/arm/boot/uImage ${work_dir}/boot/uImage-s70
#cp arch/arm/boot/uImage ${work_dir}/boot/uImage.lcd
#cp arch/arm/boot/uImage ${work_dir}/boot/uImage
cd "${base_dir}"
2016-01-30 14:18:34 -06:00
# FriendlyARM suggest using backports for wifi with their devices, and the
2021-09-16 06:58:38 +01:00
# recommended version is the 4.4.2
2020-07-22 13:52:33 -05:00
cd ${work_dir}/usr/src/
#wget https://www.kernel.org/pub/linux/kernel/projects/backports/stable/v4.4.2/backports-4.4.2-1.tar.xz
#tar -xf backports-4.4.2-1.tar.xz
git clone https://github.com/friendlyarm/wireless
cd wireless
cd backports-4.4.2-1
2022-08-22 22:59:39 +03:00
patch -p1 --no-backup-if-mismatch <${repo_dir}/patches/kali-wifi-injection-4.4.patch
cd ..
#cp ${repo_dir}/kernel-configs/backports.config .config
2020-07-22 13:52:33 -05:00
#make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j $(grep -c processor /proc/cpuinfo) KLIB_BUILD=${work_dir}/usr/src/kernel KLIB=${work_dir}
#make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- KLIB_BUILD=${work_dir}/usr/src/kernel KLIB=${work_dir} INSTALL_MOD_PATH=${work_dir} install
#make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- KLIB_BUILD=${work_dir}/usr/src/kernel KLIB=${work_dir} mrproper
#cp ${repo_dir}/kernel-configs/backports.config .config
XCROSS="${base_dir}"/gcc-arm-linux-gnueabihf-4.7/bin/arm-linux-gnueabihf- ANDROID=n ./build.sh -k ${work_dir}/usr/src/kernel -c nanopi2 -o ${work_dir}
cd "${base_dir}"
# Now we clean up the kernel build
2020-07-22 13:52:33 -05:00
cd ${work_dir}/usr/src/kernel
make mrproper
cd "${base_dir}"
2021-09-16 06:58:38 +01:00
# Copy over the firmware for the nanopi2/3 wifi
# 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
2020-07-22 13:52:33 -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
cd "${base_dir}"
2016-01-30 14:18:34 -06:00
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
2020-07-22 13:52:33 -05:00
kernver=$(ls ${work_dir}/lib/modules/)
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
cd "${base_dir}"
2017-09-20 13:23:36 -05:00
# Calculate the space to create the image and create
make_image
# Create the disk partitions
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 ext2 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-11-07 10:55:31 +01:00
make_loop
2022-08-22 22:59:39 +03:00
2018-07-06 18:03:37 -05:00
# Create file systems
2021-11-06 14:00:40 +01:00
mkfs_partitions
2022-08-22 22:59:39 +03:00
2021-11-04 16:58:08 +01:00
# Make fstab.
make_fstab
2018-07-06 18:03:37 -05:00
# Create the dirs for the partitions and mount them
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
echo "Rsyncing rootfs into image file"
rsync -HPavz -q ${work_dir}/ ${base_dir}/root/
2017-09-20 13:23:36 -05:00
2021-09-16 06:58:38 +01:00
# Samsung bootloaders must be signed
2016-01-30 14:18:34 -06:00
# These are the same steps that are done by
# https://github.com/friendlyarm/sd-fuse_nanopi2/blob/master/fusing.sh
2018-06-23 19:42:37 -05:00
2021-09-16 06:58:38 +01:00
# Download the latest prebuilt from the above url
mkdir -p "${base_dir}"/bootloader
cd "${base_dir}"/bootloader
wget 'https://github.com/friendlyarm/sd-fuse_nanopi2/blob/96e1ba9603d237d0169485801764c5ce9591bf5e/prebuilt/2ndboot.bin?raw=true' -O 2ndboot.bin
wget 'https://github.com/friendlyarm/sd-fuse_nanopi2/blob/96e1ba9603d237d0169485801764c5ce9591bf5e/prebuilt/boot.TBI?raw=true' -O boot.TBI
wget 'https://github.com/friendlyarm/sd-fuse_nanopi2/blob/96e1ba9603d237d0169485801764c5ce9591bf5e/prebuilt/bootloader' -O bootloader
#wget https://raw.githubusercontent.com/friendlyarm/sd-fuse_nanopi2/master/prebuilt/bl1-mmcboot.bin
#wget https://raw.githubusercontent.com/friendlyarm/sd-fuse_nanopi2/master/prebuilt/bl_mon.img
#wget https://raw.githubusercontent.com/friendlyarm/sd-fuse_nanopi2/master/prebuilt/bootloader.img # This is u-boot
#wget https://raw.githubusercontent.com/friendlyarm/sd-fuse_nanopi2/master/prebuilt/loader-mmc.img
wget https://raw.githubusercontent.com/friendlyarm/sd-fuse_nanopi2/master/tools/fw_printenv
2021-09-17 10:42:05 +01:00
chmod 0755 fw_printenv
ln -s fw_printenv fw_setenv
2018-06-23 19:42:37 -05:00
dd if=2ndboot.bin of=${loopdevice} bs=512 seek=1
dd if=boot.TBI of=${loopdevice} bs=512 seek=64 count=1
dd if=bootloader of=${loopdevice} bs=512 seek=65
2018-06-23 19:42:37 -05:00
2022-08-22 22:59:39 +03:00
cat <<EOF >${base_dir}/bootloader/env.conf
# U-Boot environment for Debian, Ubuntu
#
2021-09-16 06:58:38 +01:00
# Copyright (C) Guangzhou FriendlyARM Computer Tech. Co., Ltd
# (http://www.friendlyarm.com)
#
bootargs console=ttyAMA0,115200n8 root=/dev/mmcblk0p2 rootfstype=$fstype rootwait rw consoleblank=0 net.ifnames=0
bootdelay 1
EOF
./fw_setenv ${loopdevice} -s env.conf
2016-01-30 14:18:34 -06:00
sync
cd "${repo_dir}/"
2016-01-30 14:18:34 -06:00
2021-11-05 19:20:07 +01:00
# Load default finish_image configs
include finish_image