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