liminix

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

uimage.nix (1265B)


      1 {
      2   lzma
      3 , stdenv
      4 , ubootTools
      5 , dtc
      6 } :
      7 let
      8   objcopy = "${stdenv.cc.bintools.targetPrefix}objcopy";
      9 in {
     10   kernel
     11 , commandLine
     12 , entryPoint
     13 , extraName ? ""                # e.g. socFamily
     14 , loadAddress
     15 , dtb ? null
     16 } :
     17 stdenv.mkDerivation {
     18   name = "kernel.image";
     19   phases = [
     20     "preparePhase"
     21     (if dtb != null then "dtbPhase" else ":")
     22     "buildPhase"
     23     "installPhase" ];
     24   nativeBuildInputs = [
     25     lzma
     26     dtc
     27     stdenv.cc
     28     ubootTools
     29   ];
     30   preparePhase = ''
     31     cp ${kernel} vmlinux.elf; chmod +w vmlinux.elf
     32   '';
     33   dtbPhase = ''
     34     dtc -I dtb -O dts -o tmp.dts ${dtb}
     35     echo '/{ chosen { bootargs = ${builtins.toJSON commandLine}; }; };'  >> tmp.dts
     36     dtc -I dts -O dtb -o tmp.dtb tmp.dts
     37 	  ${objcopy} --update-section .appended_dtb=tmp.dtb vmlinux.elf || ${objcopy} --add-section .appended_dtb=${dtb} vmlinux.elf
     38   '';
     39 
     40   buildPhase = ''
     41     ${objcopy} -O binary -R .reginfo -R .notes -R .note -R .comment -R .mdebug -R .note.gnu.build-id -S vmlinux.elf vmlinux.bin
     42     rm -f vmlinux.bin.lzma ; lzma -k -z  vmlinux.bin
     43     mkimage -A mips -O linux -T kernel -C lzma -a ${loadAddress} -e ${entryPoint} -n 'MIPS Liminix Linux ${extraName}' -d vmlinux.bin.lzma kernel.uimage
     44   '';
     45   installPhase = ''
     46     cp kernel.uimage $out
     47   '';
     48 }