ubimage.nix (3902B)
1 { 2 config, 3 pkgs, 4 lib, 5 ... 6 }: 7 let 8 inherit (lib) mkIf mkOption types; 9 cfg = config.boot.tftp; 10 instructions = pkgs.writeText "flash.scr" '' 11 setenv serverip ${cfg.serverip} 12 setenv ipaddr ${cfg.ipaddr} 13 setenv loadaddr ${lib.toHexString cfg.loadAddress} 14 tftpboot $loadaddr result/rootfs 15 ubi write $loadaddr liminix $filesize 16 ''; 17 in 18 { 19 options.system.outputs = { 20 ubimage = mkOption { 21 type = types.package; 22 description = '' 23 ubimage 24 ******* 25 26 This output provides a UBIFS filesystem image and a small U-Boot script 27 to make the manual installation process very slightly simpler. You will 28 need a serial connection and a network connection to a TFTP server 29 containing the filesystem image it creates. 30 31 .. warning:: These steps were tested on a Belkin RT3200 (also known as 32 Linksys E8450). Other devices may be set up differently, 33 so use them as inspiration and don't just paste them 34 blindly. 35 36 1) determine which MTD device is being used for UBI, and the partition name: 37 38 .. code-block:: console 39 40 uboot> ubi part 41 Device 0: ubi0, MTD partition ubi 42 43 In this case the important value is ``ubi0`` 44 45 2) list the available volumes and create a new one on which to install Liminix 46 47 .. code-block:: console 48 49 uboot> ubi info l 50 [ copious output scrolls past ] 51 52 Expect there to be existing volumes and for some or all of them to be 53 important. Unless you know what you're doing, don't remove anything 54 whose name suggests it's related to uboot, or any kind of backup or 55 recovery partition. To see how much space is free: 56 57 .. code-block:: console 58 59 uboot> ubi info 60 [ ... ] 61 UBI: available PEBs: 823 62 63 Now we can make our new root volume 64 65 .. code-block:: console 66 67 uboot> ubi create liminix - 68 69 3) transfer the root filesystem from the build system and write it to 70 the new volume. Paste the contents of :file:`result/flash.scr` one line at a time 71 into U-Boot: 72 73 .. code-block:: console 74 75 uboot> setenv serverip 10.0.0.1 76 uboot> setenv ipaddr 10.0.0.8 77 uboot> setenv loadaddr 4007FF28 78 uboot> tftpboot $loadaddr result/rootfs 79 uboot> ubi write $loadaddr liminix $filesize 80 81 Now we have the root filesystem installed on the device. You 82 can even mount it and poke around using :command:`ubifsmount ubi0:liminix; ubifsls /` 83 84 4) optional: before you configure the device to boot into Liminix 85 automatically, you can try booting it by hand to see if it works: 86 87 .. code-block:: console 88 89 uboot> ubifsmount ubi0:liminix 90 uboot> ubifsload ''${loadaddr} boot/fit 91 uboot> bootm ''${loadaddr} 92 93 Once you've done this and you're happy with it, reset the device to 94 return to U-Boot. 95 96 5) Instructions for configuring autoboot are likely to be very 97 device-dependent and you should consult the Liminix documentation for 98 your device. (If you're bringing up a new device, some detective work 99 may be needed. Try running `printenv` and trace through the flow of 100 execution from (probably) :command:`$bootcmd` and look for a suitable 101 variable to change) 102 103 6) Now you can reboot the device into Liminix 104 105 .. code-block:: console 106 107 uboot> reset 108 ''; 109 }; 110 }; 111 112 config.system.outputs.ubimage = 113 assert config.rootfsType == "ubifs"; 114 let 115 o = config.system.outputs; 116 in 117 pkgs.runCommand "ubimage" { } '' 118 mkdir $out 119 cd $out 120 ln -s ${o.rootfs} rootfs 121 ln -s ${instructions} flash.scr 122 ''; 123 }