commit 876bd7d8ce244bb6b68144ae3262cb94d7725a95
parent 39c338d71074937658483716aa9658ef0b840c51
Author: Daniel Barlow <dan@telent.net>
Date: Mon, 11 Dec 2023 19:02:30 +0000
rename flashimage to mtdimage
Diffstat:
11 files changed, 131 insertions(+), 132 deletions(-)
diff --git a/ci.nix b/ci.nix
@@ -40,7 +40,7 @@ let
}).outputs.optionsJson;
installers = map (f: "system.outputs.${f}") [
"vmroot"
- "flashimage"
+ "mtdimage"
"ubimage"
];
inherit (pkgs.lib) concatStringsSep;
diff --git a/devices/gl-ar750/default.nix b/devices/gl-ar750/default.nix
@@ -38,7 +38,7 @@
As with many GL.iNet devices, the stock vendor firmware
is a fork of OpenWrt, meaning that the binary created by
- :ref:`system-outputs-flashimage` can be flashed using the
+ :ref:`system-outputs-mtdimage` can be flashed using the
vendor web UI or the U-Boot emergency "unbrick" routine.
For flashing from an existing Liminix system (we believe that) it
@@ -97,7 +97,7 @@
../../modules/network
../../modules/arch/mipseb.nix
../../modules/outputs/tftpboot.nix
- ../../modules/outputs/flashimage.nix
+ ../../modules/outputs/mtdimage.nix
../../modules/outputs/jffs2.nix
];
@@ -105,7 +105,7 @@
FEATURE_DD_IBS_OBS = "y"; # ath10k_cal_data needs skip_bytes,fullblock
};
hardware = {
- defaultOutput = "flashimage";
+ defaultOutput = "mtdimage";
loadAddress = lim.parseInt "0x80060000";
entryPoint = lim.parseInt "0x80060000";
flash = {
diff --git a/devices/gl-mt300a/default.nix b/devices/gl-mt300a/default.nix
@@ -29,7 +29,7 @@
============
The stock vendor firmware is a fork of OpenWrt, meaning that the
- binary created by :ref:`system-outputs-flashimage` can be flashed
+ binary created by :ref:`system-outputs-mtdimage` can be flashed
using the vendor web UI or the U-Boot emergency "unbrick" routine.
For flashing from an existing Liminix system (we think) it
@@ -55,11 +55,11 @@
imports = [
../../modules/arch/mipsel.nix
../../modules/outputs/tftpboot.nix
- ../../modules/outputs/flashimage.nix
+ ../../modules/outputs/mtdimage.nix
../../modules/outputs/jffs2.nix
];
hardware = {
- defaultOutput = "flashimage";
+ defaultOutput = "mtdimage";
loadAddress = lim.parseInt "0x80000000";
entryPoint = lim.parseInt "0x80000000";
diff --git a/devices/gl-mt300n-v2/default.nix b/devices/gl-mt300n-v2/default.nix
@@ -22,7 +22,7 @@
============
The stock vendor firmware is a fork of OpenWrt, meaning that the
- binary created by :ref:`system-outputs-flashimage` can be flashed
+ binary created by :ref:`system-outputs-mtdimage` can be flashed
using the vendor web UI or the U-Boot emergency "unbrick" routine.
For flashing from an existing Liminix system (we think) it
@@ -55,7 +55,7 @@
imports = [
../../modules/arch/mipsel.nix
../../modules/outputs/tftpboot.nix
- ../../modules/outputs/flashimage.nix
+ ../../modules/outputs/mtdimage.nix
../../modules/outputs/jffs2.nix
];
filesystem = dir {
@@ -66,7 +66,7 @@
};
};
hardware = {
- defaultOutput = "flashimage";
+ defaultOutput = "mtdimage";
loadAddress = lim.parseInt "0x80000000";
entryPoint = lim.parseInt "0x80000000";
diff --git a/devices/turris-omnia/default.nix b/devices/turris-omnia/default.nix
@@ -128,7 +128,7 @@
klibBuild = config.system.outputs.kernel.modulesupport;
};
in {
- defaultOutput = "flashimage";
+ defaultOutput = "mtdimage";
loadAddress = lim.parseInt "0x00008000";
entryPoint = lim.parseInt "0x00008000";
rootDevice = "/dev/mtdblock0";
diff --git a/doc/development.rst b/doc/development.rst
@@ -180,7 +180,7 @@ Now add the device and server IP addresses to your configuration:
};
and then build the derivation for ``outputs.default`` or
-``outputs.flashimage`` (for which it will be an alias on any device
+``outputs.mtdimage`` (for which it will be an alias on any device
where this is applicable). You should find it has created
* :file:`result/firmware.bin` which is the file you are going to flash
diff --git a/modules/all-modules.nix b/modules/all-modules.nix
@@ -24,7 +24,7 @@
./outputs.nix
./outputs/vmroot.nix
./outputs/ubimage.nix
- ./outputs/flashimage.nix
+ ./outputs/mtdimage.nix
./ppp
./ramdisk.nix
./squashfs.nix
diff --git a/modules/hardware.nix b/modules/hardware.nix
@@ -32,7 +32,7 @@ in {
};
};
defaultOutput = mkOption {
- description = "\"Default\" output: what gets built for this device when outputs.default is requested. Typically this is \"flashimage\" or \"vmroot\"";
+ description = "\"Default\" output: what gets built for this device when outputs.default is requested. Typically this is \"mtdimage\" or \"vmroot\"";
type = types.nonEmptyStr;
};
ram = {
diff --git a/modules/outputs/diskimage.nix b/modules/outputs/diskimage.nix
@@ -9,7 +9,6 @@ let
o = config.system.outputs;
phram_address = lib.toHexString (config.hardware.ram.startAddress + 256 * 1024 * 1024);
in {
-# imports = [ ./flashimage.nix ];
options.system.outputs = {
diskimage = mkOption {
type = types.package;
diff --git a/modules/outputs/flashimage.nix b/modules/outputs/flashimage.nix
@@ -1,117 +0,0 @@
-{
- config
-, pkgs
-, lib
-, ...
-}:
-let
- inherit (lib) mkOption types concatStringsSep;
- inherit (config.boot) tftp;
-in {
- options.system.outputs = {
- firmware = mkOption {
- type = types.package;
- internal = true; # component of flashimage
- description = ''
- Binary image (combining kernel, FDT, rootfs, initramfs
- if needed, etc) for the target device.
- '';
- };
- flash-scr = mkOption {
- type = types.package;
- internal = true; # component of flashimage
- description = ''
- Copy-pastable U-Boot commands to TFTP download the
- image and write it to flash
- '';
- };
- flashimage = mkOption {
- type = types.package;
- description = ''
- flashimage
- **********
-
- This creates an image called :file:`firmware.bin` suitable for
- squashfs or jffs2 systems. It can be flashed from U-Boot (if
- you have a serial console connection), or on some devices from
- the vendor firmware, or from a Liminix kexecboot system.
-
- If you are flashing from U-Boot, the file
- :file:`flash.scr` is a sequence of commands
- which you can paste at the U-Boot prompt to
- to transfer the firmware file from a TFTP server and
- write it to flash. **Please read the script before
- running it: flash operations carry the potential to
- brick your device**
-
- .. NOTE::
-
- TTL serial connections typically have no form of flow
- control and so don't always like having massive chunks of
- text pasted into them - and U-Boot may drop characters
- while it's busy. So don't necessarily expect to copy-paste
- the whole of :file:`flash.scr` into a terminal emulator and
- have it work just like that. You may need to paste each
- line one at a time, or even retype it.
- '';
- };
- };
-
- config = {
- kernel = {
- config = {
- MTD_SPLIT_UIMAGE_FW = "y";
- } // lib.optionalAttrs (pkgs.stdenv.isMips) {
- # https://stackoverflow.com/questions/26466470/can-the-logical-erase-block-size-of-an-mtd-device-be-increased
- MTD_SPI_NOR_USE_4K_SECTORS = "n";
- };
- };
-
- programs.busybox.applets = [
- "flashcp"
- ];
-
- system.outputs = {
- firmware =
- let
- o = config.system.outputs;
- bs = toString config.hardware.flash.eraseBlockSize;
- in pkgs.runCommand "firmware" {} ''
- dd if=${o.uimage} of=$out bs=${bs} conv=sync
- dd if=${o.rootfs} of=$out bs=${bs} conv=sync,nocreat,notrunc oflag=append
- '';
- flashimage =
- let o = config.system.outputs; in
- # could use trivial-builders.linkFarmFromDrvs here?
- pkgs.runCommand "flashimage" {} ''
- mkdir $out
- cd $out
- ln -s ${o.firmware} firmware.bin
- ln -s ${o.rootfs} rootfs
- ln -s ${o.kernel} vmlinux
- ln -s ${o.manifest} manifest
- ln -s ${o.kernel.headers} build
- ln -s ${o.uimage} uimage
- ln -s ${o.dtb} dtb
- ln -s ${o.flash-scr} flash.scr
- '';
-
- flash-scr =
- let
- inherit (pkgs.lib.trivial) toHexString;
- inherit (config.hardware) flash;
- in
- pkgs.buildPackages.runCommand "" {} ''
- imageSize=$(stat -L -c %s ${config.system.outputs.firmware})
- cat > $out << EOF
- setenv serverip ${tftp.serverip}
- setenv ipaddr ${tftp.ipaddr}
- tftp 0x${toHexString tftp.loadAddress} result/firmware.bin
- erase 0x${toHexString flash.address} +0x${toHexString flash.size}
- cp.b 0x${toHexString tftp.loadAddress} 0x${toHexString flash.address} \''${filesize}
- echo command line was ${builtins.toJSON (concatStringsSep " " config.boot.commandLine)}
- EOF
- '';
- };
- };
-}
diff --git a/modules/outputs/mtdimage.nix b/modules/outputs/mtdimage.nix
@@ -0,0 +1,117 @@
+{
+ config
+, pkgs
+, lib
+, ...
+}:
+let
+ inherit (lib) mkOption types concatStringsSep;
+ inherit (config.boot) tftp;
+in {
+ options.system.outputs = {
+ firmware = mkOption {
+ type = types.package;
+ internal = true; # component of mtdimage
+ description = ''
+ Binary image (combining kernel, FDT, rootfs, initramfs
+ if needed, etc) for the target device.
+ '';
+ };
+ flash-scr = mkOption {
+ type = types.package;
+ internal = true; # component of mtdimage
+ description = ''
+ Copy-pastable U-Boot commands to TFTP download the
+ image and write it to flash
+ '';
+ };
+ mtdimage = mkOption {
+ type = types.package;
+ description = ''
+ mtdimage
+ **********
+
+ This creates an image called :file:`firmware.bin` suitable for
+ squashfs or jffs2 systems. It can be flashed from U-Boot (if
+ you have a serial console connection), or on some devices from
+ the vendor firmware, or from a Liminix kexecboot system.
+
+ If you are flashing from U-Boot, the file
+ :file:`flash.scr` is a sequence of commands
+ which you can paste at the U-Boot prompt to
+ to transfer the firmware file from a TFTP server and
+ write it to flash. **Please read the script before
+ running it: flash operations carry the potential to
+ brick your device**
+
+ .. NOTE::
+
+ TTL serial connections typically have no form of flow
+ control and so don't always like having massive chunks of
+ text pasted into them - and U-Boot may drop characters
+ while it's busy. So don't necessarily expect to copy-paste
+ the whole of :file:`flash.scr` into a terminal emulator and
+ have it work just like that. You may need to paste each
+ line one at a time, or even retype it.
+ '';
+ };
+ };
+
+ config = {
+ kernel = {
+ config = {
+ MTD_SPLIT_UIMAGE_FW = "y";
+ } // lib.optionalAttrs (pkgs.stdenv.isMips) {
+ # https://stackoverflow.com/questions/26466470/can-the-logical-erase-block-size-of-an-mtd-device-be-increased
+ MTD_SPI_NOR_USE_4K_SECTORS = "n";
+ };
+ };
+
+ programs.busybox.applets = [
+ "flashcp"
+ ];
+
+ system.outputs = {
+ firmware =
+ let
+ o = config.system.outputs;
+ bs = toString config.hardware.flash.eraseBlockSize;
+ in pkgs.runCommand "firmware" {} ''
+ dd if=${o.uimage} of=$out bs=${bs} conv=sync
+ dd if=${o.rootfs} of=$out bs=${bs} conv=sync,nocreat,notrunc oflag=append
+ '';
+ mtdimage =
+ let o = config.system.outputs; in
+ # could use trivial-builders.linkFarmFromDrvs here?
+ pkgs.runCommand "mtdimage" {} ''
+ mkdir $out
+ cd $out
+ ln -s ${o.firmware} firmware.bin
+ ln -s ${o.rootfs} rootfs
+ ln -s ${o.kernel} vmlinux
+ ln -s ${o.manifest} manifest
+ ln -s ${o.kernel.headers} build
+ ln -s ${o.uimage} uimage
+ ln -s ${o.dtb} dtb
+ ln -s ${o.flash-scr} flash.scr
+ '';
+
+ flash-scr =
+ let
+ inherit (pkgs.lib.trivial) toHexString;
+ inherit (config.hardware) flash;
+ in
+ pkgs.buildPackages.runCommand "" {} ''
+ imageSize=$(stat -L -c %s ${config.system.outputs.firmware})
+ cat > $out << EOF
+ setenv serverip ${tftp.serverip}
+ setenv ipaddr ${tftp.ipaddr}
+ tftp 0x${toHexString tftp.loadAddress} result/firmware.bin
+ erase 0x${toHexString flash.address} +0x${toHexString flash.size}
+ cp.b 0x${toHexString tftp.loadAddress} 0x${toHexString flash.address} \''${filesize}
+ echo command line was ${builtins.toJSON (concatStringsSep " " config.boot.commandLine)}
+ EOF
+ '';
+ };
+ };
+}