liminix

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

dtb.nix (901B)


      1 {
      2   stdenv,
      3   dtc,
      4   lib,
      5   runCommand,
      6   writeText,
      7 }:
      8 {
      9   dts,
     10   includes,
     11   commandLine,
     12 }:
     13 let
     14   cppDtSearchFlags = builtins.concatStringsSep " " (map (f: "-I${f}") includes);
     15   dtcSearchFlags = builtins.concatStringsSep " " (map (f: "-i${f}") includes);
     16   cmdline = lib.concatStringsSep " " commandLine;
     17   chosen = writeText "chosen.dtsi" "/{ chosen { bootargs = ${builtins.toJSON cmdline}; }; };";
     18   combined = writeText "combined-dts-fragments" (
     19     lib.concatStrings (builtins.map (f: "#include \"${f}\"\n") (dts ++ [ chosen ]))
     20   );
     21 in
     22 stdenv.mkDerivation {
     23   name = "dtb";
     24   phases = [ "buildPhase" ];
     25   nativeBuildInputs = [ dtc ];
     26   buildPhase = ''
     27     ${stdenv.cc.targetPrefix}cpp -nostdinc -x assembler-with-cpp ${cppDtSearchFlags} -undef -D__DTS__  -o dtb.tmp ${combined}
     28     dtc ${dtcSearchFlags} -I dts  -O dtb -o $out dtb.tmp
     29     # dtc -I dtb  -O dts  $out
     30     test -e $out
     31   '';
     32 }