about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMalte Voos <git@mal.tc>2024-12-20 23:19:18 +0100
committerMalte Voos <git@mal.tc>2024-12-20 23:19:18 +0100
commitc3a8e89a4bfab3c64c94fc6df42e94b231be4bff (patch)
treebe996179c9862c01e845a023fca5ad47d19a310f
parent806dc1ed43be0e638fc1d60881afdae812d0e4e6 (diff)
downloadreMder-c3a8e89a4bfab3c64c94fc6df42e94b231be4bff.tar.gz
reMder-c3a8e89a4bfab3c64c94fc6df42e94b231be4bff.zip
initial attempt at rmpp emulation
-rw-r--r--flake.nix12
-rw-r--r--server.nix76
2 files changed, 57 insertions, 31 deletions
diff --git a/flake.nix b/flake.nix
index 97a3723..27a4a38 100644
--- a/flake.nix
+++ b/flake.nix
@@ -19,13 +19,13 @@
           inherit sshPassword sshPort httpPort;
         };
 
-        # reMder = pkgs.symlinkJoin {
-        #   name = "reMder";
-        #   paths = [ client server ];
-        # };
+        reMder = pkgs.symlinkJoin {
+          name = "reMder";
+          paths = [ client server ];
+        };
       in {
-        packages = { inherit server; };
+        packages = { inherit reMder; };
 
-        # defaultPackage = reMder;
+        defaultPackage = reMder;
       });
 }
diff --git a/server.nix b/server.nix
index 31462cd..906e2c6 100644
--- a/server.nix
+++ b/server.nix
@@ -1,5 +1,5 @@
-{ fetchurl, writeText, libguestfs-with-appliance, pkgsCross, qemu, runCommand
-, writeShellApplication, sshPassword, sshPort, httpPort }:
+{ lib, fetchurl, writeText, libguestfs-with-appliance, pkgsCross, qemu
+, runCommand, cpio, writeShellApplication, sshPassword, sshPort, httpPort }:
 let
   updateName = "remarkable-ct-prototype-image-3.16.1.0-ferrari-public";
 
@@ -7,7 +7,7 @@ let
     url =
       # TODO: this is not an official source. might be worth authenticating the updates
       "https://storage.googleapis.com/remarkable-versions/${updateName}.swu";
-    hash = "";
+    hash = "sha256-cwx2qcvxZBX0wAprYKls8P+gthwJJQTceVIO+qdPm/w=";
   };
 
   xochitlConfig = writeText "xochitl.conf" ''
@@ -42,14 +42,16 @@ let
     WantedBy=multi-user.target
   '';
 
-  fakefbdev = pkgsCross.remarkable2.gcc11Stdenv.mkDerivation {
+  fakefbdev = pkgsCross.aarch64-multiplatform.gcc11Stdenv.mkDerivation {
     name = "fakefbdev";
     src = ./fakefbdev;
 
     installFlags = [ "DESTDIR=${placeholder "out"}" ];
   };
 
-  rootfsImage = runCommand "rm-rootfs.ext4" ''
+  kernel = pkgsCross.aarch64-multiplatform.linux;
+
+  rootfsImage = runCommand "rm-rootfs.ext4" { nativeBuildInputs = [ cpio ]; } ''
     cpio -i --file ${updateArchive}
     gzip -dc ${updateName}.ext4.verity.gz > $out
   '';
@@ -62,35 +64,62 @@ let
     guestfish --rw --blocksize=512 --add $out <<EOF
     run
 
-    part-init /dev/sda mbr
-    part-add /dev/sda p 2048    43007
-    part-add /dev/sda p 43008   595967
-    part-add /dev/sda p 595968  1148927
-    part-add /dev/sda p 1148928 14942207
+    # not the original partition table of the RMPP
+    part-init /dev/sda gpt
+    part-add /dev/sda p     2048  2099199
+    part-add /dev/sda p  2099200 10487807
+    part-add /dev/sda p 10487808 12584959
+    part-add /dev/sda p 12584960 16775167
 
-    mkfs vfat /dev/sda1
+    mkfs ext4 /dev/sda1
     upload ${rootfsImage} /dev/sda2
-    mkfs ext4 /dev/sda3
+    resize2fs /dev/sda2
+    mkswap /dev/sda3
     mkfs ext4 /dev/sda4
 
     mount /dev/sda2 /
 
+    copy-in ${kernel}/lib/modules /lib
+
     download /etc/fstab fstab
-    ! sed -i 's/mmcblk2p/vda/' fstab
+    ! sed -i 's#mmcblk0p1#vda1#' fstab
+    ! sed -i 's#/dev/mapper/home-encrypted-disk#/dev/vda4#' fstab
     upload fstab /etc/fstab
 
+    download /etc/passwd passwd
+    ! sed -i 's#/usr/sbin/rmdevlogin#/bin/sh#' passwd
+    upload passwd /etc/passwd
+
+    download /etc/shadow shadow
+    ! sed -i 's/root:!:/root::/' shadow
+    upload shadow /etc/shadow
+
     upload ${ifnameUdevRule} /etc/udev/rules.d/70-persistent-net.rules
 
-    download /lib/systemd/system/dhcpcd.service dhcpcd.service
-    ! sed -i 's/wlan/usb/' dhcpcd.service
-    upload dhcpcd.service /lib/systemd/system/dhcpcd.service
+    # download /lib/systemd/system/dhcpcd.service dhcpcd.service
+    # ! sed -i 's/wlan/usb/' dhcpcd.service
+    # upload dhcpcd.service /lib/systemd/system/dhcpcd.service TODO
 
-    rm /lib/systemd/system/remarkable-fail.service
-    rm /lib/systemd/system/rm-sync.service
     upload ${xochitlService} /lib/systemd/system/xochitl.service
 
-    upload ${fakefbdev}/lib/libfakefbdev.so /usr/lib/libfakefbdev.so
-    chmod 0755 /usr/lib/libfakefbdev.so
+    # delete stuff which hinders boot
+    rm /lib/systemd/system/rm-sync.service
+    rm /lib/systemd/system/xochitl.service.d/xochitl-service-override.conf
+    rm /lib/systemd/system/wpa_supplicant.service
+    rm /lib/systemd/system/dropbear-wlan.socket
+    rm /lib/systemd/system/keystore.service
+    rm /lib/systemd/system/swapcryptor.service
+    rm /lib/systemd/system/homecryptor.service
+    rm /lib/systemd/system/growpart-home.service
+    rm /lib/systemd/system/memfault-attributes.service
+    rm /lib/systemd/system/swupdate.service
+    rm /lib/systemd/system/swupdate.socket
+    rm /lib/systemd/system/usb-ether-once.service
+    rm /lib/systemd/system/marker-manager.service
+    rm /lib/systemd/system/rm-sanity.timer
+
+    # upload ${fakefbdev}/lib/libfakefbdev.so /usr/lib/libfakefbdev.so
+    # chmod 0755 /usr/lib/libfakefbdev.so
 
     mount /dev/sda4 /home
     cp-a /etc/skel /home/root
@@ -102,8 +131,6 @@ let
     EOF
   '';
 
-  kernel = pkgsCross.aarch64-linux.linux_5_4;
-
 in writeShellApplication {
   name = "reMder-server";
 
@@ -117,7 +144,7 @@ in writeShellApplication {
         -machine virt \
         -cpu host \
         -m 2048 \
-        -kernel ${kernel}/zImage \
+        -kernel ${kernel}/Image \
         -drive if=none,file=./reMder.qcow2,format=qcow2,id=hd \
         -device virtio-blk-device,drive=hd \
         -netdev user,hostfwd=tcp::${toString sshPort}-:22,hostfwd=tcp::${
@@ -125,8 +152,7 @@ in writeShellApplication {
         }-:80,id=net \
         -device virtio-net-device,netdev=net,mac=${usbMacAddr} \
         -append "console=ttyAMA0 rootfstype=ext4 root=/dev/vda2 rw rootwait init=/sbin/init" \
-        -serial stdio \
-        -monitor none \
+        -serial mon:stdio \
         -nographic
   '';
 }