2015-05-12 15:34:30 -05:00
|
|
|
#!/bin/bash
|
2018-07-02 10:50:52 -05:00
|
|
|
set -e
|
2015-05-12 15:34:30 -05:00
|
|
|
|
2020-07-22 11:17:09 -05:00
|
|
|
# Uncomment to activate debug
|
|
|
|
|
# debug=true
|
2018-06-22 18:30:52 -05:00
|
|
|
|
2020-07-22 11:17:09 -05:00
|
|
|
if [ "$debug" = true ]; then
|
|
|
|
|
exec > >(tee -a -i "${0%.*}.log") 2>&1
|
|
|
|
|
set -x
|
2015-05-12 15:34:30 -05:00
|
|
|
fi
|
|
|
|
|
|
2020-07-22 11:17:09 -05:00
|
|
|
# Architecture
|
|
|
|
|
architecture=${architecture:-"armhf"}
|
|
|
|
|
# Generate a random machine name to be used.
|
|
|
|
|
machine=$(tr -cd 'A-Za-z0-9' < /dev/urandom | head -c16 ; echo)
|
2018-06-30 17:03:58 -05:00
|
|
|
# Custom hostname variable
|
2018-07-02 10:50:52 -05:00
|
|
|
hostname=${2:-kali}
|
2018-06-30 17:03:58 -05:00
|
|
|
# Custom image file name variable - MUST NOT include .img at the end.
|
2018-07-30 18:11:33 -05:00
|
|
|
imagename=${3:-kali-linux-$1-nyan}
|
2020-07-22 11:17:09 -05:00
|
|
|
# Suite to use, valid options are:
|
2018-07-06 18:03:37 -05:00
|
|
|
# kali-rolling, kali-dev, kali-bleeding-edge, kali-dev-only, kali-experimental, kali-last-snapshot
|
2020-07-22 11:17:09 -05:00
|
|
|
suite=${suite:-"kali-rolling"}
|
|
|
|
|
# Free space rootfs in MiB
|
|
|
|
|
free_space="300"
|
|
|
|
|
# /boot partition in MiB
|
|
|
|
|
bootsize="128"
|
2020-07-26 14:38:21 -05:00
|
|
|
# Select compression, xz or none
|
|
|
|
|
compress="xz"
|
|
|
|
|
# Choose filesystem format to format ( ext3 or ext4 )
|
|
|
|
|
fstype="ext3"
|
2020-07-22 11:17:09 -05:00
|
|
|
# If you have your own preferred mirrors, set them here.
|
2020-07-26 14:38:21 -05:00
|
|
|
mirror=${4:-"http://http.kali.org/kali"}
|
2020-07-22 11:17:09 -05:00
|
|
|
# Gitlab url Kali repository
|
|
|
|
|
kaligit="https://gitlab.com/kalilinux"
|
|
|
|
|
# Github raw url
|
|
|
|
|
githubraw="https://raw.githubusercontent.com"
|
2018-06-30 17:03:58 -05:00
|
|
|
|
2020-07-22 11:17:09 -05:00
|
|
|
# Check EUID=0 you can run any binary as root.
|
|
|
|
|
if [[ $EUID -ne 0 ]]; then
|
|
|
|
|
echo "This script must be run as root"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Pass version number
|
|
|
|
|
if [[ $# -eq 0 ]] ; then
|
|
|
|
|
echo "Please pass version number, e.g. $0 2.0, and (if you want) a hostname, default is kali"
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Check exist bsp directory.
|
|
|
|
|
if [ ! -e "bsp" ]; then
|
|
|
|
|
echo "Error: missing bsp directory structure"
|
|
|
|
|
echo "Please clone the full repository ${kaligit}/build-scripts/kali-arm"
|
|
|
|
|
exit 255
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Current directory
|
|
|
|
|
current_dir="$(pwd)"
|
|
|
|
|
# Base directory
|
|
|
|
|
basedir=${current_dir}/nyan-"$1"
|
|
|
|
|
# Working directory
|
|
|
|
|
work_dir="${basedir}/kali-${architecture}"
|
|
|
|
|
|
|
|
|
|
# Check directory build
|
|
|
|
|
if [ -e "${basedir}" ]; then
|
|
|
|
|
echo "${basedir} directory exists, will not continue"
|
|
|
|
|
exit 1
|
|
|
|
|
elif [[ ${current_dir} =~ [[:space:]] ]]; then
|
|
|
|
|
echo "The directory "\"${current_dir}"\" contains whitespace. Not supported."
|
|
|
|
|
exit 1
|
|
|
|
|
else
|
|
|
|
|
echo "The basedir thinks it is: ${basedir}"
|
|
|
|
|
mkdir -p ${basedir}
|
2015-05-12 15:34:30 -05:00
|
|
|
fi
|
|
|
|
|
|
2020-07-22 11:17:09 -05:00
|
|
|
components="main,contrib,non-free"
|
2020-04-28 19:35:50 -05:00
|
|
|
arm="kali-linux-arm ntpdate"
|
|
|
|
|
base="apt-transport-https apt-utils bash-completion console-setup dialog e2fsprogs ifupdown initramfs-tools inxi iw man-db mlocate netcat-traditional net-tools parted pciutils psmisc rfkill screen tmux unrar usbutils vim wget whiptail zerofree"
|
2020-06-15 12:03:47 -05:00
|
|
|
desktop="kali-desktop-xfce kali-root-login xserver-xorg-video-fbdev xserver-xorg-input-libinput xserver-xorg-input-synaptics xfonts-terminus xinput"
|
2020-06-17 15:09:54 -05:00
|
|
|
tools="kali-linux-default"
|
2020-04-28 19:35:50 -05:00
|
|
|
services="apache2 atftpd"
|
2020-04-29 19:16:19 -05:00
|
|
|
extras="alsa-utils bc bison bluez bluez-firmware kali-linux-core libnss-systemd libssl-dev triggerhappy"
|
2015-05-12 15:34:30 -05:00
|
|
|
|
2019-06-17 02:00:54 -05:00
|
|
|
packages="${arm} ${base} ${services}"
|
2015-05-12 15:34:30 -05:00
|
|
|
|
2019-01-30 19:20:03 -06:00
|
|
|
kernel_release="R71-11151.B-chromeos-3.10"
|
2017-09-20 16:45:33 -05:00
|
|
|
|
2020-07-22 11:17:09 -05:00
|
|
|
# Automatic configuration to use an http proxy, such as apt-cacher-ng.
|
|
|
|
|
# You can turn off automatic settings by uncommenting apt_cacher=off.
|
|
|
|
|
# apt_cacher=off
|
|
|
|
|
# By default the proxy settings are local, but you can define an external proxy.
|
|
|
|
|
# proxy_url="http://external.intranet.local"
|
|
|
|
|
apt_cacher=${apt_cacher:-"$(lsof -i :3142|cut -d ' ' -f3 | uniq | sed '/^\s*$/d')"}
|
|
|
|
|
if [ -n "$proxy_url" ]; then
|
|
|
|
|
export http_proxy=$proxy_url
|
|
|
|
|
elif [ "$apt_cacher" = "apt-cacher-ng" ] ; then
|
|
|
|
|
if [ -z "$proxy_url" ]; then
|
|
|
|
|
proxy_url=${proxy_url:-"http://127.0.0.1:3142/"}
|
|
|
|
|
export http_proxy=$proxy_url
|
|
|
|
|
fi
|
|
|
|
|
fi
|
2015-05-12 15:34:30 -05:00
|
|
|
|
2018-07-06 18:03:37 -05:00
|
|
|
# create the rootfs - not much to modify here, except maybe throw in some more packages if you want.
|
2020-07-22 11:17:09 -05:00
|
|
|
debootstrap --foreign --keyring=/usr/share/keyrings/kali-archive-keyring.gpg --include=kali-archive-keyring \
|
|
|
|
|
--components=${components} --arch ${architecture} ${suite} ${work_dir} http://http.kali.org/kali
|
2015-05-12 15:34:30 -05:00
|
|
|
|
2020-07-22 11:17:09 -05:00
|
|
|
# systemd-nspawn enviroment
|
|
|
|
|
systemd-nspawn_exec(){
|
|
|
|
|
qemu_bin=/usr/bin/qemu-arm-static
|
|
|
|
|
LANG=C systemd-nspawn -q --bind-ro ${qemu_bin} -M ${machine} -D ${work_dir} "$@"
|
|
|
|
|
}
|
2015-05-12 15:34:30 -05:00
|
|
|
|
2020-07-22 11:17:09 -05:00
|
|
|
# debootstrap second stage
|
|
|
|
|
systemd-nspawn_exec /debootstrap/debootstrap --second-stage
|
2015-05-12 15:34:30 -05:00
|
|
|
|
2020-07-22 11:17:09 -05:00
|
|
|
cat << EOF > ${work_dir}/etc/apt/sources.list
|
|
|
|
|
deb ${mirror} ${suite} ${components//,/ }
|
|
|
|
|
#deb-src ${mirror} ${suite} ${components//,/ }
|
2015-05-12 15:34:30 -05:00
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
# Set hostname
|
2020-07-22 11:17:09 -05:00
|
|
|
echo "${hostname}" > ${work_dir}/etc/hostname
|
2015-05-12 15:34:30 -05:00
|
|
|
|
|
|
|
|
# So X doesn't complain, we add kali to hosts
|
2020-07-22 11:17:09 -05:00
|
|
|
cat << EOF > ${work_dir}/etc/hosts
|
2018-07-02 10:50:52 -05:00
|
|
|
127.0.0.1 ${hostname} localhost
|
2015-05-12 15:34:30 -05:00
|
|
|
::1 localhost ip6-localhost ip6-loopback
|
|
|
|
|
fe00::0 ip6-localnet
|
|
|
|
|
ff00::0 ip6-mcastprefix
|
|
|
|
|
ff02::1 ip6-allnodes
|
|
|
|
|
ff02::2 ip6-allrouters
|
|
|
|
|
EOF
|
|
|
|
|
|
2020-07-22 11:17:09 -05:00
|
|
|
# Disable IPv6
|
|
|
|
|
cat << EOF > ${work_dir}/etc/modprobe.d/ipv6.conf
|
|
|
|
|
# Don't load ipv6 by default
|
|
|
|
|
alias net-pf-10 off
|
2015-05-12 15:34:30 -05:00
|
|
|
EOF
|
|
|
|
|
|
2020-07-22 11:17:09 -05:00
|
|
|
cat << EOF > ${work_dir}/etc/network/interfaces
|
|
|
|
|
auto lo
|
|
|
|
|
iface lo inet loopback
|
2015-05-12 15:34:30 -05:00
|
|
|
EOF
|
|
|
|
|
|
2020-07-22 11:17:09 -05:00
|
|
|
# DNS server
|
|
|
|
|
echo "nameserver 8.8.8.8" > ${work_dir}/etc/resolv.conf
|
2015-05-12 15:34:30 -05:00
|
|
|
|
2020-07-22 11:17:09 -05:00
|
|
|
# Copy directory bsp into build dir.
|
|
|
|
|
cp -rp bsp ${work_dir}
|
2015-05-12 15:34:30 -05:00
|
|
|
|
2020-07-22 11:17:09 -05:00
|
|
|
export MALLOC_CHECK_=0 # workaround for LP: #520465
|
2015-05-12 15:34:30 -05:00
|
|
|
|
2020-07-22 11:17:09 -05:00
|
|
|
# Enable the use of http proxy in third-stage in case it is enabled.
|
|
|
|
|
if [ -n "$proxy_url" ]; then
|
|
|
|
|
echo "Acquire::http { Proxy \"$proxy_url\" };" > ${work_dir}/etc/apt/apt.conf.d/66proxy
|
|
|
|
|
fi
|
2018-07-23 15:12:53 -05:00
|
|
|
|
2020-07-22 11:17:09 -05:00
|
|
|
# Third stage
|
|
|
|
|
cat << EOF > ${work_dir}/third-stage
|
|
|
|
|
#!/bin/bash -e
|
|
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
|
|
|
export RUNLEVEL=1
|
|
|
|
|
ln -sf /bin/true /usr/sbin/invoke-rc.d
|
2015-05-12 15:34:30 -05:00
|
|
|
echo -e "#!/bin/sh\nexit 101" > /usr/sbin/policy-rc.d
|
2018-06-22 20:38:19 -05:00
|
|
|
chmod 755 /usr/sbin/policy-rc.d
|
2015-05-12 15:34:30 -05:00
|
|
|
|
|
|
|
|
apt-get update
|
|
|
|
|
|
2020-07-22 11:17:09 -05:00
|
|
|
apt-get -y install binutils ca-certificates console-common cryptsetup-bin git initramfs-tools less locales nano u-boot-tools
|
2020-05-07 15:17:10 -05:00
|
|
|
|
|
|
|
|
# Create kali user with kali password... but first, we need to manually make some groups because they don't yet exist...
|
|
|
|
|
# This mirrors what we have on a pre-installed VM, until the script works properly to allow end users to set up their own... user.
|
|
|
|
|
# However we leave off floppy, because who a) still uses them, and b) attaches them to an SBC!?
|
|
|
|
|
# And since a lot of these have serial devices of some sort, dialout is added as well.
|
|
|
|
|
# scanner, lpadmin and bluetooth have to be added manually because they don't
|
|
|
|
|
# yet exist in /etc/group at this point.
|
|
|
|
|
groupadd -r -g 118 bluetooth
|
|
|
|
|
groupadd -r -g 113 lpadmin
|
|
|
|
|
groupadd -r -g 122 scanner
|
|
|
|
|
groupadd -g 1000 kali
|
|
|
|
|
|
|
|
|
|
useradd -m -u 1000 -g 1000 -G sudo,audio,bluetooth,cdrom,dialout,dip,lpadmin,netdev,plugdev,scanner,video,kali -s /bin/bash kali
|
|
|
|
|
echo "kali:kali" | chpasswd
|
|
|
|
|
|
2020-07-22 11:17:09 -05:00
|
|
|
aptops="--allow-change-held-packages -o dpkg::options::=--force-confnew"
|
|
|
|
|
|
2018-12-18 23:00:32 -06:00
|
|
|
# This looks weird, but we do it twice because every so often, there's a failure to download from the mirror
|
|
|
|
|
# So to workaround it, we attempt to install them twice.
|
2020-07-22 11:17:09 -05:00
|
|
|
apt-get install -y \$aptops ${packages} || apt-get --yes --fix-broken install
|
|
|
|
|
apt-get install -y \$aptops ${packages} || apt-get --yes --fix-broken install
|
|
|
|
|
apt-get install -y \$aptops ${desktop} ${extras} ${tools} || apt-get --yes --fix-broken install
|
|
|
|
|
apt-get install -y \$aptops ${desktop} ${extras} ${tools} || apt-get --yes --fix-broken install
|
|
|
|
|
apt-get install -y \$aptops --autoremove systemd-timesyncd || apt-get --yes --fix-broken install
|
|
|
|
|
apt-get dist-upgrade -y \$aptops
|
|
|
|
|
|
|
|
|
|
apt-get -y --allow-change-held-packages --purge autoremove
|
|
|
|
|
|
|
|
|
|
# Linux console/Keyboard configuration
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
# Copy all services
|
|
|
|
|
cp -p /bsp/services/all/*.service /etc/systemd/system/
|
2015-05-12 15:34:30 -05:00
|
|
|
|
2019-02-12 17:56:53 -06:00
|
|
|
# Regenerated the shared-mime-info database on the first boot
|
|
|
|
|
# since it fails to do so properly in a chroot.
|
|
|
|
|
systemctl enable smi-hack
|
2018-07-23 15:12:53 -05:00
|
|
|
|
|
|
|
|
# Generate SSH host keys on first run
|
|
|
|
|
systemctl enable regenerate_ssh_host_keys
|
2020-07-22 11:17:09 -05:00
|
|
|
# Enable sshd
|
2018-07-23 15:12:53 -05:00
|
|
|
systemctl enable ssh
|
|
|
|
|
|
2020-07-22 11:17:09 -05:00
|
|
|
cd /root
|
|
|
|
|
apt download -o APT::Sandbox::User=root ca-certificates 2>/dev/null
|
|
|
|
|
|
2018-07-23 15:12:53 -05:00
|
|
|
# Copy over the default bashrc
|
2020-07-22 11:17:09 -05:00
|
|
|
cp /etc/skel/.bashrc /root/.bashrc
|
2018-07-12 18:26:11 -05:00
|
|
|
|
2020-07-22 11:17:09 -05:00
|
|
|
# Set a REGDOMAIN. This needs to be done or wireless doesn't work correctly on the RPi 3B+
|
|
|
|
|
sed -i -e 's/REGDOM.*/REGDOMAIN=00/g' /etc/default/crda
|
|
|
|
|
|
|
|
|
|
# Enable login over serial
|
|
|
|
|
echo "T0:23:respawn:/sbin/agetty -L ttyAMA0 115200 vt100" >> /etc/inittab
|
2019-05-10 17:18:34 -05:00
|
|
|
|
2018-07-23 15:12:53 -05:00
|
|
|
# Try and make the console a bit nicer
|
|
|
|
|
# Set the terminus font for a bit nicer display.
|
|
|
|
|
sed -i -e 's/FONTFACE=.*/FONTFACE="Terminus"/' /etc/default/console-setup
|
|
|
|
|
sed -i -e 's/FONTSIZE=.*/FONTSIZE="6x12"/' /etc/default/console-setup
|
|
|
|
|
|
2020-07-22 11:17:09 -05:00
|
|
|
# Fix startup time from 5 minutes to 15 secs on raise interface wlan0
|
|
|
|
|
sed -i 's/^TimeoutStartSec=5min/TimeoutStartSec=15/g' "/usr/lib/systemd/system/networking.service"
|
2015-05-12 15:34:30 -05:00
|
|
|
|
2020-07-22 11:17:09 -05:00
|
|
|
rm -f /usr/sbin/policy-rc.d
|
|
|
|
|
unlink /usr/sbin/invoke-rc.d
|
2015-05-12 15:34:30 -05:00
|
|
|
EOF
|
|
|
|
|
|
2020-07-22 11:17:09 -05:00
|
|
|
# Run third stage
|
|
|
|
|
chmod 755 ${work_dir}/third-stage
|
|
|
|
|
systemd-nspawn_exec /third-stage
|
2015-05-12 15:34:30 -05:00
|
|
|
|
2020-07-22 11:17:09 -05:00
|
|
|
# Clean system
|
|
|
|
|
systemd-nspawn_exec << EOF
|
2015-05-12 15:34:30 -05:00
|
|
|
rm -f /0
|
2020-07-22 11:17:09 -05:00
|
|
|
rm -rf /bsp
|
|
|
|
|
fc-cache -frs
|
|
|
|
|
rm -rf /tmp/*
|
|
|
|
|
rm -rf /etc/*-
|
|
|
|
|
rm -rf /hs_err*
|
|
|
|
|
rm -rf /userland
|
|
|
|
|
rm -rf /opt/vc/src
|
|
|
|
|
rm -f /etc/ssh/ssh_host_*
|
|
|
|
|
rm -rf /var/lib/apt/lists/*
|
|
|
|
|
rm -rf /var/cache/apt/*.bin
|
|
|
|
|
rm -rf /var/cache/apt/archives/*
|
|
|
|
|
rm -rf /var/cache/debconf/*.data-old
|
|
|
|
|
history -c
|
2015-05-12 15:34:30 -05:00
|
|
|
EOF
|
2020-07-22 11:17:09 -05:00
|
|
|
#Clear all logs
|
|
|
|
|
for logs in `find $work_dir/var/log -type f`; do > $logs; done
|
2015-05-12 15:34:30 -05:00
|
|
|
|
2020-07-22 11:17:09 -05:00
|
|
|
# Disable the use of http proxy in case it is enabled.
|
|
|
|
|
if [ -n "$proxy_url" ]; then
|
|
|
|
|
unset http_proxy
|
|
|
|
|
rm -rf ${work_dir}/etc/apt/apt.conf.d/66proxy
|
|
|
|
|
fi
|
2015-05-12 15:34:30 -05:00
|
|
|
|
2020-07-26 14:38:21 -05:00
|
|
|
# Mirror replacement
|
|
|
|
|
if [ ! -z "${@:5}" ]; then
|
|
|
|
|
mirror=${@:5}
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Define sources.list
|
2020-07-22 11:17:09 -05:00
|
|
|
cat << EOF > ${work_dir}/etc/apt/sources.list
|
2020-07-26 14:38:21 -05:00
|
|
|
deb ${mirror} ${suite} ${components//,/ }
|
|
|
|
|
#deb-src ${mirror} ${suite} ${components//,/ }
|
2015-05-12 15:34:30 -05:00
|
|
|
EOF
|
|
|
|
|
|
2018-06-19 14:16:57 -05:00
|
|
|
# Pull in the gcc 5.3 cross compiler to build the kernel.
|
2020-07-22 11:17:09 -05:00
|
|
|
# Debian uses a newer compiler and the chromebook kernel doesn't support
|
2018-06-19 14:16:57 -05:00
|
|
|
# that.
|
2018-07-12 02:51:33 -05:00
|
|
|
cd "${basedir}"
|
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-06-19 18:18:26 -05:00
|
|
|
|
2015-05-12 15:34:30 -05:00
|
|
|
# Kernel section. If you want to use a custom kernel, or configuration, replace
|
|
|
|
|
# them in this section.
|
2018-07-12 02:51:33 -05:00
|
|
|
cd "${basedir}"
|
2020-07-22 11:17:09 -05:00
|
|
|
git clone --depth 1 https://chromium.googlesource.com/chromiumos/third_party/kernel -b release-${kernel_release} ${work_dir}/usr/src/kernel
|
|
|
|
|
cd ${work_dir}/usr/src/kernel
|
|
|
|
|
mkdir -p ${work_dir}/usr/src/kernel/firmware/nvidia/tegra124/
|
|
|
|
|
cp ${work_dir}/lib/firmware/nvidia/tegra124/xusb.bin firmware/nvidia/tegra124/
|
|
|
|
|
cp ${current_dir}/kernel-configs/chromebook-3.10.config .config
|
|
|
|
|
cp ${current_dir}/kernel-configs/chromebook-3.10.config ${work_dir}/usr/src/nyan.config
|
|
|
|
|
git rev-parse HEAD > ${work_dir}/usr/src/kernel-at-commit
|
2015-05-12 15:34:30 -05:00
|
|
|
export ARCH=arm
|
|
|
|
|
# Edit the CROSS_COMPILE variable as needed.
|
2018-07-12 02:51:33 -05:00
|
|
|
export CROSS_COMPILE="${basedir}"/gcc-arm-linux-gnueabihf-4.7/bin/arm-linux-gnueabihf-
|
2020-07-22 11:17:09 -05:00
|
|
|
patch -p1 --no-backup-if-mismatch < ${current_dir}/patches/mac80211-3.8.patch
|
|
|
|
|
patch -p1 --no-backup-if-mismatch < ${work_dir}/patches/0001-mwifiex-do-not-create-AP-and-P2P-interfaces-upon-dri-3.8.patch
|
|
|
|
|
patch -p1 --no-backup-if-mismatch < ${work_dir}/patches/0001-Comment-out-a-pr_debug-print.patch
|
2018-07-02 10:50:52 -05:00
|
|
|
make WIFIVERSION="-3.8" oldconfig || die "Kernel config options added"
|
2015-05-12 15:34:30 -05:00
|
|
|
make WIFIVERSION="-3.8" -j $(grep -c processor /proc/cpuinfo)
|
|
|
|
|
make WIFIVERSION="-3.8" dtbs
|
2020-07-22 11:17:09 -05:00
|
|
|
make WIFIVERSION="-3.8" modules_install INSTALL_MOD_PATH=${work_dir}
|
|
|
|
|
cat << __EOF__ > ${work_dir}/usr/src/kernel/arch/arm/boot/kernel-nyan.its
|
2015-05-12 15:34:30 -05:00
|
|
|
/dts-v1/;
|
|
|
|
|
|
|
|
|
|
/ {
|
|
|
|
|
description = "Chrome OS kernel image with one or more FDT blobs";
|
|
|
|
|
#address-cells = <1>;
|
|
|
|
|
images {
|
|
|
|
|
kernel@1{
|
|
|
|
|
description = "kernel";
|
|
|
|
|
data = /incbin/("zImage");
|
|
|
|
|
type = "kernel_noload";
|
|
|
|
|
arch = "arm";
|
|
|
|
|
os = "linux";
|
|
|
|
|
compression = "none";
|
|
|
|
|
load = <0>;
|
|
|
|
|
entry = <0>;
|
|
|
|
|
};
|
|
|
|
|
fdt@1{
|
2015-08-10 22:20:36 -05:00
|
|
|
description = "tegra124-nyan-big-rev0_2.dtb";
|
|
|
|
|
data = /incbin/("dts/tegra124-nyan-big-rev0_2.dtb");
|
2015-05-12 15:34:30 -05:00
|
|
|
type = "flat_dt";
|
|
|
|
|
arch = "arm";
|
|
|
|
|
compression = "none";
|
|
|
|
|
hash@1{
|
|
|
|
|
algo = "sha1";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
fdt@2{
|
2015-08-10 22:20:36 -05:00
|
|
|
description = "tegra124-nyan-big-rev3_7.dtb";
|
|
|
|
|
data = /incbin/("dts/tegra124-nyan-big-rev3_7.dtb");
|
2015-05-12 15:34:30 -05:00
|
|
|
type = "flat_dt";
|
|
|
|
|
arch = "arm";
|
|
|
|
|
compression = "none";
|
|
|
|
|
hash@1{
|
|
|
|
|
algo = "sha1";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
fdt@3{
|
2015-08-10 22:20:36 -05:00
|
|
|
description = "tegra124-nyan-big-rev8_9.dtb";
|
|
|
|
|
data = /incbin/("dts/tegra124-nyan-big-rev8_9.dtb");
|
2015-05-12 15:34:30 -05:00
|
|
|
type = "flat_dt";
|
|
|
|
|
arch = "arm";
|
|
|
|
|
compression = "none";
|
|
|
|
|
hash@1{
|
|
|
|
|
algo = "sha1";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
fdt@4{
|
2015-08-10 22:20:36 -05:00
|
|
|
description = "tegra124-nyan-blaze.dtb";
|
|
|
|
|
data = /incbin/("dts/tegra124-nyan-blaze.dtb");
|
2015-05-12 15:34:30 -05:00
|
|
|
type = "flat_dt";
|
|
|
|
|
arch = "arm";
|
|
|
|
|
compression = "none";
|
|
|
|
|
hash@1{
|
|
|
|
|
algo = "sha1";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
fdt@5{
|
|
|
|
|
description = "tegra124-nyan-rev0.dtb";
|
|
|
|
|
data = /incbin/("dts/tegra124-nyan-rev0.dtb");
|
|
|
|
|
type = "flat_dt";
|
|
|
|
|
arch = "arm";
|
|
|
|
|
compression = "none";
|
|
|
|
|
hash@1{
|
|
|
|
|
algo = "sha1";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
fdt@6{
|
|
|
|
|
description = "tegra124-nyan-rev1.dtb";
|
|
|
|
|
data = /incbin/("dts/tegra124-nyan-rev1.dtb");
|
|
|
|
|
type = "flat_dt";
|
|
|
|
|
arch = "arm";
|
|
|
|
|
compression = "none";
|
|
|
|
|
hash@1{
|
|
|
|
|
algo = "sha1";
|
|
|
|
|
};
|
|
|
|
|
};
|
2015-08-10 22:20:36 -05:00
|
|
|
fdt@7{
|
|
|
|
|
description = "tegra124-nyan-kitty-rev0_3.dtb";
|
|
|
|
|
data = /incbin/("dts/tegra124-nyan-kitty-rev0_3.dtb");
|
|
|
|
|
type = "flat_dt";
|
|
|
|
|
arch = "arm";
|
|
|
|
|
compression = "none";
|
|
|
|
|
hash@1{
|
|
|
|
|
algo = "sha1";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
fdt@8{
|
|
|
|
|
description = "tegra124-nyan-kitty-rev8.dtb";
|
|
|
|
|
data = /incbin/("dts/tegra124-nyan-kitty-rev8.dtb");
|
|
|
|
|
type = "flat_dt";
|
|
|
|
|
arch = "arm";
|
|
|
|
|
compression = "none";
|
|
|
|
|
hash@1{
|
|
|
|
|
algo = "sha1";
|
|
|
|
|
};
|
|
|
|
|
};
|
2015-05-12 15:34:30 -05:00
|
|
|
};
|
|
|
|
|
configurations {
|
|
|
|
|
default = "conf@1";
|
|
|
|
|
conf@1{
|
|
|
|
|
kernel = "kernel@1";
|
|
|
|
|
fdt = "fdt@1";
|
|
|
|
|
};
|
|
|
|
|
conf@2{
|
|
|
|
|
kernel = "kernel@1";
|
|
|
|
|
fdt = "fdt@2";
|
|
|
|
|
};
|
|
|
|
|
conf@3{
|
|
|
|
|
kernel = "kernel@1";
|
|
|
|
|
fdt = "fdt@3";
|
|
|
|
|
};
|
|
|
|
|
conf@4{
|
|
|
|
|
kernel = "kernel@1";
|
|
|
|
|
fdt = "fdt@4";
|
|
|
|
|
};
|
|
|
|
|
conf@5{
|
|
|
|
|
kernel = "kernel@1";
|
|
|
|
|
fdt = "fdt@5";
|
|
|
|
|
};
|
|
|
|
|
conf@6{
|
|
|
|
|
kernel = "kernel@1";
|
|
|
|
|
fdt = "fdt@6";
|
|
|
|
|
};
|
2015-08-10 22:20:36 -05:00
|
|
|
conf@7{
|
|
|
|
|
kernel = "kernel@1";
|
|
|
|
|
fdt = "fdt@7";
|
|
|
|
|
};
|
|
|
|
|
conf@8{
|
|
|
|
|
kernel = "kernel@1";
|
|
|
|
|
fdt = "fdt@8";
|
|
|
|
|
};
|
2015-05-12 15:34:30 -05:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
__EOF__
|
2020-07-22 11:17:09 -05:00
|
|
|
cd ${work_dir}/usr/src/kernel/arch/arm/boot
|
2015-05-12 15:34:30 -05:00
|
|
|
mkimage -f kernel-nyan.its nyan-big-kernel
|
|
|
|
|
|
2015-08-10 22:20:36 -05:00
|
|
|
# BEHOLD THE POWER OF PARTUUID/PARTNROFF
|
2020-05-07 15:19:48 -05:00
|
|
|
echo "noinitrd console=tty1 quiet root=PARTUUID=%U/PARTNROFF=1 rootwait rw lsm.module_locking=0 net.ifnames=0 rootfstype=ext3" > cmdline
|
2015-08-10 22:20:36 -05:00
|
|
|
|
|
|
|
|
# Pulled from ChromeOS, this is exactly what they do because there's no
|
|
|
|
|
# # bootloader in the kernel partition on ARM.
|
|
|
|
|
dd if=/dev/zero of=bootloader.bin bs=512 count=1
|
2015-05-12 15:34:30 -05:00
|
|
|
|
2018-07-12 02:51:33 -05:00
|
|
|
vbutil_kernel --arch arm --pack "${basedir}"/kernel.bin --keyblock /usr/share/vboot/devkeys/kernel.keyblock --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk --version 1 --config cmdline --bootloader bootloader.bin --vmlinuz nyan-big-kernel
|
2015-08-10 22:20:36 -05:00
|
|
|
|
2020-07-22 11:17:09 -05:00
|
|
|
cd ${work_dir}/usr/src/kernel
|
2015-08-10 22:20:36 -05:00
|
|
|
# Clean up our build of the kernel, then copy the config and run make
|
|
|
|
|
# modules_prepare so that users can more easily build kernel modules...
|
|
|
|
|
make WIFIVERSION="-3.8" mrproper
|
|
|
|
|
cp ../nyan.config .config
|
2018-07-12 02:51:33 -05:00
|
|
|
cd "${basedir}"
|
2015-05-12 15:34:30 -05:00
|
|
|
|
2017-09-20 16:45:33 -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 11:17:09 -05:00
|
|
|
kernver=$(ls ${work_dir}/lib/modules/)
|
|
|
|
|
cd ${work_dir}/lib/modules/${kernver}
|
2017-09-20 16:45:33 -05:00
|
|
|
rm build
|
|
|
|
|
rm source
|
|
|
|
|
ln -s /usr/src/kernel build
|
|
|
|
|
ln -s /usr/src/kernel source
|
2018-07-12 02:51:33 -05:00
|
|
|
cd "${basedir}"
|
2017-09-20 16:45:33 -05:00
|
|
|
|
2015-05-12 15:34:30 -05:00
|
|
|
# Lid switch
|
2020-07-22 11:17:09 -05:00
|
|
|
cat << EOF > ${work_dir}/etc/udev/rules.d/99-tegra-lid-switch.rules
|
2015-05-12 15:34:30 -05:00
|
|
|
ACTION=="remove", GOTO="tegra_lid_switch_end"
|
2015-08-10 22:20:36 -05:00
|
|
|
SUBSYSTEM=="input", KERNEL=="event*", SUBSYSTEMS=="platform", KERNELS=="gpio-keys.4", TAG+="power-switch"
|
2015-05-12 15:34:30 -05:00
|
|
|
LABEL="tegra_lid_switch_end"
|
|
|
|
|
EOF
|
|
|
|
|
|
2015-08-10 22:20:36 -05:00
|
|
|
# Bit of a hack, this is so the eMMC doesn't show up on the desktop
|
2020-07-22 11:17:09 -05:00
|
|
|
cat << EOF > ${work_dir}/etc/udev/rules.d/99-hide-emmc-partitions.rules
|
2015-08-10 22:20:36 -05:00
|
|
|
KERNEL=="mmcblk0*", ENV{UDISKS_IGNORE}="1"
|
|
|
|
|
EOF
|
|
|
|
|
|
2017-09-20 16:45:33 -05:00
|
|
|
# Disable uap0 and p2p0 interfaces in NetworkManager
|
2020-07-22 11:17:09 -05:00
|
|
|
mkdir -p ${work_dir}/etc/NetworkManager/
|
|
|
|
|
printf '\n[keyfile]\nunmanaged-devices=interface-name:p2p0\n' >> ${work_dir}/etc/NetworkManager/NetworkManager.conf
|
2017-09-20 16:45:33 -05:00
|
|
|
|
2015-05-12 15:34:30 -05:00
|
|
|
#nvidia device nodes
|
2020-07-22 11:17:09 -05:00
|
|
|
cat << EOF > ${work_dir}/lib/udev/rules.d/51-nvrm.rules
|
2015-05-12 15:34:30 -05:00
|
|
|
KERNEL=="knvmap", GROUP="video", MODE="0660"
|
|
|
|
|
KERNEL=="nvhdcp1", GROUP="video", MODE="0660"
|
|
|
|
|
KERNEL=="nvhost-as-gpu", GROUP="video", MODE="0660"
|
|
|
|
|
KERNEL=="nvhost-ctrl", GROUP="video", MODE="0660"
|
|
|
|
|
KERNEL=="nvhost-ctrl-gpu", GROUP="video", MODE="0660"
|
|
|
|
|
KERNEL=="nvhost-dbg-gpu", GROUP="video", MODE="0660"
|
|
|
|
|
KERNEL=="nvhost-gpu", GROUP="video", MODE="0660"
|
2020-04-05 14:36:46 -05:00
|
|
|
KERNEL=="nvhost-msenc", GROUP="video", MODE="0660"
|
|
|
|
|
KERNEL=="nvhost-prof-gpu", GROUP="video", MODE="0660"
|
2015-05-12 15:34:30 -05:00
|
|
|
KERNEL=="nvhost-tsec", GROUP="video", MODE="0660"
|
|
|
|
|
KERNEL=="nvhost-vic", GROUP="video", MODE="0660"
|
|
|
|
|
KERNEL=="nvmap", GROUP="video", MODE="0660"
|
|
|
|
|
KERNEL=="tegra_dc_0", GROUP="video", MODE="0660"
|
|
|
|
|
KERNEL=="tegra_dc_1", GROUP="video", MODE="0660"
|
|
|
|
|
KERNEL=="tegra_dc_ctrl", GROUP="video", MODE="0660"
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
# Touchpad configuration
|
2020-07-22 11:17:09 -05:00
|
|
|
mkdir -p ${work_dir}/etc/X11/xorg.conf.d
|
|
|
|
|
cp ${current_dir}/bsp/xorg/10-synaptics-chromebook.conf ${work_dir}/etc/X11/xorg.conf.d/
|
2015-05-12 15:34:30 -05:00
|
|
|
|
|
|
|
|
# lp0 resume firmware...
|
2018-06-19 15:18:08 -05:00
|
|
|
# Check https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/master/sys-kernel/tegra_lp0_resume/
|
|
|
|
|
# to find the lastest commit to use (note: CROS_WORKON_COMMIT )
|
2018-07-12 02:51:33 -05:00
|
|
|
cd "${basedir}"
|
2015-05-12 15:34:30 -05:00
|
|
|
git clone https://chromium.googlesource.com/chromiumos/third_party/coreboot
|
2018-07-12 02:51:33 -05:00
|
|
|
cd "${basedir}"/coreboot
|
2018-12-07 16:38:56 -06:00
|
|
|
git checkout fb840ee4195f9c365375e8914e243ce2f5e4f7bf
|
2015-05-12 15:34:30 -05:00
|
|
|
make -C src/soc/nvidia/tegra124/lp0 GCC_PREFIX=arm-linux-gnueabihf-
|
2020-07-22 11:17:09 -05:00
|
|
|
mkdir -p ${work_dir}/lib/firmware/tegra12x/
|
|
|
|
|
cp src/soc/nvidia/tegra124/lp0/tegra_lp0_resume.fw ${work_dir}/lib/firmware/tegra12x/
|
2018-07-12 02:51:33 -05:00
|
|
|
cd "${basedir}"
|
2015-05-12 15:34:30 -05:00
|
|
|
|
2020-07-22 11:17:09 -05:00
|
|
|
# Calculate the space to create the image.
|
2020-07-24 13:39:50 -05:00
|
|
|
root_size=$(du -s -B1 ${work_dir} --exclude=${work_dir}/boot | cut -f1)
|
|
|
|
|
root_extra=$((${root_size}/1024/1000*5*1024/5))
|
|
|
|
|
raw_size=$(($((${free_space}*1024))+${root_extra}+$((${bootsize}*1024))+4096))
|
2018-07-02 10:50:52 -05:00
|
|
|
|
2020-07-22 11:17:09 -05:00
|
|
|
# Create the disk and partition it
|
2020-07-24 13:39:50 -05:00
|
|
|
echo "Creating image file ${imagename}.img"
|
2020-07-26 14:38:21 -05:00
|
|
|
fallocate -l $(echo ${raw_size}Ki | numfmt --from=iec-i --to=si) ${current_dir}/${imagename}.img
|
|
|
|
|
parted ${current_dir}/${imagename}.img --script -- mklabel gpt
|
|
|
|
|
cgpt create -z ${current_dir}/${imagename}.img
|
|
|
|
|
cgpt create ${current_dir}/${imagename}.img
|
2015-05-12 15:34:30 -05:00
|
|
|
|
2020-07-26 14:38:21 -05:00
|
|
|
cgpt add -i 1 -t kernel -b 8192 -s 32768 -l kernel -S 1 -T 5 -P 10 ${current_dir}/${imagename}.img
|
|
|
|
|
cgpt add -i 2 -t data -b 40960 -s `expr $(cgpt show ${current_dir}/${imagename}.img | grep 'Sec GPT table' | awk '{ print \$1 }') - 40960` -l Root ${current_dir}/${imagename}.img
|
2018-07-02 10:50:52 -05:00
|
|
|
|
2020-07-26 14:38:21 -05:00
|
|
|
loopdevice=`losetup -f --show ${current_dir}/${imagename}.img`
|
2018-07-03 16:44:59 -05:00
|
|
|
device=`kpartx -va ${loopdevice} | sed 's/.*\(loop[0-9]\+\)p.*/\1/g' | head -1`
|
2018-07-02 10:50:52 -05:00
|
|
|
sleep 5
|
|
|
|
|
device="/dev/mapper/${device}"
|
|
|
|
|
bootp=${device}p1
|
|
|
|
|
rootp=${device}p2
|
|
|
|
|
|
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-02 10:50:52 -05:00
|
|
|
|
2018-07-12 02:51:33 -05:00
|
|
|
mkdir -p "${basedir}"/root
|
|
|
|
|
mount ${rootp} "${basedir}"/root
|
2018-07-02 10:50:52 -05:00
|
|
|
|
2018-07-02 16:48:39 -05:00
|
|
|
# We do this down here to get rid of the build system's resolv.conf after running through the build.
|
2020-07-22 11:17:09 -05:00
|
|
|
cat << EOF > ${work_dir}/etc/resolv.conf
|
2018-07-02 16:48:39 -05:00
|
|
|
nameserver 8.8.8.8
|
|
|
|
|
EOF
|
|
|
|
|
|
2020-06-25 17:42:35 -05:00
|
|
|
# Create an fstab so that we don't mount / read-only.
|
|
|
|
|
UUID=$(blkid -s UUID -o value ${rootp})
|
2020-07-22 11:17:09 -05:00
|
|
|
echo "UUID=$UUID / ext3 errors=remount-ro 0 1" >> ${work_dir}/etc/fstab
|
2020-06-25 17:42:35 -05:00
|
|
|
|
2018-07-02 10:50:52 -05:00
|
|
|
echo "Rsyncing rootfs into image file"
|
2020-07-22 11:17:09 -05:00
|
|
|
rsync -HPavz -q ${work_dir}/ ${basedir}/root/
|
2017-09-20 16:45:33 -05:00
|
|
|
|
2015-05-12 15:34:30 -05:00
|
|
|
# Unmount partitions
|
2018-07-02 10:50:52 -05:00
|
|
|
sync
|
|
|
|
|
umount ${rootp}
|
|
|
|
|
|
2018-07-12 02:51:33 -05:00
|
|
|
dd if="${basedir}"/kernel.bin of=${bootp}
|
2015-05-12 15:34:30 -05:00
|
|
|
|
2018-07-02 10:50:52 -05:00
|
|
|
cgpt repair ${loopdevice}
|
2015-05-12 15:34:30 -05:00
|
|
|
|
2018-07-02 10:50:52 -05:00
|
|
|
kpartx -dv ${loopdevice}
|
|
|
|
|
losetup -d ${loopdevice}
|
2015-05-12 15:34:30 -05:00
|
|
|
|
|
|
|
|
|
2020-07-26 14:38:21 -05:00
|
|
|
# Limite use cpu function
|
|
|
|
|
limit_cpu (){
|
2020-07-22 11:17:09 -05:00
|
|
|
rand=$(tr -cd 'A-Za-z0-9' < /dev/urandom | head -c4 ; echo) # Randowm name group
|
2020-07-26 14:38:21 -05:00
|
|
|
cgcreate -g cpu:/cpulimit-${rand} # Name of group cpulimit
|
2020-07-22 11:17:09 -05:00
|
|
|
cgset -r cpu.shares=800 cpulimit-${rand} # Max 1024
|
|
|
|
|
cgset -r cpu.cfs_quota_us=80000 cpulimit-${rand} # Max 100000
|
2020-07-26 14:38:21 -05:00
|
|
|
# Retry command
|
|
|
|
|
local n=1; local max=5; local delay=2
|
|
|
|
|
while true; do
|
|
|
|
|
cgexec -g cpu:cpulimit-${rand} "$@" && break || {
|
|
|
|
|
if [[ $n -lt $max ]]; then
|
|
|
|
|
((n++))
|
|
|
|
|
echo -e "\e[31m Command failed. Attempt $n/$max \033[0m"
|
|
|
|
|
sleep $delay;
|
|
|
|
|
else
|
|
|
|
|
echo "The command has failed after $n attempts."
|
|
|
|
|
break
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if [ $compress = xz ]; then
|
|
|
|
|
if [ $(arch) == 'x86_64' ]; then
|
|
|
|
|
echo "Compressing ${imagename}.img"
|
|
|
|
|
limit_cpu pixz -p 2 ${current_dir}/${imagename}.img # -p Nº cpu cores use
|
|
|
|
|
chmod 644 ${current_dir}/${imagename}.img.xz
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
chmod 644 ${current_dir}/${imagename}.img
|
2015-05-12 15:34:30 -05:00
|
|
|
fi
|
2018-06-19 20:02:23 -05: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.
|
|
|
|
|
echo "Removing temporary build files"
|
2018-07-12 02:51:33 -05:00
|
|
|
rm -rf "${basedir}"
|