From 9f4453a4d21a596eeff4be89b2782fcad5fb18a4 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Wed, 13 Jun 2018 01:47:00 +0000 Subject: [PATCH] Reviews start of init script. --- bootimg.nix | 8 +++--- devices/asus-z00t/default.nix | 12 ++++++++- rootfs.nix | 47 +++++++++++++++++------------------ 3 files changed, 39 insertions(+), 28 deletions(-) diff --git a/bootimg.nix b/bootimg.nix index 5df5f1ef..4b1c362e 100644 --- a/bootimg.nix +++ b/bootimg.nix @@ -1,10 +1,12 @@ { device_name }: -with (import ./overlay); - let - device_config = import (./devices + ("/" + device_name)) {inherit lib;}; + pkgs = (import ./overlay); +in +with pkgs; +let + device_config = import (./devices + ("/" + device_name)) {inherit pkgs lib;}; linux = pkgs."linux_${device_name}"; kernel = "${linux}/Image.gz-dtb"; dt = "${linux}/boot/dt.img"; diff --git a/devices/asus-z00t/default.nix b/devices/asus-z00t/default.nix index 1dea9fc3..837f59de 100644 --- a/devices/asus-z00t/default.nix +++ b/devices/asus-z00t/default.nix @@ -1,12 +1,22 @@ { + pkgs, lib, + ... }: let config = (lib.importJSON ../postmarketOS-devices.json).asus-z00t; in config // { name = config.pm_name; - rootfs = { + stage-1 = { fb_modes = ./fb.modes; + packages = with pkgs; [ + strace + msm-fb-refresher + ]; + initFramebuffer = '' + msm-fb-refresher --loop & + echo 10 > /sys/class/leds/lcd-backlight/brightness + ''; }; } diff --git a/rootfs.nix b/rootfs.nix index 1f00751c..cec0195b 100644 --- a/rootfs.nix +++ b/rootfs.nix @@ -10,8 +10,6 @@ busybox, glibc, - strace, - msm-fb-refresher, dropbear, fbv, lib, @@ -19,16 +17,20 @@ }: let + inherit (lib) optionalString optionals optional; + + stage-1 = if device_config ? stage-1 then device_config.stage-1 else {}; + device_name = device_config.name; extraUtils = mkExtraUtils { name = device_name; packages = [ busybox - msm-fb-refresher fbv - strace { package = dropbear; extraCommand = "cp -pv ${glibc.out}/lib/libnss_files.so.* $out/lib"; } - ]; + ] + ++ optionals (stage-1 ? packages) stage-1.packages + ; }; shell = "${extraUtils}/bin/ash"; @@ -38,54 +40,51 @@ let export PATH=${extraUtils}/bin/ export LD_LIBRARY_PATH=${extraUtils}/lib - mkdir -p /proc /sys /dev /etc/udev /tmp /run/ /lib/ /mnt/ /var/log /etc/plymouth /bin + mkdir -p /bin + ln -sv ${shell} /bin/sh + + mkdir -p /proc /sys /dev /etc/udev /tmp /run/ /lib/ /mnt/ /var/log /etc mount -t devtmpfs devtmpfs /dev/ mount -t proc proc /proc mount -t sysfs sysfs /sys - # Some things will like having /etc/. - mkdir -p /etc + # /dev/pts (needed for ssh or telnet) + mkdir -p /dev/pts + mount -t devpts devpts /dev/pts show_splash() { - echo | fbv -afeci /$1.png > /dev/null 2>&1 + echo | fbv -cafei /$1.png > /dev/null 2>&1 } set_framebuffer_mode() { + # Uses the first defined mode if [ -e /etc/fb.modes ]; then - # Uses the first defined mode fbset $(grep ^mode /etc/fb.modes | head -n1 | cut -d'"' -f2) else [ -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 fi - } - echo 1 > /sys/class/leds/lcd-backlight/brightness + ${ + # Start tools like msm-fb-refresher + lib.optionalString (stage-1 ? initFramebuffer) stage-1.initFramebuffer + } + } set_framebuffer_mode show_splash loading - set_framebuffer_mode - - msm-fb-refresher --loop & - - ln -sv ${shell} /bin/sh - loop_forever() { while true; do sleep 3600 done } - # /dev/pts (needed for telnet) - mkdir -p /dev/pts - mount -t devpts devpts /dev/pts - IP=172.16.42.1 TELNET_PORT=23 @@ -201,7 +200,7 @@ let { object = ./temp-splash.png; symlink = "/splash.png"; } { object = ./loading.png; symlink = "/loading.png"; } ] - ++ lib.optional (device_config ? rootfs.fb_modes) { object = device_config.rootfs.fb_modes; symlink = "/etc/fb.modes"; } + ++ optional (stage-1 ? fb_modes) { object = stage-1.fb_modes; symlink = "/etc/fb.modes"; } ; }; in