1# This module adds Memtest86+/Memtest86 to the GRUB boot menu.
2
3{ config, lib, pkgs, ... }:
4
5with lib;
6
7let
8 memtest86 = pkgs.memtest86plus;
9 efiSupport = config.boot.loader.grub.efiSupport;
10 cfg = config.boot.loader.grub.memtest86;
11in
12
13{
14 options = {
15
16 boot.loader.grub.memtest86 = {
17
18 enable = mkOption {
19 default = false;
20 type = types.bool;
21 description = lib.mdDoc ''
22 Make Memtest86+ (or MemTest86 if EFI support is enabled),
23 a memory testing program, available from the
24 GRUB boot menu. MemTest86 is an unfree program, so
25 this requires `allowUnfree` to be set to
26 `true`.
27 '';
28 };
29
30 params = mkOption {
31 default = [];
32 example = [ "console=ttyS0,115200" ];
33 type = types.listOf types.str;
34 description = lib.mdDoc ''
35 Parameters added to the Memtest86+ command line. As of memtest86+ 5.01
36 the following list of (apparently undocumented) parameters are
37 accepted:
38
39 - `console=...`, set up a serial console.
40 Examples:
41 `console=ttyS0`,
42 `console=ttyS0,9600` or
43 `console=ttyS0,115200n8`.
44
45 - `btrace`, enable boot trace.
46
47 - `maxcpus=N`, limit number of CPUs.
48
49 - `onepass`, run one pass and exit if there
50 are no errors.
51
52 - `tstlist=...`, list of tests to run.
53 Example: `0,1,2`.
54
55 - `cpumask=...`, set a CPU mask, to select CPUs
56 to use for testing.
57
58 This list of command line options was obtained by reading the
59 Memtest86+ source code.
60 '';
61 };
62
63 };
64 };
65
66 config = mkMerge [
67 (mkIf (cfg.enable && efiSupport) {
68 assertions = [
69 {
70 assertion = cfg.params == [];
71 message = "Parameters are not available for MemTest86";
72 }
73 ];
74
75 boot.loader.grub.extraFiles = {
76 "memtest86.efi" = "${pkgs.memtest86-efi}/BOOTX64.efi";
77 };
78
79 boot.loader.grub.extraEntries = ''
80 menuentry "Memtest86" {
81 chainloader /memtest86.efi
82 }
83 '';
84 })
85
86 (mkIf (cfg.enable && !efiSupport) {
87 boot.loader.grub.extraEntries =
88 if config.boot.loader.grub.version == 2 then
89 ''
90 menuentry "Memtest86+" {
91 linux16 @bootRoot@/memtest.bin ${toString cfg.params}
92 }
93 ''
94 else
95 throw "Memtest86+ is not supported with GRUB 1.";
96
97 boot.loader.grub.extraFiles."memtest.bin" = "${memtest86}/memtest.bin";
98 })
99 ];
100}