# Build uImage instead of zImage

**URL:** https://discourse.nixos.org/t/build-uimage-instead-of-zimage/35855
**Category:** Help
**Created:** [November 22, 2023, 9:26am UTC](https://discourse.nixos.org/t/build-uimage-instead-of-zimage/35855 "2023-11-22T09:26:45Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![simpleboy0](https://discourse.nixos.org/user_avatar/discourse.nixos.org/simpleboy0/32/11558_2.png) [@simpleboy0](https://discourse.nixos.org/u/simpleboy0)
#### Post date: [November 22, 2023, 9:26am UTC](https://discourse.nixos.org/t/build-uimage-instead-of-zimage/35855/1 "2023-11-22T09:26:45Z")

</div>

Hello,

Anyone knows how to build `uImage` instead of `zImage` here?

I don’t know how can I use this option:

> <https://github.com/NixOS/nixpkgs/blob/da41de71f62bf7fb989a04e39629b8adbf8aa8b5/pkgs/os-specific/linux/kernel/manual-config.nix#L257>

Here’s the sample of my module:

```auto
let
  # dont use overlays for the qemu, it causes a lot of wasted time on recompiles
  x86pkgs = import pkgs.path { system = "x86_64-linux"; };
  build = config.system.build;

  # armv7l cross-compile and boot fixes
  customKernel = pkgs.linux.override {
    extraConfig = ''
      OVERLAY_FS y
    '';
  };
  customKernelPackages = pkgs.linuxPackagesFor customKernel;
in {
  boot.kernelPackages = customKernelPackages;
  nixpkgs.system = "armv7l-linux";
  system.build.zynq_image = let
    cmdline = "root=/dev/mmcblk0 console=ttyPS0,115200n8 systemConfig=${builtins.unsafeDiscardStringContext build.toplevel}";
    qemuScript = ''
      #!/bin/bash -v
      export PATH=${x86pkgs.qemu}/bin:$PATH
      set -x
      base=$(dirname $0)

      mkdir ./tmp/
      cp $base/root.squashfs ./tmp/
      chmod +w ./tmp/root.squashfs
      truncate -s 64M ./tmp/root.squashfs

      qemu-system-arm \
        -M xilinx-zynq-a9 \
        -serial /dev/null \
        -serial stdio \
        -display none \
        -dtb $base/zynq-zc706.dtb \
        -kernel $base/zImage \
        -initrd $base/initrd \
        -drive file=./tmp/root.squashfs,if=sd,format=raw \
        -append "${cmdline}"
    '';
  in pkgs.runCommand "zynq_image" {
    inherit qemuScript;
    passAsFile = ["qemuScript"];
    preferLocalBuild = true;
  } ''
    mkdir $out
    cd $out
    cp ${build.squashfs} root.squashfs
    cp ${build.kernel}/*zImage .
    cp ${build.initialRamdisk}/initrd initrd
    cp ${build.kernel}/dtbs/zynq-zc706.dtb .
    ln -sv ${build.toplevel} toplevel
    cp $qemuScriptPath qemu-script
    chmod +x qemu-script
    patchShebangs qemu-script
    ls -ltrh
  '';

```

---

<div class="post-metadata">

### Author: ![tobiasBora](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/t/9de0a6/32.png) [@tobiasBora](https://discourse.nixos.org/u/tobiasBora)
#### Post date: [November 22, 2023, 10:07am UTC](https://discourse.nixos.org/t/build-uimage-instead-of-zimage/35855/2 "2023-11-22T10:07:14Z")

</div>

I am not at all a kernel expert, and I’m not even sure to know what you are trying to do, but a ` rg 'target = "uimage"' -i` in the nixpkgs folder points to [https://github.com/NixOS/nixpkgs/blob/3302bc3ddda5b1f72f7382b259d25856ed763a5e/lib/systems/platforms.nix#L66](https://github.com/NixOS/nixpkgs/blob/3302bc3ddda5b1f72f7382b259d25856ed763a5e/lib/systems/platforms.nix#L66) that contains stuff like:

```auto
  pogoplug4 = {
    linux-kernel = {
      name = "pogoplug4";

      baseConfig = "multi_v5_defconfig";
      autoModules = false;
      extraConfig = ''
        # Ubi for the mtd
        MTD_UBI y
        UBIFS_FS y
        UBIFS_FS_XATTR y
        UBIFS_FS_ADVANCED_COMPR y
        UBIFS_FS_LZO y
        UBIFS_FS_ZLIB y
        UBIFS_FS_DEBUG n
      '';
      makeFlags = ["LOADADDR=0x8000"];
      target = "uImage";
      # TODO reenable once manual-config's config actually builds a .dtb and this is checked to be working
      #DTB = true;
    };
    gcc = {
      arch = "armv5te";
    };
  };

```

which makes sense since when reading the code, you realize that `kernelConf` is set to `stdenv.hostPlatform.linux-kernel` (`host` being understood as the architecture running the kernel).  
so doing an extrapolation with your code also containing `extraConfig`, my first try would be to do:

```auto
  customKernel = pkgs.linux.override {
    extraConfig = ''
      OVERLAY_FS y
    '';
    # add this:
    target = "uImage";
  };

```

But I might be very wrong. Have you tried that before?

If not, you might want to give a try to this reading discussing how to override kernel options using `kernelPatches` [The \*correct\* way to override the latest kernel config - #7 by aszlig](https://discourse.nixos.org/t/the-correct-way-to-override-the-latest-kernel-config/533/7) and this discussion also seems related [Override kernel build dependencies - #3 by Skallwar](https://discourse.nixos.org/t/override-kernel-build-dependencies/24359/3)

---

<div class="post-metadata">

### Author: ![simpleboy0](https://discourse.nixos.org/user_avatar/discourse.nixos.org/simpleboy0/32/11558_2.png) [@simpleboy0](https://discourse.nixos.org/u/simpleboy0)
#### Post date: [November 22, 2023, 6:26pm UTC](https://discourse.nixos.org/t/build-uimage-instead-of-zimage/35855/3 "2023-11-22T18:26:12Z")

</div>

Already tried to add `target = "uImage"`. Nothing seems to happen. Actually if I set any arbitrary values there, it was also not picked up. Maybe this is not the right way.

---

<div class="post-metadata">

### Author: ![tobiasBora](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/t/9de0a6/32.png) [@tobiasBora](https://discourse.nixos.org/u/tobiasBora)
#### Post date: [November 22, 2023, 7:01pm UTC](https://discourse.nixos.org/t/build-uimage-instead-of-zimage/35855/4 "2023-11-22T19:01:03Z")

</div>

Uhm… Do you mean that `extraConfig` is also not considered, or this applies only to `target` ? What happens if you use something like:

```auto
boot.kernelPatches = [{ name="patch-uImage"; patch = null; target = "uImage"; }];

```

instead?

---

<div class="post-metadata">

### Author: ![simpleboy0](https://discourse.nixos.org/user_avatar/discourse.nixos.org/simpleboy0/32/11558_2.png) [@simpleboy0](https://discourse.nixos.org/u/simpleboy0)
#### Post date: [November 22, 2023, 10:14pm UTC](https://discourse.nixos.org/t/build-uimage-instead-of-zimage/35855/6 "2023-11-22T22:14:29Z")

</div>

`extraConfig` was considered , just not the target. Tried the `boot.kernelPatches`. It rebuilds the kernel, though I do not know how to check for the `uImage` if it was really generated.
