liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

uimage.nix (2190B)


      1 {
      2   lzma
      3 , stdenv
      4 , ubootTools
      5 , dtc
      6 , lib
      7 } :
      8 let
      9   objcopy = "${stdenv.cc.bintools.targetPrefix}objcopy";
     10   arch = stdenv.hostPlatform.linuxArch;
     11   stripAndZip = ''
     12     ${objcopy} -O binary -R .reginfo -R .notes -R .note -R .comment -R .mdebug -R .note.gnu.build-id -S vmlinux.elf vmlinux.bin
     13     rm -f vmlinux.bin.lzma ; lzma -k -z  vmlinux.bin
     14   '';
     15 in {
     16   kernel
     17 , commandLine
     18 , entryPoint
     19 , extraName ? ""                # e.g. socFamily
     20 , loadAddress
     21 , imageFormat
     22 , dtb ? null
     23 } : stdenv.mkDerivation {
     24   name = "kernel.image";
     25   phases = [
     26     "preparePhase"
     27     (if commandLine != null then assert dtb != null; "mungeDtbPhase" else ":")
     28     (if imageFormat == "fit" then "buildPhaseFIT" else "buildPhaseUImage")
     29     "installPhase"
     30   ];
     31   nativeBuildInputs = [
     32     lzma
     33     dtc
     34     stdenv.cc
     35     ubootTools
     36   ];
     37   preparePhase = ''
     38     cp ${kernel} vmlinux.elf; chmod +w vmlinux.elf
     39   '';
     40   mungeDtbPhase = ''
     41     dtc -I dtb -O dts -o tmp.dts ${dtb}
     42     echo '/{ chosen { bootargs = ${builtins.toJSON commandLine}; }; };'  >> tmp.dts
     43     dtc -I dts -O dtb -o tmp.dtb tmp.dts
     44   '';
     45 
     46   buildPhaseUImage = ''
     47     test -f tmp.dtb && ${objcopy} --update-section .appended_dtb=tmp.dtb vmlinux.elf || ${objcopy} --add-section .appended_dtb=tmp.dtb vmlinux.elf
     48     ${stripAndZip}
     49     mkimage -A ${arch} -O linux -T kernel -C lzma -a 0x${lib.toHexString loadAddress} -e 0x${lib.toHexString entryPoint} -n '${lib.toUpper arch} Liminix Linux ${extraName}' -d vmlinux.bin.lzma kernel.uimage
     50   '';
     51 
     52   buildPhaseFIT = ''
     53     ${stripAndZip}
     54     cat ${./kernel_fdt.its} > mkimage.its
     55     cat << _VARS  >> mkimage.its
     56     / {
     57         images {
     58             kernel {
     59                 data = /incbin/("./vmlinux.bin.lzma");
     60                 load = <0x${lib.toHexString loadAddress}>;
     61                 entry = <0x${lib.toHexString entryPoint}>;
     62                 arch = "${arch}";
     63                 compression = "lzma";
     64             };
     65             fdt-1 {
     66                 data = /incbin/("./tmp.dtb");
     67                 arch = "${arch}";
     68             };
     69         };
     70     };
     71     _VARS
     72     mkimage -f mkimage.its kernel.uimage
     73     mkimage -l kernel.uimage
     74   '';
     75 
     76   installPhase = ''
     77     cp kernel.uimage $out
     78   '';
     79 }