forked from NixOS/nixos-hardware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirmware.nix
66 lines (62 loc) · 2.21 KB
/
firmware.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
{ config, pkgs, lib, ... }:
let
cfg = config.hardware.visionfive2;
in
{
options = {
hardware.visionfive2 = {
opensbi = {
src = lib.mkOption {
description = "VisionFive2 OpenSBI source";
type = lib.types.nullOr lib.types.package;
default = null;
};
patches = lib.mkOption {
description = "List of patches to apply to the VisionFive2 OpenSBI source";
type = lib.types.nullOr (lib.types.listOf lib.types.package);
default = null;
};
};
uboot = {
src = lib.mkOption {
description = "VisionFive2 U-boot source";
type = lib.types.nullOr lib.types.package;
default = null;
};
patches = lib.mkOption {
description = "List of patches to apply to the VisionFive2 U-boot source";
type = lib.types.nullOr (lib.types.listOf lib.types.package);
default = null;
};
};
};
};
config = {
system.build = {
opensbi = (pkgs.callPackage ./opensbi.nix {}).overrideAttrs (f: p: {
src = if cfg.opensbi.src != null then cfg.opensbi.src else p.src;
patches = if cfg.opensbi.patches != null then cfg.opensbi.patches else (p.patches or []);
});
uboot = (pkgs.callPackage ./uboot.nix { inherit (config.system.build) opensbi; }).overrideAttrs (f: p: {
src = if cfg.uboot.src != null then cfg.uboot.src else p.src;
patches = if cfg.uboot.patches != null then cfg.uboot.patches else (p.patches or []);
});
updater-flash = pkgs.writeShellApplication {
name = "visionfive2-firmware-update-flash";
runtimeInputs = [ pkgs.mtdutils ];
text = ''
flashcp -v ${config.system.build.uboot}/u-boot-spl.bin.normal.out /dev/mtd0
flashcp -v ${config.system.build.uboot}/u-boot.itb /dev/mtd2
'';
};
updater-sd = pkgs.writeShellApplication {
name = "visionfive2-firmware-update-sd";
runtimeInputs = [ ];
text = ''
dd if=${config.system.build.uboot}/u-boot-spl.bin.normal.out of=/dev/mmcblk0p1 conv=fsync
dd if=${config.system.build.uboot}/u-boot.itb of=/dev/mmcblk0p2 conv=fsync
'';
};
};
};
}