2017-05-26 20:26:25 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
source_deviceinfo()
|
|
|
|
{
|
|
|
|
if [ ! -e "/etc/deviceinfo" ]; then
|
|
|
|
echo "ERROR: Missing /etc/deviceinfo!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
. /etc/deviceinfo
|
|
|
|
if [ -z "${deviceinfo_modules_initfs}" ]; then
|
|
|
|
echo "WARNING: deviceinfo_modules_initfs is empty!"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
parse_commandline()
|
|
|
|
{
|
|
|
|
if [ "$1" != "-o" ]; then
|
|
|
|
echo "postmarketos-mkinitfs"
|
2017-07-28 18:51:21 +00:00
|
|
|
echo "usage: $(basename "$0") -o OUTFILE KERNELVERSION"
|
2017-05-26 20:26:25 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
outfile=$2
|
2017-07-28 18:51:21 +00:00
|
|
|
outfile_extra=$2-extra
|
2017-05-26 20:26:25 +00:00
|
|
|
kernel=$3
|
|
|
|
modules_path="/lib/modules/${kernel}"
|
|
|
|
|
|
|
|
if [ ! -d ${abi_path} ]; then
|
|
|
|
echo "ERROR: Modules path not found: ${modules_path}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
create_folders()
|
|
|
|
{
|
|
|
|
for dir in /bin /sbin /usr/bin /usr/sbin /proc /sys /dev /tmp /lib \
|
2017-07-28 18:51:21 +00:00
|
|
|
/boot /sysroot; do
|
2017-05-26 20:26:25 +00:00
|
|
|
mkdir -p "$tmpdir$dir"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
get_modules_by_globs()
|
|
|
|
{
|
|
|
|
globs="
|
|
|
|
# base.modules
|
|
|
|
kernel/drivers/block/loop.ko
|
|
|
|
kernel/fs/overlayfs
|
|
|
|
|
|
|
|
# cryptsetup.modules
|
|
|
|
kernel/crypto/*
|
|
|
|
kernel/arch/*/crypto/*
|
|
|
|
kernel/drivers/md/dm-crypt.ko
|
|
|
|
|
|
|
|
# kms.modules
|
|
|
|
kernel/drivers/char/agp
|
|
|
|
kernel/drivers/gpu
|
|
|
|
kernel/drivers/i2c
|
|
|
|
kernel/drivers/video
|
|
|
|
kernel/arch/x86/video/fbdev.ko
|
|
|
|
|
|
|
|
# mmc.modules
|
|
|
|
kernel/drivers/mmc
|
|
|
|
|
|
|
|
# required for modprobe
|
|
|
|
modules.*
|
|
|
|
"
|
|
|
|
|
|
|
|
for glob in $globs; do
|
|
|
|
for file in /lib/modules/$kernel/$glob; do
|
|
|
|
if [ -d "$file" ]; then
|
2017-07-28 18:51:21 +00:00
|
|
|
find "$file" -type f
|
2017-05-26 20:26:25 +00:00
|
|
|
elif [ -e "$file" ]; then
|
2017-07-28 18:51:21 +00:00
|
|
|
echo "$file"
|
2017-05-26 20:26:25 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# NOTE: This does not work with busybox' modprobe
|
|
|
|
# That's why postmarketos-mkinitfs depends on kmod
|
|
|
|
get_modules_by_name()
|
|
|
|
{
|
|
|
|
MODULES="drm_kms_helper drm dm_crypt ext4 \
|
|
|
|
${deviceinfo_modules_initfs}"
|
|
|
|
modprobe \
|
|
|
|
-a \
|
|
|
|
--dry-run \
|
|
|
|
--show-depends \
|
|
|
|
--set-version="$kernel" \
|
|
|
|
$MODULES \
|
|
|
|
| sort -u \
|
|
|
|
| cut -d ' ' -f 2
|
|
|
|
}
|
|
|
|
|
|
|
|
get_modules()
|
|
|
|
{
|
|
|
|
get_modules_by_globs
|
|
|
|
get_modules_by_name
|
|
|
|
}
|
|
|
|
|
|
|
|
# Get the paths to all binaries and their dependencies
|
|
|
|
get_binaries()
|
|
|
|
{
|
2017-07-28 18:51:21 +00:00
|
|
|
BINARIES="/bin/busybox /bin/busybox-extras /usr/sbin/telnetd /sbin/kpartx"
|
2017-05-26 20:26:25 +00:00
|
|
|
lddtree -l $BINARIES | sort -u
|
|
|
|
}
|
|
|
|
|
2017-07-28 18:51:21 +00:00
|
|
|
get_binaries_extra()
|
|
|
|
{
|
|
|
|
BINARIES_EXTRA="
|
|
|
|
/sbin/cryptsetup
|
|
|
|
/sbin/dmsetup
|
|
|
|
/usr/sbin/parted
|
|
|
|
/sbin/e2fsck
|
|
|
|
/usr/sbin/resize2fs
|
|
|
|
"
|
|
|
|
tmp1=$(mktemp /tmp/mkinitfs.XXXXXX)
|
|
|
|
get_binaries > "$tmp1"
|
|
|
|
tmp2=$(mktemp /tmp/mkinitfs.XXXXXX)
|
|
|
|
lddtree -l $BINARIES_EXTRA | sort -u > "$tmp2"
|
|
|
|
ret=$(comm -13 "$tmp1" "$tmp2")
|
|
|
|
rm "$tmp1" "$tmp2"
|
|
|
|
echo "${ret}"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Copy files to the destination specified
|
2017-05-26 20:26:25 +00:00
|
|
|
# FIXME: this is a performance bottleneck
|
|
|
|
# $1: files
|
2017-07-28 18:51:21 +00:00
|
|
|
# $2: destination
|
2017-05-26 20:26:25 +00:00
|
|
|
copy_files()
|
|
|
|
{
|
|
|
|
for file in $1; do
|
2017-08-06 13:12:43 +00:00
|
|
|
[ -e "$file" ] || continue
|
2017-07-28 18:51:21 +00:00
|
|
|
install -Dm755 "$file" "$2$file"
|
2017-05-26 20:26:25 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
create_device_nodes()
|
|
|
|
{
|
2017-07-28 18:51:21 +00:00
|
|
|
mknod -m 666 "$tmpdir/dev/null" c 1 3
|
|
|
|
mknod -m 644 "$tmpdir/dev/random" c 1 8
|
|
|
|
mknod -m 644 "$tmpdir/dev/urandom" c 1 9
|
2017-05-26 20:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
replace_init_variables()
|
|
|
|
{
|
2017-07-28 18:51:21 +00:00
|
|
|
sed -i "s:@MODULES@:${deviceinfo_modules_initfs} ext4:g" "$tmpdir/init"
|
|
|
|
sed -i "s:@INITRAMFS_EXTRA@:${outfile_extra}:g" "$tmpdir/init"
|
2017-05-26 20:26:25 +00:00
|
|
|
}
|
|
|
|
|
2017-07-28 18:51:21 +00:00
|
|
|
# Create a cpio image of the specified folder
|
|
|
|
# $1: folder
|
|
|
|
# $2: outfile
|
2017-05-26 20:26:25 +00:00
|
|
|
create_cpio_image()
|
|
|
|
{
|
2017-07-28 18:51:21 +00:00
|
|
|
cd "$1"
|
2017-05-26 20:26:25 +00:00
|
|
|
find . -print0 \
|
|
|
|
| cpio --quiet -o -H newc \
|
2017-07-28 18:51:21 +00:00
|
|
|
| gzip -1 > "$2"
|
2017-05-26 20:26:25 +00:00
|
|
|
}
|
|
|
|
|
2017-06-29 17:51:17 +00:00
|
|
|
# Legacy u-boot images
|
2017-07-25 20:08:35 +00:00
|
|
|
create_uboot_files()
|
2017-06-29 17:51:17 +00:00
|
|
|
{
|
|
|
|
[ "${deviceinfo_generate_legacy_uboot_initfs}" == "true" ] || return
|
|
|
|
echo "==> initramfs: creating uInitrd"
|
|
|
|
mkimage -A arm -T ramdisk -C none -n uInitrd -d "$outfile" "${outfile/initramfs-/uInitrd-}"
|
2017-07-25 20:08:35 +00:00
|
|
|
|
|
|
|
echo "==> kernel: creating uImage"
|
|
|
|
kernelfile="${outfile/initramfs-/vmlinuz-}"
|
|
|
|
if [ -n "${deviceinfo_dtb}" ]; then
|
|
|
|
kernelfile="${kernelfile}-dtb"
|
|
|
|
fi
|
|
|
|
mkimage -A arm -O linux -T kernel -C none -a 80008000 -e 80008000 -n postmarketos -d $kernelfile "${outfile/initramfs-/uImage-}"
|
2017-06-29 17:51:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Android devices
|
|
|
|
create_bootimg()
|
|
|
|
{
|
|
|
|
[ "${deviceinfo_generate_bootimg}" == "true" ] || return
|
|
|
|
echo "==> initramfs: creating boot.img"
|
2017-07-19 20:44:12 +00:00
|
|
|
_base="${deviceinfo_flash_offset_base}"
|
|
|
|
[ -z "$_base" ] && _base="0x10000000"
|
2017-07-25 20:08:35 +00:00
|
|
|
|
|
|
|
kernelfile="${outfile/initramfs-/vmlinuz-}"
|
|
|
|
if [ -n "${deviceinfo_dtb}" ]; then
|
|
|
|
kernelfile="${kernelfile}-dtb"
|
|
|
|
fi
|
2017-06-29 17:51:17 +00:00
|
|
|
mkbootimg \
|
2017-07-25 20:08:35 +00:00
|
|
|
--kernel "${kernelfile}" \
|
2017-06-29 17:51:17 +00:00
|
|
|
--ramdisk "$outfile" \
|
2017-07-19 20:44:12 +00:00
|
|
|
--base "${_base}" \
|
2017-06-29 17:51:17 +00:00
|
|
|
--second_offset "${deviceinfo_flash_offset_second}" \
|
|
|
|
--cmdline "${deviceinfo_kernel_cmdline}" \
|
|
|
|
--kernel_offset "${deviceinfo_flash_offset_kernel}" \
|
|
|
|
--ramdisk_offset "${deviceinfo_flash_offset_ramdisk}" \
|
|
|
|
--tags_offset "${deviceinfo_flash_offset_tags}" \
|
|
|
|
--pagesize "${deviceinfo_flash_pagesize}" \
|
2017-08-09 20:57:52 +00:00
|
|
|
${deviceinfo_bootimg_qcdt:+ --dt /boot/dt.img} \
|
2017-06-29 17:51:17 +00:00
|
|
|
-o "${outfile/initramfs-/boot.img-}"
|
|
|
|
}
|
|
|
|
|
2017-07-23 12:50:40 +00:00
|
|
|
# Create splash screens
|
|
|
|
generate_splash_screens()
|
|
|
|
{
|
|
|
|
width=${deviceinfo_screen_width:-720}
|
|
|
|
height=${deviceinfo_screen_height:-1280}
|
|
|
|
|
|
|
|
pmos-make-splash --text="On-screen keyboard is not implemented yet, plug in a USB cable and run on your PC:\ntelnet 172.16.42.1" \
|
2017-07-28 18:51:21 +00:00
|
|
|
--config /etc/postmarketos/splash.ini "$width" "$height" "${tmpdir}/splash-telnet.ppm"
|
|
|
|
gzip "${tmpdir}/splash-telnet.ppm"
|
2017-07-23 12:50:40 +00:00
|
|
|
|
|
|
|
pmos-make-splash --text="Loading..." --center \
|
2017-07-28 18:51:21 +00:00
|
|
|
--config /etc/postmarketos/splash.ini "$width" "$height" "${tmpdir}/splash-loading.ppm"
|
|
|
|
gzip "${tmpdir}/splash-loading.ppm"
|
|
|
|
|
|
|
|
pmos-make-splash --text="boot partition not found\nhttps://postmarketos.org/troubleshooting" --center \
|
|
|
|
--config /etc/postmarketos/splash.ini "$width" "$height" "${tmpdir}/splash-noboot.ppm"
|
|
|
|
gzip "${tmpdir}/splash-noboot.ppm"
|
|
|
|
|
|
|
|
pmos-make-splash --text="initramfs-extra not found\nhttps://postmarketos.org/troubleshooting" --center \
|
|
|
|
--config /etc/postmarketos/splash.ini "$width" "$height" "${tmpdir}/splash-noinitramfsextra.ppm"
|
|
|
|
gzip "${tmpdir}/splash-noinitramfsextra.ppm"
|
2017-07-23 12:50:40 +00:00
|
|
|
|
2017-07-28 18:51:21 +00:00
|
|
|
pmos-make-splash --text="system partition not found\nhttps://postmarketos.org/troubleshooting" --center \
|
|
|
|
--config /etc/postmarketos/splash.ini "$width" "$height" "${tmpdir}/splash-nosystem.ppm"
|
|
|
|
gzip "${tmpdir}/splash-nosystem.ppm"
|
2017-08-03 16:01:00 +00:00
|
|
|
|
|
|
|
pmos-make-splash --text="unable to mount root partition\nhttps://postmarketos.org/troubleshooting" --center \
|
|
|
|
--config /etc/postmarketos/splash.ini "$width" "$height" "${tmpdir}/splash-mounterror.ppm"
|
|
|
|
gzip "${tmpdir}/splash-mounterror.ppm"
|
2017-07-23 12:50:40 +00:00
|
|
|
}
|
2017-06-29 17:51:17 +00:00
|
|
|
|
2017-07-25 20:08:35 +00:00
|
|
|
# Append the correct device tree to the linux image file
|
|
|
|
append_device_tree()
|
|
|
|
{
|
|
|
|
[ -n "${deviceinfo_dtb}" ] || return
|
|
|
|
dtb="/usr/share/dtb/${deviceinfo_dtb}.dtb"
|
|
|
|
kernel="${outfile/initramfs-/vmlinuz-}"
|
|
|
|
echo "==> kernel: appending device-tree ${deviceinfo_dtb}"
|
|
|
|
cat $kernel $dtb > "${kernel}-dtb"
|
|
|
|
}
|
|
|
|
|
2017-05-26 20:26:25 +00:00
|
|
|
# initialize
|
|
|
|
source_deviceinfo
|
2017-07-28 18:51:21 +00:00
|
|
|
parse_commandline "$1" "$2" "$3"
|
2017-05-26 20:26:25 +00:00
|
|
|
echo "==> initramfs: creating $outfile"
|
|
|
|
tmpdir=$(mktemp -d /tmp/mkinitfs.XXXXXX)
|
|
|
|
|
|
|
|
# set up initfs in temp folder
|
|
|
|
create_folders
|
2017-07-28 18:51:21 +00:00
|
|
|
copy_files "$(get_modules)" "$tmpdir"
|
|
|
|
copy_files "$(get_binaries)" "$tmpdir"
|
|
|
|
copy_files "/etc/postmarketos-mkinitfs/hooks/*.sh" "$tmpdir"
|
2017-05-26 20:26:25 +00:00
|
|
|
create_device_nodes
|
|
|
|
ln -s "/bin/busybox" "$tmpdir/bin/sh"
|
|
|
|
install -Dm755 "/usr/share/postmarketos-mkinitfs/init.sh.in" \
|
|
|
|
"$tmpdir/init"
|
|
|
|
install -Dm755 "/usr/share/postmarketos-mkinitfs/init_functions.sh" \
|
|
|
|
"$tmpdir/init_functions.sh"
|
|
|
|
|
|
|
|
# finish up
|
2017-07-23 12:50:40 +00:00
|
|
|
generate_splash_screens
|
2017-05-26 20:26:25 +00:00
|
|
|
replace_init_variables
|
2017-07-28 18:51:21 +00:00
|
|
|
create_cpio_image "$tmpdir" "$outfile"
|
2017-07-25 20:08:35 +00:00
|
|
|
append_device_tree
|
|
|
|
create_uboot_files
|
2017-06-29 17:51:17 +00:00
|
|
|
create_bootimg
|
2017-06-09 23:41:01 +00:00
|
|
|
|
2017-05-26 20:26:25 +00:00
|
|
|
rm -rf "$tmpdir"
|
2017-07-28 18:51:21 +00:00
|
|
|
|
|
|
|
# initialize initramfs-extra
|
|
|
|
echo "==> initramfs: creating $outfile_extra"
|
|
|
|
tmpdir_extra=$(mktemp -d /tmp/mkinitfs.XXXXXX)
|
|
|
|
|
|
|
|
# set up initfs-extra in temp folder
|
|
|
|
mkdir -p "$tmpdir_extra"
|
|
|
|
copy_files "$(get_binaries_extra)" "$tmpdir_extra"
|
|
|
|
|
|
|
|
# finish up
|
|
|
|
create_cpio_image "$tmpdir_extra" "$outfile_extra"
|
|
|
|
|
|
|
|
rm -rf "$tmpdir_extra"
|
|
|
|
|
2017-05-26 20:26:25 +00:00
|
|
|
exit 0
|