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 CuBox (32-bit) - Original Marvell based NOT Freescale based
|
|
|
|
|
# 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/cubox/
|
|
|
|
|
#
|
2013-10-29 16:45:51 +02:00
|
|
|
|
2021-11-05 19:38:24 +01:00
|
|
|
# Hardware model
|
|
|
|
|
hw_model=${hw_model:-"cubox"}
|
|
|
|
|
# Architecture (arm64, armhf, armel)
|
2020-07-22 12:07:20 -05:00
|
|
|
architecture=${architecture:-"armhf"}
|
2021-11-05 19:38:24 +01:00
|
|
|
# Desktop manager (xfce, gnome, i3, kde, lxde, mate, e17 or none)
|
|
|
|
|
desktop=${desktop:-"xfce"}
|
2013-10-29 16:45:51 +02:00
|
|
|
|
2021-11-05 19:38:24 +01:00
|
|
|
# Load default base_image configs
|
|
|
|
|
source ./common.d/base_image.sh
|
2019-04-29 23:30:19 -05:00
|
|
|
|
2021-11-05 19:38:24 +01:00
|
|
|
# Network configs
|
|
|
|
|
add_interface eth0
|
2013-10-29 16:45:51 +02:00
|
|
|
|
2020-07-22 12:07:20 -05:00
|
|
|
# Run third stage
|
2021-11-05 19:38:24 +01:00
|
|
|
include third_stage
|
2020-08-02 00:14:21 -05:00
|
|
|
|
2020-07-22 12:07:20 -05:00
|
|
|
# Clean system
|
2021-11-05 19:38:24 +01:00
|
|
|
include clean_system
|
2021-09-16 06:58:38 +01:00
|
|
|
# We need an older cross compiler due to 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-08-06 17:49:07 -05:00
|
|
|
|
2014-03-26 02:36:32 -04: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 12:07:20 -05:00
|
|
|
git clone --depth 1 https://github.com/rabeeh/linux.git ${work_dir}/usr/src/kernel
|
|
|
|
|
cd ${work_dir}/usr/src/kernel
|
|
|
|
|
git rev-parse HEAD > ${work_dir}/usr/src/kernel-at-commit
|
2021-10-12 17:04:33 -05:00
|
|
|
patch -p1 --no-backup-if-mismatch < ${repo_dir}/patches/mac80211.patch
|
|
|
|
|
patch -p1 --no-backup-if-mismatch < ${repo_dir}/patches/remove-defined-from-timeconst.patch
|
2013-10-29 16:45:51 +02:00
|
|
|
touch .scmversion
|
|
|
|
|
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-
|
2013-10-29 16:45:51 +02:00
|
|
|
make cubox_defconfig
|
2020-07-22 12:07:20 -05:00
|
|
|
cp .config ${work_dir}/usr/src/cubox.config
|
2013-10-29 16:45:51 +02:00
|
|
|
make -j $(grep -c processor /proc/cpuinfo) uImage modules
|
2020-07-22 12:07:20 -05:00
|
|
|
make modules_install INSTALL_MOD_PATH=${work_dir}
|
|
|
|
|
cp arch/arm/boot/uImage ${work_dir}/boot
|
2015-08-10 22:29:44 -05:00
|
|
|
make mrproper
|
|
|
|
|
cp ../cubox.config .config
|
2021-09-19 10:11:39 +01:00
|
|
|
cd "${base_dir}"
|
2013-10-29 16:45:51 +02:00
|
|
|
|
2017-09-20 16:50:37 -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 12:07:20 -05:00
|
|
|
kernver=$(ls ${work_dir}/lib/modules/)
|
|
|
|
|
cd ${work_dir}/lib/modules/${kernver}
|
2017-09-20 16:50:37 -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 16:50:37 -05:00
|
|
|
|
2013-10-29 16:45:51 +02:00
|
|
|
# Create boot.txt file
|
2020-07-22 12:07:20 -05:00
|
|
|
cat << EOF > ${work_dir}/boot/boot.txt
|
2013-10-29 16:45:51 +02:00
|
|
|
echo "== Executing \${directory}\${bootscript} on \${device_name} partition \${partition} =="
|
|
|
|
|
|
|
|
|
|
setenv unit_no 0
|
|
|
|
|
setenv root_device ?
|
|
|
|
|
|
|
|
|
|
if itest.s \${device_name} -eq usb; then
|
2020-05-07 15:19:48 -05:00
|
|
|
itest.s \$root_device -eq ? && ext3ls usb 0:1 /dev && setenv root_device /dev/sda1 && setenv unit_no 0
|
|
|
|
|
itest.s \$root_device -eq ? && ext3ls usb 1:1 /dev && setenv root_device /dev/sda1 && setenv unit_no 1
|
2013-10-29 16:45:51 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if itest.s \${device_name} -eq mmc; then
|
2020-05-07 15:19:48 -05:00
|
|
|
itest.s \$root_device -eq ? && ext3ls mmc 0:2 /dev && setenv root_device /dev/mmcblk0p2
|
|
|
|
|
itest.s \$root_device -eq ? && ext3ls mmc 0:1 /dev && setenv root_device /dev/mmcblk0p1
|
2013-10-29 16:45:51 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if itest.s \${device_name} -eq ide; then
|
2020-05-07 15:19:48 -05:00
|
|
|
itest.s \$root_device -eq ? && ext3ls ide 0:1 /dev && setenv root_device /dev/sda1
|
2013-10-29 16:45:51 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if itest.s \$root_device -ne ?; then
|
2020-07-26 17:40:50 -05:00
|
|
|
setenv bootargs "console=ttyS0,115200n8 vmalloc=448M video=dovefb:lcd0:1920x1080-32@60-edid clcd.lcd0_enable=1 clcd.lcd1_enable=0 root=\${root_device} rootfstype=$fstype rw net.ifnames=0"
|
2018-12-29 19:20:05 -06:00
|
|
|
setenv loadimage "\${fstype}load \${device_name} \${unit_no}:\${partition} 0x00200000 \${directory}\${image_name}"
|
2013-10-29 16:45:51 +02:00
|
|
|
\$loadimage && bootm 0x00200000
|
2016-03-18 00:22:30 -05:00
|
|
|
|
2013-10-29 16:45:51 +02:00
|
|
|
echo "!! Unable to load \${directory}\${image_name} from \${device_name} \${unit_no}:\${partition} !!"
|
|
|
|
|
exit
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "!! Unable to locate root partition on \${device_name} !!"
|
|
|
|
|
EOF
|
|
|
|
|
|
2014-03-26 02:36:32 -04:00
|
|
|
# Create u-boot boot script image
|
2020-07-22 12:07:20 -05:00
|
|
|
mkimage -A arm -T script -C none -d ${work_dir}/boot/boot.txt ${work_dir}/boot/boot.scr
|
2013-10-29 16:45:51 +02:00
|
|
|
|
2021-09-19 10:11:39 +01:00
|
|
|
cd "${base_dir}"
|
2018-07-06 18:03:37 -05:00
|
|
|
|
2021-11-05 19:38:24 +01:00
|
|
|
# Calculate the space to create the image and create
|
|
|
|
|
make_image
|
2013-10-29 16:45:51 +02:00
|
|
|
|
2020-07-22 12:07:20 -05:00
|
|
|
# Create the disk and partition it
|
2021-09-19 13:45:29 +01:00
|
|
|
parted -s "${image_dir}/${image_name}.img" mklabel msdos
|
|
|
|
|
parted -s -a minimal "${image_dir}/${image_name}.img" mkpart primary $fstype 1MiB 100%
|
2015-08-10 22:29:44 -05:00
|
|
|
|
2018-07-06 18:03:37 -05:00
|
|
|
# Set the partition variables
|
2021-11-05 19:38:24 +01:00
|
|
|
loopdevice=$(losetup --show -fP "${image_dir}/${image_name}.img")
|
|
|
|
|
rootp="${loopdevice}p1"
|
2018-07-06 18:03:37 -05:00
|
|
|
|
2021-11-05 19:38:24 +01:00
|
|
|
# Create file systems
|
|
|
|
|
status "Formatting partitions"
|
|
|
|
|
if [[ "$fstype" == "ext4" ]]; then
|
|
|
|
|
features="^64bit,^metadata_csum"
|
|
|
|
|
elif [[ "$fstype" == "ext3" ]]; then
|
|
|
|
|
features="^64bit"
|
2020-07-26 14:38:21 -05:00
|
|
|
fi
|
2021-11-05 19:38:24 +01:00
|
|
|
mkfs -U "$root_uuid" -O "$features" -t "$fstype" -L ROOTFS "${rootp}"
|
2018-07-06 18:03:37 -05:00
|
|
|
|
2021-11-05 19:38:24 +01:00
|
|
|
# Make fstab.
|
|
|
|
|
make_fstab
|
2018-07-06 18:03:37 -05:00
|
|
|
|
2021-11-05 19:38:24 +01: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
|
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 16:50:37 -05:00
|
|
|
|
2021-11-05 19:38:24 +01:00
|
|
|
# Load default finish_image configs
|
|
|
|
|
include finish_image
|