2017-05-26 20:26:25 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# This file will be in /init_functions.sh inside the initramfs.
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
IP=172.16.42.1
|
2020-02-10 21:23:07 +00:00
|
|
|
ROOT_PARTITION_UNLOCKED=0
|
2017-05-26 20:26:25 +00:00
|
|
|
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
# Redirect stdout and stderr to logfile
|
|
|
|
setup_log() {
|
|
|
|
# Bail out if PMOS_NO_OUTPUT_REDIRECT is set
|
|
|
|
echo "### postmarketOS initramfs ###"
|
|
|
|
grep -q PMOS_NO_OUTPUT_REDIRECT /proc/cmdline && return
|
|
|
|
|
|
|
|
# Print a message about what is going on to the normal output
|
|
|
|
echo "NOTE: All output from the initramfs gets redirected to:"
|
|
|
|
echo "/pmOS_init.log"
|
|
|
|
echo "If you want to disable this behavior (e.g. because you're"
|
|
|
|
echo "debugging over serial), please add this to your kernel"
|
|
|
|
echo "command line: PMOS_NO_OUTPUT_REDIRECT"
|
|
|
|
|
|
|
|
# Start redirect, print the first line again
|
|
|
|
exec >/pmOS_init.log 2>&1
|
|
|
|
echo "### postmarketOS initramfs ###"
|
|
|
|
}
|
|
|
|
|
|
|
|
mount_proc_sys_dev() {
|
|
|
|
# mdev
|
2019-06-27 12:02:20 +00:00
|
|
|
mount -t proc -o nodev,noexec,nosuid proc /proc || echo "Couldn't mount /proc"
|
|
|
|
mount -t sysfs -o nodev,noexec,nosuid sysfs /sys || echo "Couldn't mount /sys"
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
|
2017-07-13 15:17:48 +00:00
|
|
|
mkdir /config
|
|
|
|
mount -t configfs -o nodev,noexec,nosuid configfs /config
|
|
|
|
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
# /dev/pts (needed for telnet)
|
|
|
|
mkdir -p /dev/pts
|
|
|
|
mount -t devpts devpts /dev/pts
|
2019-05-14 15:08:35 +00:00
|
|
|
|
|
|
|
# /run (needed for cryptsetup)
|
|
|
|
mkdir /run
|
2017-06-22 17:36:44 +00:00
|
|
|
}
|
|
|
|
|
2019-07-21 10:21:24 +00:00
|
|
|
setup_firmware_path() {
|
|
|
|
# Add the postmarketOS-specific path to the firmware search paths.
|
|
|
|
# This should be sufficient on kernel 3.10+, before that we need
|
|
|
|
# the kernel calling udev (and in our case /usr/lib/firmwareload.sh)
|
|
|
|
# to load the firmware for the kernel.
|
|
|
|
echo "Configuring kernel firmware image search path"
|
|
|
|
SYS=/sys/module/firmware_class/parameters/path
|
|
|
|
if ! [ -e "$SYS" ]; then
|
|
|
|
echo "Kernel does not support setting the firmware image search path. Skipping."
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
# shellcheck disable=SC2039
|
|
|
|
echo -n /lib/firmware/postmarketos >$SYS
|
|
|
|
}
|
|
|
|
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
setup_mdev() {
|
|
|
|
echo /sbin/mdev >/proc/sys/kernel/hotplug
|
|
|
|
mdev -s
|
|
|
|
}
|
|
|
|
|
|
|
|
mount_subpartitions() {
|
2017-10-20 17:20:40 +00:00
|
|
|
# Do not create subpartition mappings if pmOS_boot
|
|
|
|
# already exists (e.g. installed on an sdcard)
|
|
|
|
blkid |grep -q "pmOS_boot" && return
|
2018-10-10 18:11:20 +00:00
|
|
|
attempt_count=0
|
|
|
|
echo "Trying to mount subpartitions for 10 seconds..."
|
|
|
|
while [ -z "$(find_boot_partition)" ]; do
|
2018-11-02 00:15:41 +00:00
|
|
|
partitions="$(grep -v "loop\|ram" < /proc/diskstats |\
|
|
|
|
sed 's/\(\s\+[0-9]\+\)\+\s\+//;s/ .*//;s/^/\/dev\//')"
|
|
|
|
echo "$partitions" | while read -r partition; do
|
|
|
|
case "$(kpartx -l "$partition" 2>/dev/null | wc -l)" in
|
2018-10-10 18:11:20 +00:00
|
|
|
2)
|
2018-11-02 00:15:41 +00:00
|
|
|
echo "Mount subpartitions of $partition"
|
|
|
|
kpartx -afs "$partition"
|
2018-10-10 18:11:20 +00:00
|
|
|
# Ensure that this was the *correct* subpartition
|
|
|
|
# Some devices have mmc partitions that appear to have
|
|
|
|
# subpartitions, but aren't our subpartition.
|
|
|
|
if blkid | grep -q "pmOS_boot"; then
|
|
|
|
break
|
|
|
|
fi
|
2018-11-02 00:15:41 +00:00
|
|
|
kpartx -d "$partition"
|
2018-10-10 18:11:20 +00:00
|
|
|
continue
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
continue
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
attempt_count=$(( attempt_count + 1 ));
|
|
|
|
if [ "$attempt_count" -gt "100" ]; then
|
|
|
|
echo "ERROR: failed to mount subpartitions!"
|
|
|
|
return;
|
|
|
|
fi
|
|
|
|
sleep 0.1;
|
2017-05-26 20:26:25 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
find_root_partition() {
|
|
|
|
# The partition layout is one of the following:
|
|
|
|
# a) boot, root partitions on sdcard
|
|
|
|
# b) boot, root partition on the "system" partition (which has its
|
|
|
|
# own partition header! so we have partitions on partitions!)
|
|
|
|
#
|
|
|
|
# mount_subpartitions() must get executed before calling
|
|
|
|
# find_root_partition(), so partitions from b) also get found.
|
|
|
|
|
2019-11-19 23:23:40 +00:00
|
|
|
# Short circuit all autodetection logic if pmos_root= is supplied
|
|
|
|
# on the kernel cmdline
|
|
|
|
# shellcheck disable=SC2013
|
2020-02-10 21:23:07 +00:00
|
|
|
if [ "$ROOT_PARTITION_UNLOCKED" = 0 ]; then
|
|
|
|
for x in $(cat /proc/cmdline); do
|
|
|
|
[ "$x" = "${x#pmos_root=}" ] && continue
|
|
|
|
DEVICE="${x#pmos_root=}"
|
|
|
|
done
|
2020-06-01 09:02:49 +00:00
|
|
|
|
|
|
|
# On-device installer: before postmarketOS is installed,
|
|
|
|
# we want to use the installer partition as root. It is the
|
|
|
|
# partition behind pmos_root. pmos_root will either point to
|
|
|
|
# reserved space, or to an unfinished installation.
|
|
|
|
# p1: boot
|
|
|
|
# p2: (reserved space) <--- pmos_root
|
|
|
|
# p3: pmOS_install
|
|
|
|
# Details: https://postmarketos.org/on-device-installer
|
|
|
|
if [ -n "$DEVICE" ]; then
|
|
|
|
next="$(echo "$DEVICE" | sed 's/2$/3/')"
|
|
|
|
|
|
|
|
# If the next partition is labeled pmOS_install (and
|
|
|
|
# not pmOS_deleteme), then postmarketOS is not
|
|
|
|
# installed yet.
|
|
|
|
if blkid | grep "$next" | grep -q pmOS_install; then
|
|
|
|
DEVICE="$next"
|
|
|
|
fi
|
|
|
|
fi
|
2020-02-10 21:23:07 +00:00
|
|
|
fi
|
2019-11-19 23:23:40 +00:00
|
|
|
|
2017-10-14 18:10:12 +00:00
|
|
|
# Try partitions in /dev/mapper and /dev/dm-* first
|
2019-11-19 23:23:40 +00:00
|
|
|
if [ -z "$DEVICE" ]; then
|
2020-06-01 09:02:49 +00:00
|
|
|
for id in pmOS_install pmOS_root crypto_LUKS; do
|
2019-11-19 23:23:40 +00:00
|
|
|
for path in /dev/mapper /dev/dm; do
|
|
|
|
DEVICE="$(blkid | grep "$path" | grep "$id" \
|
|
|
|
| cut -d ":" -f 1 | head -n 1)"
|
|
|
|
[ -z "$DEVICE" ] || break 2
|
|
|
|
done
|
2017-10-14 18:10:12 +00:00
|
|
|
done
|
2019-11-19 23:23:40 +00:00
|
|
|
fi
|
2017-06-22 17:34:51 +00:00
|
|
|
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
# Then try all devices
|
2017-06-22 17:34:51 +00:00
|
|
|
if [ -z "$DEVICE" ]; then
|
2020-06-01 09:02:49 +00:00
|
|
|
for id in pmOS_install pmOS_root crypto_LUKS; do
|
2019-11-19 23:23:40 +00:00
|
|
|
DEVICE="$(blkid | grep "$id" | cut -d ":" -f 1 \
|
|
|
|
| head -n 1)"
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
[ -z "$DEVICE" ] || break
|
|
|
|
done
|
2017-06-22 17:34:51 +00:00
|
|
|
fi
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
echo "$DEVICE"
|
|
|
|
}
|
2017-06-22 17:34:51 +00:00
|
|
|
|
2017-07-28 18:51:21 +00:00
|
|
|
find_boot_partition() {
|
2019-11-19 23:23:40 +00:00
|
|
|
# shellcheck disable=SC2013
|
|
|
|
for x in $(cat /proc/cmdline); do
|
|
|
|
[ "$x" = "${x#pmos_boot=}" ] && continue
|
|
|
|
echo "${x#pmos_boot=}"
|
|
|
|
return
|
|
|
|
done
|
2017-07-28 18:51:21 +00:00
|
|
|
findfs LABEL="pmOS_boot"
|
|
|
|
}
|
|
|
|
|
|
|
|
mount_boot_partition() {
|
|
|
|
partition=$(find_boot_partition)
|
|
|
|
if [ -z "$partition" ]; then
|
|
|
|
echo "ERROR: boot partition not found!"
|
|
|
|
show_splash /splash-noboot.ppm.gz
|
|
|
|
loop_forever
|
|
|
|
fi
|
2017-08-03 16:01:00 +00:00
|
|
|
echo "Mount boot partition ($partition)"
|
2017-08-24 21:07:36 +00:00
|
|
|
mount -r "$partition" /boot
|
2017-07-28 18:51:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# $1: initramfs-extra path
|
|
|
|
extract_initramfs_extra() {
|
|
|
|
initramfs_extra="$1"
|
|
|
|
if [ ! -e "$initramfs_extra" ]; then
|
|
|
|
echo "ERROR: initramfs-extra not found!"
|
|
|
|
show_splash /splash-noinitramfsextra.ppm.gz
|
|
|
|
loop_forever
|
|
|
|
fi
|
2017-08-03 16:01:00 +00:00
|
|
|
echo "Extract $initramfs_extra"
|
2017-07-28 18:51:21 +00:00
|
|
|
gzip -d -c "$initramfs_extra" | cpio -i
|
|
|
|
}
|
|
|
|
|
2017-08-03 16:01:00 +00:00
|
|
|
wait_root_partition() {
|
|
|
|
while [ -z "$(find_root_partition)" ]; do
|
2018-07-15 21:41:31 +00:00
|
|
|
show_splash /splash-norootfs.ppm.gz
|
|
|
|
echo "Could not find the rootfs."
|
2017-08-03 16:01:00 +00:00
|
|
|
echo "Maybe you need to insert the sdcard, if your device has"
|
|
|
|
echo "any? Trying again in one second..."
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
resize_root_partition() {
|
|
|
|
partition=$(find_root_partition)
|
2020-06-01 09:02:49 +00:00
|
|
|
|
|
|
|
# Do not resize the installer partition
|
|
|
|
if blkid "$partition" | grep -q pmOS_install; then
|
|
|
|
echo "Resize root partition: skipped (on-device installer)"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2017-08-03 16:01:00 +00:00
|
|
|
# Only resize the partition if it's inside the device-mapper, which means
|
|
|
|
# that the partition is stored as a subpartition inside another one.
|
2019-10-10 17:09:49 +00:00
|
|
|
# In this case we want to resize it to use all the unused space of the
|
2017-08-03 16:01:00 +00:00
|
|
|
# external partition.
|
|
|
|
if [ -z "${partition##"/dev/mapper/"*}" ]; then
|
|
|
|
# Get physical device
|
|
|
|
partition_dev=$(dmsetup deps -o devname "$partition" | \
|
|
|
|
awk -F "[()]" '{print "/dev/"$2}')
|
|
|
|
# Check if there is unallocated space at the end of the device
|
|
|
|
if parted -s "$partition_dev" print free | tail -n2 | \
|
|
|
|
head -n1 | grep -qi "free space"; then
|
|
|
|
echo "Resize root partition ($partition)"
|
|
|
|
# unmount subpartition, resize and remount it
|
|
|
|
kpartx -d "$partition"
|
|
|
|
parted -s "$partition_dev" resizepart 2 100%
|
|
|
|
kpartx -afs "$partition_dev"
|
|
|
|
fi
|
|
|
|
fi
|
2017-11-04 22:54:42 +00:00
|
|
|
# Resize the root partition (non-subpartitions). Usually we do not want this,
|
|
|
|
# except for QEMU devices (where PMOS_FORCE_PARTITION_RESIZE gets passed as
|
|
|
|
# kernel parameter).
|
|
|
|
if grep -q PMOS_FORCE_PARTITION_RESIZE /proc/cmdline; then
|
2017-08-18 22:39:32 +00:00
|
|
|
echo "Resize root partition ($partition)"
|
2017-11-04 22:54:42 +00:00
|
|
|
parted -s "$(echo "$partition" | sed -E 's/p?2$//')" resizepart 2 100%
|
2017-08-18 22:39:32 +00:00
|
|
|
partprobe
|
|
|
|
fi
|
2017-08-03 16:01:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unlock_root_partition() {
|
|
|
|
partition="$(find_root_partition)"
|
|
|
|
if cryptsetup isLuks "$partition"; then
|
|
|
|
until cryptsetup status root | grep -qwi active; do
|
2017-10-14 18:10:12 +00:00
|
|
|
start_onscreen_keyboard
|
2017-08-03 16:01:00 +00:00
|
|
|
done
|
2020-02-10 21:23:07 +00:00
|
|
|
ROOT_PARTITION_UNLOCKED=1
|
2017-08-03 16:01:00 +00:00
|
|
|
# Show again the loading splashscreen
|
|
|
|
show_splash /splash-loading.ppm.gz
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
resize_root_filesystem() {
|
|
|
|
partition="$(find_root_partition)"
|
|
|
|
touch /etc/mtab # see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=673323
|
|
|
|
echo "Check/repair root filesystem ($partition)"
|
2019-11-05 18:28:30 +00:00
|
|
|
e2fsck -y "$partition"
|
2017-08-03 16:01:00 +00:00
|
|
|
echo "Resize root filesystem ($partition)"
|
|
|
|
resize2fs -f "$partition"
|
|
|
|
}
|
|
|
|
|
|
|
|
mount_root_partition() {
|
|
|
|
partition="$(find_root_partition)"
|
|
|
|
echo "Mount root partition ($partition)"
|
2017-09-30 21:52:33 +00:00
|
|
|
mount -t ext4 -o ro "$partition" /sysroot
|
2017-08-03 16:01:00 +00:00
|
|
|
if ! [ -e /sysroot/usr ]; then
|
|
|
|
echo "ERROR: unable to mount root partition!"
|
|
|
|
show_splash /splash-mounterror.ppm.gz
|
|
|
|
loop_forever
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
setup_usb_network_android() {
|
|
|
|
# Only run, when we have the android usb driver
|
|
|
|
SYS=/sys/class/android_usb/android0
|
2019-06-27 12:02:20 +00:00
|
|
|
if ! [ -e "$SYS" ]; then
|
|
|
|
echo " /sys/class/android_usb does not exist, skipping android_usb"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo " Setting up an USB gadget through android_usb"
|
2017-06-22 17:34:51 +00:00
|
|
|
|
2019-11-10 17:20:28 +00:00
|
|
|
usb_idVendor="$(echo "${deviceinfo_usb_idVendor:-0x18D1}" | sed "s/0x//g")" # default: Google Inc.
|
|
|
|
usb_idProduct="$(echo "${deviceinfo_usb_idProduct:-0xD001}" | sed "s/0x//g")" # default: Nexus 4 (fastboot)
|
|
|
|
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
# Do the setup
|
2019-11-10 17:20:28 +00:00
|
|
|
echo "0" >"$SYS/enable"
|
|
|
|
echo "$usb_idVendor" >"$SYS/idVendor"
|
|
|
|
echo "$usb_idProduct" >"$SYS/idProduct"
|
|
|
|
echo "rndis" >"$SYS/functions"
|
|
|
|
echo "1" >"$SYS/enable"
|
2017-05-26 20:26:25 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 15:17:48 +00:00
|
|
|
setup_usb_network_configfs() {
|
2019-09-12 15:18:19 +00:00
|
|
|
# See: https://www.kernel.org/doc/Documentation/usb/gadget_configfs.txt
|
2017-07-13 15:17:48 +00:00
|
|
|
CONFIGFS=/config/usb_gadget
|
|
|
|
|
2019-06-27 12:02:20 +00:00
|
|
|
if ! [ -e "$CONFIGFS" ]; then
|
|
|
|
echo " /config/usb_gadget does not exist, skipping configfs usb gadget"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2019-09-12 15:18:19 +00:00
|
|
|
# Default values for USB-related deviceinfo variables
|
|
|
|
usb_idVendor="${deviceinfo_usb_idVendor:-0x18D1}" # default: Google Inc.
|
|
|
|
usb_idProduct="${deviceinfo_usb_idProduct:-0xD001}" # default: Nexus 4 (fastboot)
|
|
|
|
usb_serialnumber="${deviceinfo_usb_serialnumber:-postmarketOS}"
|
|
|
|
usb_rndis_function="${deviceinfo_usb_rndis_function:-rndis.usb0}"
|
|
|
|
|
2019-06-27 12:02:20 +00:00
|
|
|
echo " Setting up an USB gadget through configfs"
|
|
|
|
# Create an usb gadet configuration
|
|
|
|
mkdir $CONFIGFS/g1 || echo " Couldn't create $CONFIGFS/g1"
|
2019-09-12 15:18:19 +00:00
|
|
|
echo "$usb_idVendor" > "$CONFIGFS/g1/idVendor"
|
|
|
|
echo "$usb_idProduct" > "$CONFIGFS/g1/idProduct"
|
2017-07-13 15:17:48 +00:00
|
|
|
|
2019-06-27 12:02:20 +00:00
|
|
|
# Create english (0x409) strings
|
|
|
|
mkdir $CONFIGFS/g1/strings/0x409 || echo " Couldn't create $CONFIGFS/g1/strings/0x409"
|
|
|
|
|
2019-09-12 15:18:19 +00:00
|
|
|
# shellcheck disable=SC2154
|
|
|
|
echo "$deviceinfo_manufacturer" > "$CONFIGFS/g1/strings/0x409/manufacturer"
|
|
|
|
echo "$usb_serialnumber" > "$CONFIGFS/g1/strings/0x409/serialnumber"
|
|
|
|
# shellcheck disable=SC2154
|
|
|
|
echo "$deviceinfo_name" > "$CONFIGFS/g1/strings/0x409/product"
|
|
|
|
|
|
|
|
# Create rndis function. The function can be named differently in downstream kernels.
|
|
|
|
mkdir $CONFIGFS/g1/functions/"$usb_rndis_function" \
|
|
|
|
|| echo " Couldn't create $CONFIGFS/g1/functions/$usb_rndis_function"
|
2017-07-13 15:17:48 +00:00
|
|
|
|
2019-06-27 12:02:20 +00:00
|
|
|
# Create configuration instance for the gadget
|
2019-09-12 15:18:19 +00:00
|
|
|
mkdir $CONFIGFS/g1/configs/c.1 \
|
|
|
|
|| echo " Couldn't create $CONFIGFS/g1/configs/c.1"
|
|
|
|
mkdir $CONFIGFS/g1/configs/c.1/strings/0x409 \
|
|
|
|
|| echo " Couldn't create $CONFIGFS/g1/configs/c.1/strings/0x409"
|
|
|
|
echo "rndis" > $CONFIGFS/g1/configs/c.1/strings/0x409/configuration \
|
|
|
|
|| echo " Couldn't write configration name"
|
2017-07-13 15:17:48 +00:00
|
|
|
|
2019-06-27 12:02:20 +00:00
|
|
|
# Link the rndis instance to the configuration
|
2019-09-12 15:18:19 +00:00
|
|
|
ln -s $CONFIGFS/g1/functions/"$usb_rndis_function" $CONFIGFS/g1/configs/c.1 \
|
|
|
|
|| echo " Couldn't symlink $usb_rndis_function"
|
2017-07-13 15:17:48 +00:00
|
|
|
|
2019-06-27 12:02:20 +00:00
|
|
|
# Check if there's an USB Device Controller
|
|
|
|
if [ -z "$(ls /sys/class/udc)" ]; then
|
|
|
|
echo " No USB Device Controller available"
|
|
|
|
return
|
|
|
|
fi
|
2017-08-09 20:30:41 +00:00
|
|
|
|
2019-09-12 15:18:19 +00:00
|
|
|
# Link the gadget instance to an USB Device Controller. This activates the gadget.
|
2019-06-27 12:02:20 +00:00
|
|
|
# See also: https://github.com/postmarketOS/pmbootstrap/issues/338
|
2017-08-09 20:30:41 +00:00
|
|
|
# shellcheck disable=SC2005
|
2019-06-27 12:02:20 +00:00
|
|
|
echo "$(ls /sys/class/udc)" > $CONFIGFS/g1/UDC || echo " Couldn't write UDC"
|
2017-07-13 15:17:48 +00:00
|
|
|
}
|
|
|
|
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
setup_usb_network() {
|
|
|
|
# Only run once
|
|
|
|
_marker="/tmp/_setup_usb_network"
|
|
|
|
[ -e "$_marker" ] && return
|
|
|
|
touch "$_marker"
|
2017-08-03 16:01:00 +00:00
|
|
|
echo "Setup usb network"
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
# Run all usb network setup functions (add more below!)
|
|
|
|
setup_usb_network_android
|
2017-07-13 15:17:48 +00:00
|
|
|
setup_usb_network_configfs
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
start_udhcpd() {
|
|
|
|
# Only run once
|
|
|
|
[ -e /etc/udhcpd.conf ] && return
|
|
|
|
|
2018-06-21 21:10:12 +00:00
|
|
|
# Skip if disabled
|
|
|
|
# shellcheck disable=SC2154
|
|
|
|
if [ "$deviceinfo_disable_dhcpd" = "true" ]; then
|
|
|
|
echo "NOTE: start of dhcpd is disabled (deviceinfo_disable_dhcpd)"
|
|
|
|
touch /etc/udhcpcd.conf
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2019-06-27 12:02:20 +00:00
|
|
|
echo "Starting udhcpd"
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
# Get usb interface
|
|
|
|
INTERFACE=""
|
2019-06-27 12:02:20 +00:00
|
|
|
ifconfig rndis0 "$IP" 2>/dev/null && INTERFACE=rndis0
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
if [ -z $INTERFACE ]; then
|
2019-06-27 12:02:20 +00:00
|
|
|
ifconfig usb0 "$IP" 2>/dev/null && INTERFACE=usb0
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
fi
|
2017-12-23 19:22:28 +00:00
|
|
|
if [ -z $INTERFACE ]; then
|
2019-06-27 12:02:20 +00:00
|
|
|
ifconfig eth0 "$IP" 2>/dev/null && INTERFACE=eth0
|
2017-12-23 19:22:28 +00:00
|
|
|
fi
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
|
2019-06-27 12:02:20 +00:00
|
|
|
if [ -z $INTERFACE ]; then
|
|
|
|
echo " Could not find an interface to run a dhcp server on"
|
|
|
|
echo " Interfaces:"
|
|
|
|
ip link
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo " Using interface $INTERFACE"
|
|
|
|
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
# Create /etc/udhcpd.conf
|
|
|
|
{
|
|
|
|
echo "start 172.16.42.2"
|
2017-09-23 14:23:38 +00:00
|
|
|
echo "end 172.16.42.2"
|
|
|
|
echo "auto_time 0"
|
|
|
|
echo "decline_time 0"
|
|
|
|
echo "conflict_time 0"
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
echo "lease_file /var/udhcpd.leases"
|
|
|
|
echo "interface $INTERFACE"
|
|
|
|
echo "option subnet 255.255.255.0"
|
|
|
|
} >/etc/udhcpd.conf
|
|
|
|
|
2019-06-27 12:02:20 +00:00
|
|
|
echo " Start the dhcpcd daemon (forks into background)"
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
udhcpd
|
|
|
|
}
|
|
|
|
|
2020-01-02 04:12:20 +00:00
|
|
|
setup_directfb_tslib() {
|
2018-03-05 22:59:23 +00:00
|
|
|
# Set up directfb and tslib
|
2017-10-14 18:10:12 +00:00
|
|
|
# Note: linux_input module is disabled since it will try to take over
|
|
|
|
# the touchscreen device from tslib (e.g. on the N900)
|
|
|
|
export DFBARGS="system=fbdev,no-cursor,disable-module=linux_input"
|
|
|
|
# shellcheck disable=SC2154
|
2019-09-26 19:25:44 +00:00
|
|
|
if [ -n "$deviceinfo_dev_touchscreen" ]; then
|
2017-10-14 18:10:12 +00:00
|
|
|
export TSLIB_TSDEVICE="$deviceinfo_dev_touchscreen"
|
|
|
|
fi
|
2018-03-05 22:59:23 +00:00
|
|
|
}
|
|
|
|
|
2020-01-02 04:12:20 +00:00
|
|
|
start_onscreen_keyboard() {
|
2018-03-05 22:59:23 +00:00
|
|
|
setup_directfb_tslib
|
2017-10-14 18:10:12 +00:00
|
|
|
osk-sdl -n root -d "$partition" -c /etc/osk.conf -v > /osk-sdl.log 2>&1
|
|
|
|
unset DFBARGS
|
|
|
|
unset TSLIB_TSDEVICE
|
2017-07-28 18:51:21 +00:00
|
|
|
}
|
|
|
|
|
2020-01-02 04:12:20 +00:00
|
|
|
start_charging_mode() {
|
2018-03-05 22:59:23 +00:00
|
|
|
# Check cmdline for charging mode
|
|
|
|
chargingmodes="
|
|
|
|
androidboot.mode=charger
|
|
|
|
lpm_boot=1
|
|
|
|
androidboot.huawei_type=oem_rtc
|
|
|
|
startup=0x00010004
|
2018-06-01 10:36:05 +00:00
|
|
|
lpcharge=1
|
2018-07-20 05:04:13 +00:00
|
|
|
androidboot.bootchg=true
|
2018-03-05 22:59:23 +00:00
|
|
|
"
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
grep -Eq "$(echo $chargingmodes | tr ' ' '|')" /proc/cmdline || return
|
|
|
|
setup_directfb_tslib
|
|
|
|
# Get the font from osk-sdl config
|
|
|
|
fontpath=$(awk '/^keyboard-font/{print $3}' /etc/osk.conf)
|
|
|
|
# Set up triggerhappy config
|
|
|
|
{
|
|
|
|
echo "KEY_POWER 1 pgrep -x charging-sdl || charging-sdl -pcf $fontpath"
|
|
|
|
} >/etc/triggerhappy.conf
|
|
|
|
# Start it once and then start triggerhappy
|
2018-08-05 14:18:28 +00:00
|
|
|
(
|
|
|
|
charging-sdl -pcf "$fontpath" \
|
|
|
|
|| show_splash /splash-charging-error.ppm.gz
|
|
|
|
) &
|
2018-03-05 22:59:23 +00:00
|
|
|
thd --deviceglob /dev/input/event* --triggers /etc/triggerhappy.conf
|
|
|
|
}
|
|
|
|
|
2017-05-26 20:26:25 +00:00
|
|
|
# $1: path to ppm.gz file
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
show_splash() {
|
2018-12-19 01:13:31 +00:00
|
|
|
# Skip for non-framebuffer devices
|
|
|
|
# shellcheck disable=SC2154
|
|
|
|
if [ "$deviceinfo_no_framebuffer" = "true" ]; then
|
|
|
|
echo "NOTE: Skipping framebuffer splashscreen (deviceinfo_no_framebuffer)"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
postmarketos-mkinitfs: Major refactoring
* rewrote find_root_partition to make it compatible with the i9100
again (and added a big description comment about how it works)
* usb network and dhcp server gets started independent of hooks
now. this really makes sense for development now, we can disable
this later (and set up networking via OpenRC, when the usb-shell
hook is not installed)
* telnet splash + unlock telnetd code only runs, when the rootfs
is encrypted
* usb_setup_android wrapped with a generic usb_setup function, so
we can support networking for more device types in a clean way
* the IP of the device is now in init_functions.sh, and init_functions.sh
gets included in all hooks.
* rewrote logging function. it logs all stdout and stderr to
/pmOS_init.log, except when PMOS_NO_OUTPUT_REDIRECT is specified
as kernel command line. This way we can see error output from
all commands.
* used shfmt to format everything, so it looks consistent again
* added automatic shellchecking for init.sh.in and
init_functions.sh
* clear naming scheme for initfs functions, they all start with a
verb now (e.g. setup_usb_network, start_udhcpd, ...)
2017-06-28 15:32:16 +00:00
|
|
|
gzip -c -d "$1" >/tmp/splash.ppm
|
2017-05-26 20:26:25 +00:00
|
|
|
fbsplash -s /tmp/splash.ppm
|
|
|
|
}
|
2017-07-19 18:05:34 +00:00
|
|
|
|
2017-09-29 15:22:20 +00:00
|
|
|
set_framebuffer_mode() {
|
|
|
|
[ -e "/sys/class/graphics/fb0/modes" ] || return
|
|
|
|
[ -z "$(cat /sys/class/graphics/fb0/mode)" ] || return
|
|
|
|
|
|
|
|
_mode="$(cat /sys/class/graphics/fb0/modes)"
|
|
|
|
echo "Setting framebuffer mode to: $_mode"
|
|
|
|
echo "$_mode" > /sys/class/graphics/fb0/mode
|
|
|
|
}
|
|
|
|
|
2018-10-10 18:11:20 +00:00
|
|
|
setup_framebuffer() {
|
|
|
|
# Skip for non-framebuffer devices
|
|
|
|
# shellcheck disable=SC2154
|
|
|
|
if [ "$deviceinfo_no_framebuffer" = "true" ]; then
|
2018-12-19 01:13:31 +00:00
|
|
|
echo "NOTE: Skipping framebuffer setup (deviceinfo_no_framebuffer)"
|
2018-10-10 18:11:20 +00:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Wait for /dev/fb0
|
|
|
|
echo "NOTE: Waiting 10 seconds for the framebuffer /dev/fb0."
|
|
|
|
echo "If your device does not have a framebuffer, disable this with:"
|
|
|
|
echo "no_framebuffer=true in <https://postmarketos.org/deviceinfo>"
|
2018-11-02 00:15:41 +00:00
|
|
|
for _ in $(seq 1 100); do
|
2018-10-10 18:11:20 +00:00
|
|
|
[ -e "/dev/fb0" ] && break
|
|
|
|
sleep 0.1
|
|
|
|
done
|
|
|
|
if ! [ -e "/dev/fb0" ]; then
|
|
|
|
echo "ERROR: /dev/fb0 did not appear!"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
set_framebuffer_mode
|
|
|
|
}
|
|
|
|
|
2020-01-02 04:12:20 +00:00
|
|
|
setup_bootchart2() {
|
|
|
|
if grep -q PMOS_BOOTCHART2 /proc/cmdline; then
|
|
|
|
if [ -f "/sysroot/sbin/bootchartd" ]; then
|
|
|
|
# shellcheck disable=SC2034
|
|
|
|
init="/sbin/bootchartd"
|
|
|
|
echo "remounting /sysroot as rw for /sbin/bootchartd"
|
|
|
|
mount -o remount, rw /sysroot
|
|
|
|
|
|
|
|
# /dev/null may not exist at the first boot after
|
|
|
|
# the root filesystem has been created.
|
|
|
|
[ -c /sysroot/dev/null ] && return
|
|
|
|
echo "creating /sysroot/dev/null for /sbin/bootchartd"
|
|
|
|
mknod -m 666 "/sysroot/dev/null" c 1 3
|
|
|
|
else
|
|
|
|
echo "WARNING: bootchart2 is not installed."
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-07-28 18:51:21 +00:00
|
|
|
loop_forever() {
|
|
|
|
while true; do
|
|
|
|
sleep 1
|
|
|
|
done
|
2017-07-19 18:05:34 +00:00
|
|
|
}
|