add support for OpenWrt device trees
This commit is contained in:
@@ -2,41 +2,47 @@
|
||||
lzma
|
||||
, stdenv
|
||||
, ubootTools
|
||||
, dtc
|
||||
} :
|
||||
let
|
||||
objcopy = "${stdenv.cc.bintools.targetPrefix}objcopy";
|
||||
in {
|
||||
vmlinux
|
||||
# , commandLine
|
||||
# , fdt ? null
|
||||
, commandLine
|
||||
, entryPoint
|
||||
# , extraName ? "" # e.g. socFamily
|
||||
, extraName ? "" # e.g. socFamily
|
||||
, loadAddress
|
||||
, dtb ? null
|
||||
} :
|
||||
# patchDtbCommand = if (fdt != null) then ''
|
||||
# ( cat vmlinux.stripped ${fdt} > vmlinux.tmp ) && mv vmlinux.tmp vmlinux.stripped
|
||||
# '' else ''
|
||||
# echo patch-cmdline vmlinux.stripped '${commandLine}'
|
||||
# patch-cmdline vmlinux.stripped '${commandLine}'
|
||||
# echo
|
||||
# '';
|
||||
stdenv.mkDerivation {
|
||||
name = "kernel.image";
|
||||
phases = [ "buildPhase" "installPhase" ];
|
||||
phases = [
|
||||
"preparePhase"
|
||||
(if dtb != null then "dtbPhase" else ":")
|
||||
"buildPhase"
|
||||
"installPhase" ];
|
||||
nativeBuildInputs = [
|
||||
# patchImage
|
||||
lzma
|
||||
dtc
|
||||
stdenv.cc
|
||||
ubootTools
|
||||
];
|
||||
preparePhase = ''
|
||||
cp ${vmlinux} vmlinux.elf; chmod +w vmlinux.elf
|
||||
'';
|
||||
dtbPhase = ''
|
||||
dtc -I dtb -O dts -o tmp.dts ${dtb}
|
||||
echo '/{ chosen { bootargs = ${builtins.toJSON commandLine}; }; };' >> tmp.dts
|
||||
dtc -I dts -O dtb -o tmp.dtb tmp.dts
|
||||
${objcopy} --update-section .appended_dtb=tmp.dtb vmlinux.elf || ${objcopy} --add-section .appended_dtb=${dtb} vmlinux.elf
|
||||
'';
|
||||
|
||||
buildPhase = ''
|
||||
${objcopy} -O binary -R .reginfo -R .notes -R .note -R .comment -R .mdebug -R .note.gnu.build-id -S ${vmlinux} vmlinux.stripped
|
||||
# {patchDtbCommand}
|
||||
rm -f vmlinux.stripped.lzma
|
||||
lzma -k -z vmlinux.stripped
|
||||
mkimage -A mips -O linux -T kernel -C lzma -a ${loadAddress} -e ${entryPoint} -n 'MIPS Liminix Linux ' -d vmlinux.stripped.lzma kernel.image
|
||||
${objcopy} -O binary -R .reginfo -R .notes -R .note -R .comment -R .mdebug -R .note.gnu.build-id -S vmlinux.elf vmlinux.bin
|
||||
rm -f vmlinux.bin.lzma ; lzma -k -z vmlinux.bin
|
||||
mkimage -A mips -O linux -T kernel -C lzma -a ${loadAddress} -e ${entryPoint} -n 'MIPS Liminix Linux ${extraName}' -d vmlinux.bin.lzma kernel.uimage
|
||||
'';
|
||||
installPhase = ''
|
||||
cp kernel.image $out
|
||||
cp kernel.uimage $out
|
||||
'';
|
||||
}
|
||||
|
Reference in New Issue
Block a user