about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMalte Voos <git@mal.tc>2024-04-04 16:00:30 +0200
committerMalte Voos <git@mal.tc>2024-04-04 20:48:37 +0200
commit726cc6f8ae68760e1848a57c87f970998ee0201f (patch)
treef6a551120196397cada2c8e8a0d72582f5896e4b
parentc9425bb3f494e215fefab92b6d2dea40deda82a7 (diff)
downloadreMder-726cc6f8ae68760e1848a57c87f970998ee0201f.tar.gz
reMder-726cc6f8ae68760e1848a57c87f970998ee0201f.zip
switch to qemu's "virt" arm board for better performance
-rw-r--r--flake.nix47
1 files changed, 34 insertions, 13 deletions
diff --git a/flake.nix b/flake.nix
index ef60b13..2a92482 100644
--- a/flake.nix
+++ b/flake.nix
@@ -59,6 +59,17 @@
         installFlags = [ "DESTDIR=${placeholder "out"}" ];
       };
 
+      ext4Rootfs = pkgs.runCommand "rm-rootfs.ext4"
+        {
+          nativeBuildInputs = with pkgs; [
+            (python3.withPackages (pypkgs: [ pypkgs.protobuf ]))
+            qemu
+            libguestfs-with-appliance
+          ];
+        } ''
+        python3 ${ddvk-stuff}/extractor/extractor.py ${updateArchive} $out
+      '';
+
       rootfs = pkgs.runCommand "rm-rootfs.qcow2"
         {
           nativeBuildInputs = with pkgs; [
@@ -88,7 +99,7 @@
         mount /dev/sda2 /
 
         download /etc/fstab fstab
-        ! sed -i 's/mmcblk2/mmcblk1/' fstab
+        ! sed -i 's/mmcblk2p/vda/' fstab
         upload fstab /etc/fstab
 
         upload ${ifnameUdevRule} /etc/udev/rules.d/70-persistent-net.rules
@@ -115,7 +126,11 @@
       '';
 
       kernel = pkgs.pkgsCross.armv7l-hf-multiplatform.linux_5_4.override {
-        defconfig = "imx_v6_v7_defconfig";
+        # structuredExtraConfig = with pkgs.lib.kernel; {
+        #   PCI = yes;
+        #   VIRTIO_PCI = yes;
+        #   PCI_HOST_GENERIC = yes;
+        # };
       };
 
       server = pkgs.writeShellApplication {
@@ -126,15 +141,18 @@
         text = ''
           qemu-img create -b ${rootfs} -F qcow2 -f qcow2 ./reMder.qcow2
 
+          # TODO switch to pci virtio devices? (uncomment kernel config above)
           qemu-system-arm \
-              -machine mcimx7d-sabre \
-              -cpu cortex-a9 \
+              -machine virt \
               -m 2048 \
               -kernel ${kernel}/zImage \
-              -dtb ${kernel}/dtbs/imx7d-sbc-imx7.dtb \
-              -drive if=sd,file=./reMder.qcow2,format=qcow2,index=2 \
-              -append "console=ttymxc0 video=vfb: rootfstype=ext4 root=/dev/mmcblk1p2 rw rootwait init=/sbin/init" \
-              -nic user,hostfwd=tcp::${toString sshPort}-:22,hostfwd=tcp::${toString httpPort}-:80,mac=${usbMacAddr} \
+              -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::${toString httpPort}-: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 \
               -nographic
         '';
       };
@@ -157,8 +175,8 @@
 
             in_basename="$(basename "$in")"
 
-            ${ssh} ${guest} rm -rf "${documentDir}"
-            ${ssh} ${guest} mkdir "${documentDir}"
+            ${ssh} ${guest} rm -rf ${documentDir}
+            ${ssh} ${guest} mkdir ${documentDir}
 
             ${scp} "$in" ${guest}:${documentDir} 
             ${ssh} ${guest} unzip "${documentDir}/$in_basename" -d ${documentDir}
@@ -168,14 +186,17 @@
           '';
       };
 
-      package = pkgs.symlinkJoin {
+      reMder = pkgs.symlinkJoin {
         name = "reMder";
         paths = [ client server ];
       };
     in
     {
-      packages.reMder = package;
-      defaultPackage = package;
+      packages = {
+        inherit reMder fakefbdev ext4Rootfs;
+      };
+
+      defaultPackage = reMder;
     }
   );
 }