Skip to content

Commit

Permalink
Modify u-boot env vars for bpi r3
Browse files Browse the repository at this point in the history
  • Loading branch information
jmbaur committed Aug 13, 2023
1 parent ad3ca99 commit 28fc2bd
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 77 deletions.
11 changes: 5 additions & 6 deletions nixos-configurations/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ in
({ modulesPath, ... }: {
nixpkgs.hostPlatform = "x86_64-linux";
imports = [
"${modulesPath}/profiles/installation-device.nix"
"${modulesPath}/installer/sd-card/sd-image-x86_64.nix"
];
})
Expand Down Expand Up @@ -168,11 +167,11 @@ in

bpi-r3-installer = mkInstaller {
modules = [
../nixos-modules/sd-image.nix
({ config, ... }: {
boot.loader.systemd-boot.extraFiles = {
"efi/dtbs" = "${config.boot.kernelPackages.kernel}/dtbs";
};
# ../nixos-modules/sd-image.nix
({ lib, modulesPath, ... }: {
imports = [ "${modulesPath}/installer/sd-card/sd-image-aarch64.nix" ];
boot.initrd.systemd.enable = true;
sdImage.populateFirmwareCommands = lib.mkForce "";
nixpkgs.hostPlatform = "aarch64-linux";
hardware.bpi-r3.enable = true;
custom.server.enable = true; # limits packages needed for cross-compilation
Expand Down
6 changes: 6 additions & 0 deletions nixos-modules/hardware/bpi-r3.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
config = lib.mkIf config.hardware.bpi-r3.enable {
boot.kernelPackages = pkgs.linuxPackages_latest;

boot.kernelParams = [ "console=ttyS0,115200" ];

# u-boot looks for $fdtfile on the ESP at /dtb
boot.loader.systemd-boot.extraFiles."dtb" = "${config.hardware.deviceTree.package}";
boot.loader.grub.extraFiles."dtb" = "${config.hardware.deviceTree.package}";

hardware.deviceTree.enable = true;
hardware.deviceTree.name = "mediatek/mt7986a-bananapi-bpi-r3.dtb";
hardware.deviceTree.overlays = [
Expand Down
80 changes: 23 additions & 57 deletions nixos-modules/sd-image.nix
Original file line number Diff line number Diff line change
@@ -1,61 +1,27 @@
{ config, lib, pkgs, ... }: {
{ config, pkgs, modulesPath, ... }: {
imports = [ "${modulesPath}/installer/sd-card/sd-image.nix" ];

boot.loader.systemd-boot.enable = true;
boot.growPartition = true;
boot.loader.efi.efiSysMountPoint = "/boot/firmware";
boot.loader.efi.canTouchEfiVariables = false;

lib.isoFileSystems = with lib; {
"/" = mkImageMediaOverride {
fsType = "tmpfs";
options = [ "mode=0755" ];
};

"/boot" = {
device = "/dev/disk/by-label/ESP";
fsType = "vfat";
options = [ "ro" ];
};

"/ro" = mkImageMediaOverride {
device = "/dev/disk/by-label/nixos";
fsType = "ext4";
options = [ "ro" ];
neededForBoot = true;
};

"/nix/.ro-store" = mkImageMediaOverride {
fsType = "bind";
device = "/ro/nix/store";
neededForBoot = true;
};

"/nix/.rw-store" = mkImageMediaOverride {
fsType = "tmpfs";
options = [ "mode=0755" ];
neededForBoot = true;
};

"/nix/store" = mkImageMediaOverride {
fsType = "overlay";
device = "overlay";
options = [
"lowerdir=/nix/.ro-store"
"upperdir=/nix/.rw-store/store"
"workdir=/nix/.rw-store/work"
];
depends = [
"/nix/.ro-store"
"/nix/.rw-store/store"
"/nix/.rw-store/work"
];
};
};

fileSystems = config.lib.isoFileSystems;

system.build.sdImage = import (pkgs.path + "/nixos/lib/make-disk-image.nix") {
name = "sd-image";
inherit pkgs lib config;
partitionTableType = "efi";
format = "raw";
};
sdImage.firmwareSize = 512;
sdImage.populateRootCommands = '''';
sdImage.populateFirmwareCommands =
let
entry = pkgs.writeText "nixos.conf" ''
title nixos
linux /linux
initrd /initrd
options init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams}
'';
in
''
mkdir -p firmware/{EFI/boot,loader/entries}
cp -r ${config.hardware.deviceTree.package} firmware/dtb
cp ${config.system.build.toplevel}/kernel firmware/kernel
cp ${config.system.build.toplevel}/initrd firmware/initrd
cp ${entry} firmware/loader/entries/nixos.conf
cp ${config.systemd.package}/lib/systemd/boot/efi/systemd-boot${pkgs.stdenv.hostPlatform.efiArch}.efi firmware/EFI/boot/boot${pkgs.stdenv.hostPlatform.efiArch}.efi
'';
}
21 changes: 7 additions & 14 deletions overlays/bpi-r3-firmware.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,23 @@ let
// You need to be mindful of these when defining memory locations
// for u-boot to use to boot the system, or these will clobber.
// bootm_size=0x10000000
fdt_addr_r=0x43030000
kernel_addr_r=0x43200000
bootm_size=0x10000000
kernel_addr_r=0x43040000
fdt_addr_r=0x47140000
ramdisk_addr_r=0x47340000
pxefile_addr_r=0x90100000
ramdisk_addr_r=0x4b100000
scriptaddr=0x90000000
// Set initrd high to be under the reserved memory
// initrd_high=0x4fc00000
initrd_high=0x4fc00000
// CONFIG_DEFAULT_FDT_FILE has quotes around path, which makes for an invalid path
fdtfile=mediatek/mt7986a-bananapi-bpi-r3.dtb
'';
uboot = (buildUBoot rec {
version = "2023.07.02";
src = fetchFromGitHub {
owner = "u-boot";
repo = "u-boot";
rev = "v${version}";
hash = "sha256-HPBjm/rIkfTCyAKCFvCqoK7oNN9e9rV9l32qLmI/qz4=";
};
uboot = (buildUBoot {
filesToInstall = [ "u-boot.bin" ];
# eMMC and SD are mutually exclusive on this board, choose one
defconfig = "mt7986a_bpir3_${"sd" /*if internalBoot then "emmc" else "sd"*/}_defconfig";
defconfig = "mt7986a_bpir3_sd_defconfig";
extraMeta.platforms = [ "aarch64-linux" ];
postPatch = ''
cp ${env} board/mediatek/mt7986/mt7986-nixos.env
Expand Down

0 comments on commit 28fc2bd

Please sign in to comment.