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
|
|
|
|
2021-09-16 06:42:05 +01:00
|
|
|
# Stop on error
|
|
|
|
|
set -e
|
2016-01-30 14:18:34 -06:00
|
|
|
|
2020-07-22 13:52:33 -05:00
|
|
|
# Uncomment to activate debug
|
|
|
|
|
# debug=true
|
2018-06-22 18:44:57 -05:00
|
|
|
|
2021-09-20 01:18:48 +02:00
|
|
|
# shellcheck disable=SC2154
|
|
|
|
|
# Load general functions
|
|
|
|
|
# shellcheck source=/dev/null
|
|
|
|
|
source ./common.d/functions.sh
|
2016-01-30 14:18:34 -06:00
|
|
|
|
2020-08-02 00:14:21 -05:00
|
|
|
|
|
|
|
|
|
2021-09-20 01:18:48 +02:00
|
|
|
# Hardware model
|
|
|
|
|
hw_model=${hw_model:-"nanopi2"}
|
|
|
|
|
# Architecture
|
|
|
|
|
architecture=${architecture:-"armhf"}
|
|
|
|
|
# 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
|
|
|
|
|
# Checks script environment
|
|
|
|
|
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-22 13:52:33 -05:00
|
|
|
# debootstrap second stage
|
2020-08-02 00:14:21 -05:00
|
|
|
systemd-nspawn_exec eatmydata /debootstrap/debootstrap --second-stage
|
2021-09-20 01:18:48 +02:00
|
|
|
# Define sources.list
|
|
|
|
|
include sources.list
|
|
|
|
|
# APT options
|
|
|
|
|
include apt_options
|
2020-07-22 13:52:33 -05:00
|
|
|
# So X doesn't complain, we add kali to hosts
|
2021-09-20 01:18:48 +02:00
|
|
|
include hosts
|
|
|
|
|
# Set hostname
|
|
|
|
|
set_hostname "${hostname}"
|
|
|
|
|
# Network configs
|
|
|
|
|
include network
|
|
|
|
|
add_interface eth0
|
2016-01-30 14:18:34 -06:00
|
|
|
|
2021-09-16 06:58:38 +01:00
|
|
|
# Copy directory bsp into build dir
|
2021-09-20 01:18:48 +02:00
|
|
|
status "Copy directory bsp into build dir"
|
|
|
|
|
cp -rp bsp "${work_dir}"
|
2020-07-22 13:52:33 -05:00
|
|
|
|
2021-09-20 01:18:48 +02:00
|
|
|
# Disable RESUME (suspend/resume is currently broken anyway!) which speeds up boot massively
|
|
|
|
|
mkdir -p ${work_dir}/etc/initramfs-tools/conf.d/
|
|
|
|
|
cat << EOF > ${work_dir}/etc/initramfs-tools/conf.d/resume
|
|
|
|
|
RESUME=none
|
|
|
|
|
EOF
|
2016-01-30 14:18:34 -06:00
|
|
|
|
2018-07-17 17:18:17 -05:00
|
|
|
|
2020-07-22 13:52:33 -05:00
|
|
|
# Third stage
|
2021-09-22 16:37:07 +02:00
|
|
|
cat <<EOF > "${work_dir}"/third-stage
|
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
set -e
|
|
|
|
|
status_3i=0
|
|
|
|
|
status_3t=\$(grep '^status_stage3 ' \$0 | wc -l)
|
2016-01-30 14:18:34 -06:00
|
|
|
|
2021-09-22 16:37:07 +02:00
|
|
|
status_stage3() {
|
|
|
|
|
status_3i=\$((status_3i+1))
|
|
|
|
|
echo " [i] Stage 3 (\${status_3i}/\${status_3t}): \$1"
|
|
|
|
|
}
|
2016-01-30 14:18:34 -06:00
|
|
|
|
2021-09-22 16:37:07 +02:00
|
|
|
status_stage3 'Update apt'
|
|
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
|
|
|
eatmydata apt-get update
|
2020-05-07 15:17:10 -05:00
|
|
|
|
2021-09-22 16:37:07 +02:00
|
|
|
status_stage3 'Install core packages'
|
|
|
|
|
eatmydata apt-get -y install ${third_stage_pkgs}
|
2020-05-07 15:17:10 -05:00
|
|
|
|
2021-09-22 16:37:07 +02:00
|
|
|
status_stage3 'Install packages'
|
|
|
|
|
eatmydata apt-get install -y ${packages} || eatmydata apt-get install -y --fix-broken
|
2020-05-07 15:17:10 -05:00
|
|
|
|
2021-09-22 16:37:07 +02:00
|
|
|
status_stage3 'Install desktop packages'
|
|
|
|
|
eatmydata apt-get install -y ${desktop_pkgs} ${extra} || eatmydata apt-get install -y --fix-broken
|
2020-07-22 13:52:33 -05:00
|
|
|
|
2021-09-22 17:47:15 +02:00
|
|
|
status_stage3 'ntp does not always sync the date, but systemd-timesyncd does, so we remove ntp and reinstall it with this'
|
2021-09-22 16:37:07 +02:00
|
|
|
eatmydata apt-get install -y systemd-timesyncd --autoremove
|
2016-01-30 14:18:34 -06:00
|
|
|
|
2021-09-22 16:37:07 +02:00
|
|
|
status_stage3 'Clean up'
|
|
|
|
|
eatmydata apt-get -y --purge autoremove
|
2016-01-30 14:18:34 -06:00
|
|
|
|
2021-09-22 16:37:07 +02:00
|
|
|
status_stage3 'Linux console/keyboard configuration'
|
2020-07-22 13:52:33 -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-22 16:37:07 +02:00
|
|
|
status_stage3 'Copy all services'
|
2020-07-22 13:52:33 -05:00
|
|
|
cp -p /bsp/services/all/*.service /etc/systemd/system/
|
2018-07-17 17:18:17 -05:00
|
|
|
|
2019-02-12 17:56:53 -06:00
|
|
|
# Regenerated the shared-mime-info database on the first boot
|
2021-09-16 06:58:38 +01:00
|
|
|
# since it fails to do so properly in a chroot
|
2019-02-12 17:56:53 -06:00
|
|
|
systemctl enable smi-hack
|
2018-07-17 17:18:17 -05:00
|
|
|
|
2021-09-22 16:37:07 +02:00
|
|
|
|
|
|
|
|
status_stage3 'Generate SSH host keys on first run'
|
2018-07-17 17:18:17 -05:00
|
|
|
systemctl enable regenerate_ssh_host_keys
|
2021-09-25 13:58:34 +02:00
|
|
|
status_stage3 'Enable sshd'
|
2018-07-17 17:18:17 -05:00
|
|
|
systemctl enable ssh
|
2016-01-30 14:18:34 -06:00
|
|
|
|
2021-09-22 16:37:07 +02:00
|
|
|
status_stage3 'Allow users to use NetworkManager over ssh'
|
2020-08-08 20:38:29 -05:00
|
|
|
install -m644 /bsp/polkit/10-NetworkManager.pkla /var/lib/polkit-1/localauthority/50-local.d
|
|
|
|
|
|
2021-09-22 16:37:07 +02:00
|
|
|
status_stage3 'Install ca-certificate'
|
2019-05-10 17:18:34 -05:00
|
|
|
cd /root
|
2020-07-22 13:52:33 -05:00
|
|
|
apt download -o APT::Sandbox::User=root ca-certificates 2>/dev/null
|
2019-05-10 17:18:34 -05:00
|
|
|
|
2021-09-22 16:37:07 +02:00
|
|
|
status_stage3 'Set a REGDOMAIN'
|
2020-07-22 13:52:33 -05:00
|
|
|
sed -i -e 's/REGDOM.*/REGDOMAIN=00/g' /etc/default/crda
|
2016-01-30 14:18:34 -06:00
|
|
|
|
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
|
|
|
|
2021-09-22 16:37:07 +02:00
|
|
|
status_stage3 'Try and make the console a bit nicer. Set the terminus font for a bit nicer display'
|
2020-07-22 13:52:33 -05:00
|
|
|
sed -i -e 's/FONTFACE=.*/FONTFACE="Terminus"/' /etc/default/console-setup
|
|
|
|
|
sed -i -e 's/FONTSIZE=.*/FONTSIZE="6x12"/' /etc/default/console-setup
|
|
|
|
|
|
2021-09-22 16:37:07 +02:00
|
|
|
status_stage3 'Fix startup time from 5 minutes to 15 secs on raise interface wlan0'
|
2020-07-22 13:52:33 -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-09-22 16:37:07 +02:00
|
|
|
status_stage3 'Enable runonce'
|
|
|
|
|
install -m755 /bsp/scripts/runonce /usr/sbin/
|
|
|
|
|
cp -rf /bsp/runonce.d /etc
|
|
|
|
|
systemctl enable runonce
|
|
|
|
|
|
|
|
|
|
status_stage3 'Clean up dpkg.eatmydata'
|
2020-08-02 00:14:21 -05:00
|
|
|
rm -f /usr/bin/dpkg
|
2021-09-22 16:37:07 +02:00
|
|
|
dpkg-divert --remove --rename /usr/bin/dpkg
|
2016-01-30 14:18:34 -06:00
|
|
|
EOF
|
|
|
|
|
|
2020-07-22 13:52:33 -05:00
|
|
|
# Run third stage
|
2021-09-20 01:18:48 +02:00
|
|
|
chmod 0755 "${work_dir}"/third-stage
|
|
|
|
|
status "Run third stage"
|
2020-07-22 13:52:33 -05:00
|
|
|
systemd-nspawn_exec /third-stage
|
2016-01-30 14:18:34 -06:00
|
|
|
|
2020-07-22 13:52:33 -05:00
|
|
|
# Clean system
|
2021-09-20 01:18:48 +02:00
|
|
|
include clean_system
|
|
|
|
|
trap clean_build ERR SIGTERM SIGINT
|
2016-01-30 14:18:34 -06:00
|
|
|
|
|
|
|
|
|
2021-09-20 01:18:48 +02:00
|
|
|
# Disable the use of http proxy in case it is enabled.
|
|
|
|
|
disable_proxy
|
2020-08-10 16:55:26 +02:00
|
|
|
# Mirror & suite replacement
|
2021-09-20 01:18:48 +02:00
|
|
|
restore_mirror
|
|
|
|
|
# Reload sources.list
|
|
|
|
|
include sources.list
|
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
|
2021-09-19 10:11:39 +01:00
|
|
|
cd "${base_dir}"
|
2019-04-30 05:27:16 -05:00
|
|
|
git clone --depth 1 https://gitlab.com/kalilinux/packages/gcc-arm-linux-gnueabihf-4-7.git gcc-arm-linux-gnueabihf-4.7
|
2018-07-30 16:02:58 -05:00
|
|
|
|
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
|
|
|
|
|
git rev-parse HEAD > ${work_dir}/usr/src/kernel-at-commit
|
2016-01-30 14:18:34 -06:00
|
|
|
touch .scmversion
|
2018-07-17 02:04:27 -05:00
|
|
|
export ARCH=arm
|
2021-09-19 10:11:39 +01:00
|
|
|
export CROSS_COMPILE="${base_dir}"/gcc-arm-linux-gnueabihf-4.7/bin/arm-linux-gnueabihf-
|
2020-07-22 13:52:33 -05:00
|
|
|
patch -p1 --no-backup-if-mismatch < ${current_dir}/patches/mac80211.patch
|
2018-07-30 16:02:58 -05:00
|
|
|
# Ugh, this patch is needed because the ethernet driver uses parts of netdev
|
|
|
|
|
# from a newer kernel?
|
2020-07-22 13:52:33 -05:00
|
|
|
patch -p1 --no-backup-if-mismatch < ${current_dir}/patches/0001-Remove-define.patch
|
|
|
|
|
cp ${current_dir}/kernel-configs/nanopi2* ${work_dir}/usr/src/
|
2018-07-30 16:02:58 -05:00
|
|
|
cp ../nanopi2-vendor.config .config
|
2016-01-30 14:18:34 -06:00
|
|
|
make -j $(grep -c processor /proc/cpuinfo)
|
2018-07-30 16:02:58 -05:00
|
|
|
make uImage
|
2020-07-22 13:52:33 -05:00
|
|
|
make modules_install INSTALL_MOD_PATH=${work_dir}
|
2021-09-16 06:58:38 +01:00
|
|
|
# We copy this twice because you can't do symlinks on fat partitions
|
2018-07-30 16:02:58 -05:00
|
|
|
# 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
|
2021-09-16 06:58:38 +01:00
|
|
|
# Friendlyarm suggests staying at 720p for now
|
2018-07-30 16:02:58 -05:00
|
|
|
#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
|
2018-07-30 16:02:58 -05:00
|
|
|
#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
|
2018-07-30 16:02:58 -05:00
|
|
|
#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
|
2018-07-30 16:02:58 -05:00
|
|
|
#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
|
2021-09-19 10:11:39 +01:00
|
|
|
cd "${base_dir}"
|
2016-01-30 14:18:34 -06:00
|
|
|
|
2018-07-30 16:02:58 -05: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/
|
2018-07-30 16:02:58 -05:00
|
|
|
#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
|
2020-07-22 13:52:33 -05:00
|
|
|
patch -p1 --no-backup-if-mismatch < ${current_dir}/patches/kali-wifi-injection-4.4.patch
|
2018-07-30 16:02:58 -05:00
|
|
|
cd ..
|
2020-07-22 13:52:33 -05:00
|
|
|
#cp ${current_dir}/kernel-configs/backports.config .config
|
|
|
|
|
#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 ${current_dir}/kernel-configs/backports.config .config
|
2021-09-19 10:11:39 +01:00
|
|
|
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}"
|
2018-07-30 16:02:58 -05:00
|
|
|
|
2018-07-30 17:46:36 -05:00
|
|
|
# Now we clean up the kernel build
|
2020-07-22 13:52:33 -05:00
|
|
|
cd ${work_dir}/usr/src/kernel
|
2018-07-30 17:46:36 -05:00
|
|
|
make mrproper
|
2021-09-19 10:11:39 +01:00
|
|
|
cd "${base_dir}"
|
2018-07-30 17:46:36 -05:00
|
|
|
|
2021-09-16 06:58:38 +01:00
|
|
|
# Copy over the firmware for the nanopi2/3 wifi
|
2018-07-17 01:00:44 -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
|
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
|
2021-09-19 10:11:39 +01:00
|
|
|
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
|
2021-09-19 10:11:39 +01:00
|
|
|
cd "${base_dir}"
|
2017-09-20 13:23:36 -05:00
|
|
|
|
2018-07-17 01:00:44 -05:00
|
|
|
|
2021-09-20 01:18:48 +02: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
|
2021-09-22 18:06:15 +02:00
|
|
|
parted -s "${image_dir}/${image_name}.img" mkpart primary fat32 4MiB "${bootsize}"MiB
|
2021-09-20 01:18:48 +02:00
|
|
|
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 10:11:39 +01:00
|
|
|
loopdevice=`losetup -f --show ${current_dir}/${image_name}.img`
|
2018-07-06 18:03:37 -05:00
|
|
|
device=`kpartx -va ${loopdevice} | sed 's/.*\(loop[0-9]\+\)p.*/\1/g' | head -1`
|
|
|
|
|
sleep 5
|
|
|
|
|
device="/dev/mapper/${device}"
|
|
|
|
|
bootp=${device}p1
|
|
|
|
|
rootp=${device}p2
|
|
|
|
|
|
|
|
|
|
# Create file systems
|
2021-09-20 01:18:48 +02:00
|
|
|
status "Formatting partitions" green
|
2020-07-22 13:52:33 -05:00
|
|
|
mkfs.ext3 -L BOOT ${bootp}
|
2020-07-26 14:38:21 -05:00
|
|
|
if [[ $fstype == ext4 ]]; then
|
|
|
|
|
features="-O ^64bit,^metadata_csum"
|
|
|
|
|
elif [[ $fstype == ext3 ]]; then
|
|
|
|
|
features="-O ^64bit"
|
|
|
|
|
fi
|
|
|
|
|
mkfs $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-20 01:18:48 +02: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
|
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
|
2021-09-18 05:48:20 +01:00
|
|
|
echo "nameserver ${nameserver}" > "${work_dir}"/etc/resolv.conf
|
2016-01-30 14:18:34 -06:00
|
|
|
|
2021-09-16 06:58:38 +01:00
|
|
|
# Create an fstab so that we don't mount / read-only
|
2020-06-25 17:42:35 -05:00
|
|
|
UUID=$(blkid -s UUID -o value ${rootp})
|
2020-07-26 17:40:50 -05:00
|
|
|
echo "UUID=$UUID / $fstype errors=remount-ro 0 1" >> ${work_dir}/etc/fstab
|
2020-06-25 17:42:35 -05:00
|
|
|
|
2018-07-06 18:03:37 -05:00
|
|
|
echo "Rsyncing rootfs into image file"
|
2021-09-19 10:11:39 +01:00
|
|
|
rsync -HPavz -q ${work_dir}/ ${base_dir}/root/
|
2017-09-20 13:23:36 -05:00
|
|
|
|
2016-01-30 14:18:34 -06:00
|
|
|
# Unmount partitions
|
2018-07-06 18:03:37 -05:00
|
|
|
sync
|
|
|
|
|
umount -l ${bootp}
|
|
|
|
|
umount -l ${rootp}
|
2018-07-17 01:00:44 -05:00
|
|
|
kpartx -dv ${loopdevice}
|
2016-01-30 14:18:34 -06: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
|
2021-09-19 10:11:39 +01:00
|
|
|
mkdir -p "${base_dir}"/bootloader
|
|
|
|
|
cd "${base_dir}"/bootloader
|
2018-07-30 19:00:12 -05:00
|
|
|
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
|
2018-07-17 01:00:44 -05:00
|
|
|
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
|
2018-07-17 01:00:44 -05:00
|
|
|
ln -s fw_printenv fw_setenv
|
2018-06-23 19:42:37 -05:00
|
|
|
|
2018-07-30 19:00:12 -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
|
|
|
|
2021-09-19 10:11:39 +01:00
|
|
|
cat << EOF > ${base_dir}/bootloader/env.conf
|
2018-07-17 01:00:44 -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-17 01:00:44 -05:00
|
|
|
# (http://www.friendlyarm.com)
|
|
|
|
|
#
|
|
|
|
|
|
2020-07-26 17:40:50 -05:00
|
|
|
bootargs console=ttyAMA0,115200n8 root=/dev/mmcblk0p2 rootfstype=$fstype rootwait rw consoleblank=0 net.ifnames=0
|
2018-07-17 01:00:44 -05:00
|
|
|
bootdelay 1
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
./fw_setenv ${loopdevice} -s env.conf
|
|
|
|
|
|
2016-01-30 14:18:34 -06:00
|
|
|
sync
|
|
|
|
|
|
2021-09-19 10:11:39 +01:00
|
|
|
cd "${base_dir}"
|
2016-01-30 14:18:34 -06:00
|
|
|
|
2021-09-20 01:18:48 +02:00
|
|
|
# Remove loop devices
|
2018-07-06 18:03:37 -05:00
|
|
|
losetup -d ${loopdevice}
|
2016-01-30 14:18:34 -06:00
|
|
|
|
2018-07-06 18:03:37 -05:00
|
|
|
|
2021-09-20 01:18:48 +02:00
|
|
|
# Compress image compilation
|
|
|
|
|
include compress_img
|
|
|
|
|
|
|
|
|
|
# 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
|