Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a more recent kernel #2

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8,355 changes: 8,355 additions & 0 deletions modules/kernel/config

Large diffs are not rendered by default.

74 changes: 0 additions & 74 deletions modules/kernel/kernel.diff

This file was deleted.

42 changes: 18 additions & 24 deletions modules/kernel/kernel.nix
Original file line number Diff line number Diff line change
@@ -1,38 +1,32 @@
{ stdenv
, buildPackages
, fetchFromGitHub
, perl
, buildLinux
, libelf
, utillinux
, lib
, linuxManualConfig
, ...
}@args:
}:

buildLinux (args // rec {
version = "4.9.241-107";
linuxManualConfig rec {
inherit stdenv;

version = "5.11.16";

# modDirVersion needs to be x.y.z.
modDirVersion = "4.9.241";
modDirVersion = "5.11.16";

# branchVersion needs to be x.y.
extraMeta.branch = "4.9";
extraMeta.branch = "5.11";
extraMeta.platforms = [ "aarch64-linux" ];
# TODO: are these needed?

# src = ./linux;
src = fetchFromGitHub {
owner = "hardkernel";
owner = "tobetter";
repo = "linux";
rev = version;
sha256 = "1f004ahbj0x5nmr0240jdv7v6ssgbxd53ivsv7gra87hcm00hbn3";
};

defconfig = "odroidg12_defconfig";

autoModules = false;
structuredExtraConfig = with lib.kernel; {
NR_CPUS = lib.mkForce (freeform "8");
rev = "ddd1bcb1f4d743a8f46b767c7ffc6bfc13f407bc";
sha256 = "186jj25bv7p4b8xjsbyiq7j3rnxwpb6q04h16gbm2gql2imy0d5r";
};

extraMeta.platforms = [ "aarch64-linux" ];
# Strip down kernel
configfile = ./config;

} // (args.argsOverride or { }))
# Needs to be set when building with manual config
allowImportFromDerivation = true;
}
12 changes: 1 addition & 11 deletions modules/kernel/overlay.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
final: prev: {
linux_hardkernel = final.callPackage ./kernel.nix {
kernelPatches = [
# The kernel fails to cross-compile due to:
# 1. warnings caused by different interpretation of function pointers
# 2. NR_CPUS causing stack overflows when allocating cpu_topology
# 3. The IRBLASTER module not registering syscalls correctly

# The following patch makes the above warnings non-errors, decreases NR_CPUS to 4 and disables the IRBLASTER module.
({ name = "hardkernel-patches"; patch = ./kernel.diff; })
];
};
linux_tobetter = final.callPackage ./kernel.nix { };
}
17 changes: 7 additions & 10 deletions modules/odroidhc4/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@ with lib;
{
imports = [
../base.nix
../uboot/hardkernel-uboot.nix
../uboot-script
];
# The linux kernel used is compiled from the Hardkernel fork of
# torvalds/linux
boot.kernelPackages = pkgs.linuxPackagesFor pkgs.linux_hardkernel;
boot.kernelPackages = pkgs.linuxPackagesFor pkgs.linux_tobetter;

boot.initrd.availableKernelModules = [ ];

nixpkgs.overlays = [
(import ../kernel/overlay.nix)
(import ../uboot/overlay.nix)
];

# Bootloader (use Hardkernel fork of Das U-Boot)
# Bootloader (u-boot is installed, generate /boot/boot.scr for it)
boot.loader.grub.enable = false;
boot.loader.generic-extlinux-compatible.enable = false;
boot.loader.hardkernel-uboot.enable = true;

# DTB file to use. This one is present in the hardkernel and tobetter tree
# only. For real mainline kernel use "amlogic/meson-sm1-odroid-hc4.dtb"
# instead, and some peripherals might not work.
hardware.deviceTree.name = "amlogic/meson64_odroidhc4.dtb";

# SSH
services.openssh.enable = true;
Expand Down Expand Up @@ -49,10 +50,6 @@ with lib;
};

fileSystems = {
"/boot" = {
device = "/dev/disk/by-label/FIRMWARE";
fsType = "vfat";
};
"/" = {
device = "/dev/disk/by-label/NIXOS_SD";
fsType = "ext4";
Expand Down
18 changes: 10 additions & 8 deletions modules/sd-image/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,25 @@ in
nixpkgs.pkgs = import "${nixpkgs}" {
inherit (config.nixpkgs) config localSystem crossSystem;
};
nixpkgs.overlays = [
(import ../uboot-bin/overlay.nix)
];

sdImage = {
compressImage = false;
# Use 512 MB for boot partition to fit multiple kernel versions
firmwareSize = 512;
# Copy u-boot bootloader to SD card
# Copy u-boot bootloader to SD card, set partition 1 (unused vfat
# "FIRMWARE") not bootable and partition 2 (ext4 main) bootable
postBuildCommands = ''
dd if="${pkgs.uboot_hardkernel}/u-boot.bin" of="$img" conv=fsync,notrunc bs=512 seek=1
{ echo a; echo 1; echo a; echo 2; echo w; } | fdisk "$img"
'';
# Fill the FIRMWARE partition with the u-boot files, linux kernel and initrd (ramdisk)
populateFirmwareCommands = ''
${config.boot.loader.hardkernel-uboot.populateCmd} -c ${config.system.build.toplevel} -d ./firmware
'';
# Ignore this
populateFirmwareCommands = "";
# Fill the root partition with this nix configuration in /etc/nixos
# and create a mount point for the FIRMWARE partition at /boot
# and create an initial boot.scr in /boot
populateRootCommands = ''
mkdir -p ./files/boot
${config.boot.loader.hardkernel-uboot.populateCmd} -c ${config.system.build.toplevel} -d ./files/boot
mkdir -p ./files/etc/nixos
cp ${../../configuration.nix} ./files/etc/nixos/configuration.nix
cp -r ${../.} ./files/etc/nixos/modules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ in
src = fetchgit {
url = "https://github.com/hardkernel/u-boot.git";
rev = "90ebb7015c1bfbbf120b2b94273977f558a5da46"; # "odroidg12-v2015.01"
sha256 = "1v8z5m0k6a9iw0qbkn6qcwh02rsdsfax29l2ilshr39a3nj40i96";
sha256 = "06d9zk2a9q9mhnjlgi3p8rw1ymy37344wws6lxaa6b5x7v1s48yv";
leaveDotGit = true;
};

Expand Down
5 changes: 5 additions & 0 deletions modules/uboot-bin/overlay.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
final: prev: {
uboot_hardkernel = final.callPackage ./u-boot-odroid.nix {
inherit (final.callPackage ./hardkernel-firmware.nix { }) firmwareOdroidC4;
};
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
pkgs.substituteAll {
src = ./boot-ini-builder.sh;
isExecutable = true;
path = [ pkgs.coreutils pkgs.gnused pkgs.gnugrep pkgs.ubootTools_hardkernel pkgs.gzip ];
configIni = ./config.ini;
# ubootTools is just for mkimage. the one in nixpkgs is enough, we don't have
# to build our own.
path = [ pkgs.coreutils pkgs.gnused pkgs.gnugrep pkgs.ubootTools pkgs.gzip ];
inherit (pkgs) bash;
}
57 changes: 57 additions & 0 deletions modules/uboot-script/boot-ini-builder.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#! @bash@/bin/sh -e

shopt -s nullglob

export PATH=/empty
for i in @path@; do PATH=$PATH:$i/bin; done

usage() {
echo "usage: $0 -c <path-to-default-configuration> -n <dtb file> [-d <boot-dir>]" >&2
exit 1
}

config='' # Default configuration
target=/boot # Target directory
dtbname='' # Devicetree name

while getopts "t:c:d:g:n:" opt; do
case "$opt" in
c) config="$OPTARG" ;;
d) target="$OPTARG" ;;
n) dtbname="$OPTARG" ;;
\?) usage ;;
esac
done

[ -e "$config" -a -d "$target" -a -n "$dtbname" ] || usage

resolve () { readlink -v -e "$1" || exit 2; }
kernel=$(resolve $config/kernel)
dtb=$(resolve $config/dtbs/$dtbname)
initrd=$(resolve $config/initrd.uboot)
syscfg=$(resolve $config)
init=$(resolve $config/init)

bootscr="$target/boot.scr"
tmpini="$bootscr.tmp1.$$"
tmpscr="$bootscr.tmp2.$$"

cat >$tmpini <<EOF
# Generated file, all changes will be lost on nixos-rebuild!

# expect to be set by u-boot:
# devtype, devnum, distro_bootpart, kernel_addr_r, fdt_addr_r, ramdisk_addr_r

load \${devtype} \${devnum}:\${distro_bootpart} \${kernel_addr_r} $kernel
load \${devtype} \${devnum}:\${distro_bootpart} \${fdt_addr_r} $dtb
fdt addr \${fdt_addr_r}
load \${devtype} \${devnum}:\${distro_bootpart} \${ramdisk_addr_r} $initrd

setenv bootargs "root=/dev/mmcblk0p\${distro_bootpart} rootwait rw systemConfig=$syscfg init=$init"

booti \${kernel_addr_r} \${ramdisk_addr_r} \${fdt_addr_r}
EOF

mkimage -A arm64 -O linux -T script -C none -d $tmpini $tmpscr
mv -f $tmpscr $bootscr
rm -f $tmpini
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ in
default = false;
type = types.bool;
description = ''
Whether to generate an extlinux-compatible configuration file
under <literal>/boot/extlinux.conf</literal>. For instance,
U-Boot's generic distro boot support uses this file format.
See <link xlink:href="http://git.denx.de/?p=u-boot.git;a=blob;f=doc/README.distro;hb=refs/heads/master">U-boot's documentation</link>
for more information.
Whether to generate a uboot-compatible configuration file
under <literal>/boot/boot.scr</literal>.
'';
};

Expand All @@ -44,11 +41,20 @@ in

config =
let
builderArgs = "-t ${timeoutStr}" + lib.optionalString (dtCfg.name != null) " -n ${dtCfg.name}";
builderArgs =
assert lib.assertMsg (dtCfg.name != null) "hardware.deviceTree.name must be set";
"-t ${timeoutStr} -n ${dtCfg.name}";
in
mkIf cfg.enable {
system.build.installBootLoader = "${builder} ${builderArgs} -c";
system.boot.loader.id = "hardkernel-uboot";
boot.loader.hardkernel-uboot.populateCmd = "${populateBuilder} ${builderArgs}";
system.extraSystemBuilderCmds = let
initrdUbootPath = pkgs.buildPackages.callPackage ./uboot-image.nix {
initrdPath = "${config.system.build.initialRamdisk}/${config.system.boot.loader.initrdFile}";
};
in ''
ln -s ${initrdUbootPath} $out/initrd.uboot
'';
};
}
12 changes: 12 additions & 0 deletions modules/uboot-script/uboot-image.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{ stdenvNoCC
, gzip
, ubootTools
, initrdPath
}:
stdenvNoCC.mkDerivation {
name = "initrd-uboot";
buildCommand = ''
${gzip}/bin/gzip -d < "${initrdPath}" > tmp
${ubootTools}/bin/mkimage -A arm64 -O linux -T ramdisk -C none -d tmp $out
'';
}
Loading