forked from DGNum/liminix
add support for OpenWrt device trees
This commit is contained in:
parent
2f3072d7d5
commit
9cbffdab50
4 changed files with 49 additions and 21 deletions
|
@ -16,13 +16,19 @@ let
|
||||||
kernel = callPackage ./kernel {
|
kernel = callPackage ./kernel {
|
||||||
inherit (config.kernel) config checkedConfig;
|
inherit (config.kernel) config checkedConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = rec {
|
outputs = rec {
|
||||||
inherit squashfs kernel;
|
inherit squashfs kernel;
|
||||||
|
dtb = kernel.dtb {
|
||||||
|
dts = "qca9531_glinet_gl-ar750.dts";
|
||||||
|
|
||||||
|
};
|
||||||
uimage = kernel.uimage {
|
uimage = kernel.uimage {
|
||||||
|
commandLine = "earlyprintk=serial,ttyS0 console=ttyS0,115200 panic=10 oops=panic init=/bin/init loglevel=8 rootfstype=squashfs";
|
||||||
inherit (device.boot) loadAddress entryPoint;
|
inherit (device.boot) loadAddress entryPoint;
|
||||||
inherit (kernel) vmlinux;
|
inherit (kernel) vmlinux;
|
||||||
|
inherit dtb;
|
||||||
};
|
};
|
||||||
|
|
||||||
combined-image = nixpkgs.pkgs.runCommand "firmware.bin" {
|
combined-image = nixpkgs.pkgs.runCommand "firmware.bin" {
|
||||||
nativeBuildInputs = [ nixpkgs.buildPackages.ubootTools ];
|
nativeBuildInputs = [ nixpkgs.buildPackages.ubootTools ];
|
||||||
} ''
|
} ''
|
||||||
|
|
|
@ -28,9 +28,11 @@
|
||||||
};
|
};
|
||||||
kernel = {
|
kernel = {
|
||||||
checkedConfig = {
|
checkedConfig = {
|
||||||
"MIPS_RAW_APPENDED_DTB" = "y";
|
"MIPS_ELF_APPENDED_DTB" = "y";
|
||||||
};
|
};
|
||||||
config = {
|
config = {
|
||||||
|
MIPS_ELF_APPENDED_DTB = "y";
|
||||||
|
|
||||||
# this is all copied from nixwrt ath79 config. Clearly not all
|
# this is all copied from nixwrt ath79 config. Clearly not all
|
||||||
# of it is device config, some of it is wifi config or
|
# of it is device config, some of it is wifi config or
|
||||||
# installation method config or ...
|
# installation method config or ...
|
||||||
|
@ -46,7 +48,6 @@
|
||||||
"IMAGE_CMDLINE_HACK" = "n";
|
"IMAGE_CMDLINE_HACK" = "n";
|
||||||
"IP_PNP" = "y";
|
"IP_PNP" = "y";
|
||||||
"JFFS2_FS" = "n";
|
"JFFS2_FS" = "n";
|
||||||
"MIPS_RAW_APPENDED_DTB" = "y";
|
|
||||||
"MODULE_SIG" = "y";
|
"MODULE_SIG" = "y";
|
||||||
"MTD_CMDLINE_PARTS" = "y";
|
"MTD_CMDLINE_PARTS" = "y";
|
||||||
"MTD_SPLIT_FIRMWARE" = "y";
|
"MTD_SPLIT_FIRMWARE" = "y";
|
||||||
|
|
|
@ -34,9 +34,24 @@ let
|
||||||
cp -a . $out
|
cp -a . $out
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
openwrtSource = fetchFromGitHub {
|
||||||
|
repo = "openwrt";
|
||||||
|
owner = "openwrt";
|
||||||
|
rev = "a5265497a4f6da158e95d6a450cb2cb6dc085cab";
|
||||||
|
hash = "sha256-YYi4gkpLjbOK7bM2MGQjAyEBuXJ9JNXoz/JEmYf8xE8=";
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
in rec {
|
in rec {
|
||||||
vmlinux = callPackage ./vmlinux.nix {
|
vmlinux = callPackage ./vmlinux.nix {
|
||||||
inherit tree config checkedConfig;
|
inherit tree config checkedConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
uimage = callPackage ./uimage.nix { };
|
uimage = callPackage ./uimage.nix { };
|
||||||
|
|
||||||
|
dtb = callPackage ./dtb.nix {
|
||||||
|
openwrt = openwrtSource;
|
||||||
|
kernel = tree;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,41 +2,47 @@
|
||||||
lzma
|
lzma
|
||||||
, stdenv
|
, stdenv
|
||||||
, ubootTools
|
, ubootTools
|
||||||
|
, dtc
|
||||||
} :
|
} :
|
||||||
let
|
let
|
||||||
objcopy = "${stdenv.cc.bintools.targetPrefix}objcopy";
|
objcopy = "${stdenv.cc.bintools.targetPrefix}objcopy";
|
||||||
in {
|
in {
|
||||||
vmlinux
|
vmlinux
|
||||||
# , commandLine
|
, commandLine
|
||||||
# , fdt ? null
|
|
||||||
, entryPoint
|
, entryPoint
|
||||||
# , extraName ? "" # e.g. socFamily
|
, extraName ? "" # e.g. socFamily
|
||||||
, loadAddress
|
, 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 {
|
stdenv.mkDerivation {
|
||||||
name = "kernel.image";
|
name = "kernel.image";
|
||||||
phases = [ "buildPhase" "installPhase" ];
|
phases = [
|
||||||
|
"preparePhase"
|
||||||
|
(if dtb != null then "dtbPhase" else ":")
|
||||||
|
"buildPhase"
|
||||||
|
"installPhase" ];
|
||||||
nativeBuildInputs = [
|
nativeBuildInputs = [
|
||||||
# patchImage
|
|
||||||
lzma
|
lzma
|
||||||
|
dtc
|
||||||
stdenv.cc
|
stdenv.cc
|
||||||
ubootTools
|
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 = ''
|
buildPhase = ''
|
||||||
${objcopy} -O binary -R .reginfo -R .notes -R .note -R .comment -R .mdebug -R .note.gnu.build-id -S ${vmlinux} vmlinux.stripped
|
${objcopy} -O binary -R .reginfo -R .notes -R .note -R .comment -R .mdebug -R .note.gnu.build-id -S vmlinux.elf vmlinux.bin
|
||||||
# {patchDtbCommand}
|
rm -f vmlinux.bin.lzma ; lzma -k -z vmlinux.bin
|
||||||
rm -f vmlinux.stripped.lzma
|
mkimage -A mips -O linux -T kernel -C lzma -a ${loadAddress} -e ${entryPoint} -n 'MIPS Liminix Linux ${extraName}' -d vmlinux.bin.lzma kernel.uimage
|
||||||
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
|
|
||||||
'';
|
'';
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
cp kernel.image $out
|
cp kernel.uimage $out
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue