forked from lf-edge/eve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0000-core-os-merge.patch
6484 lines (6327 loc) · 198 KB
/
0000-core-os-merge.patch
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
From 617b08377dbaa9ea3876b5585fe0ba36286fbed6 Mon Sep 17 00:00:00 2001
From: Roman Shaposhnik <[email protected]>
Date: Sat, 11 Apr 2020 05:47:55 +0000
Subject: [PATCH] Merging CoreOS UEFI/GPT support
A lot of this needs to be refactored once we move to GRUB 2.04
diff --git a/.gitignore b/.gitignore
index eca17bec9..5a9cce919 100644
--- a/.gitignore
+++ b/.gitignore
@@ -42,6 +42,7 @@ gensymlist.sh
gentrigtables
gentrigtables.exe
gettext_strings_test
+gpt_unit_test
grub-bin2h
/grub-bios-setup
/grub-bios-setup.exe
diff --git a/Makefile.util.def b/Makefile.util.def
index 3180ac880..9c33c46e4 100644
--- a/Makefile.util.def
+++ b/Makefile.util.def
@@ -1166,6 +1166,18 @@ script = {
common = tests/grub_cmd_tr.in;
};
+script = {
+ testcase;
+ name = gptrepair_test;
+ common = tests/gptrepair_test.in;
+};
+
+script = {
+ testcase;
+ name = gptprio_test;
+ common = tests/gptprio_test.in;
+};
+
script = {
testcase;
name = file_filter_test;
@@ -1261,6 +1273,25 @@ program = {
ldadd = '$(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)';
};
+program = {
+ testcase;
+ name = gpt_unit_test;
+ common = tests/gpt_unit_test.c;
+ common = tests/lib/unit_test.c;
+ common = grub-core/commands/search_part_label.c;
+ common = grub-core/commands/search_part_uuid.c;
+ common = grub-core/commands/search_disk_uuid.c;
+ common = grub-core/disk/host.c;
+ common = grub-core/kern/emu/hostfs.c;
+ common = grub-core/lib/gpt.c;
+ common = grub-core/tests/lib/test.c;
+ ldadd = libgrubmods.a;
+ ldadd = libgrubgcry.a;
+ ldadd = libgrubkern.a;
+ ldadd = grub-core/gnulib/libgnu.a;
+ ldadd = '$(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)';
+};
+
program = {
name = grub-menulst2cfg;
mansection = 1;
diff --git a/docs/grub.texi b/docs/grub.texi
index 0f2ab91fc..b58d188f5 100644
--- a/docs/grub.texi
+++ b/docs/grub.texi
@@ -3884,6 +3884,7 @@ you forget a command, you can run the command @command{help}
* sha256sum:: Compute or check SHA256 hash
* sha512sum:: Compute or check SHA512 hash
* sleep:: Wait for a specified number of seconds
+* smbios:: Retrieve SMBIOS information
* source:: Read a configuration file in same context
* test:: Check file types and compare values
* true:: Do nothing, successfully
@@ -5004,6 +5005,74 @@ if timeout was interrupted by @key{ESC}.
@end deffn
+@node smbios
+@subsection smbios
+
+@deffn Command smbios @
+ [@option{--type} @var{type}] @
+ [@option{--handle} @var{handle}] @
+ [@option{--match} @var{match}] @
+ (@option{--get-byte} | @option{--get-word} | @option{--get-dword} | @
+ @option{--get-qword} | @option{--get-string} | @option{--get-uuid}) @
+ @var{offset} @
+ [@option{--set} @var{variable}]
+Retrieve SMBIOS information.
+
+The @command{smbios} command returns the value of a field in an SMBIOS
+structure. The following options determine which structure to select.
+
+@itemize @bullet
+@item
+Specifying @option{--type} will select structures with a matching
+@var{type}. The type can be any integer from 0 to 255.
+@item
+Specifying @option{--handle} will select structures with a matching
+@var{handle}. The handle can be any integer from 0 to 65535.
+@item
+Specifying @option{--match} will select structure number @var{match} in the
+filtered list of structures; e.g. @code{smbios --type 4 --match 2} will select
+the second Process Information (Type 4) structure. The list is always ordered
+the same as the hardware's SMBIOS table. The match number must be a positive
+integer. If unspecified, the first matching structure will be selected.
+@end itemize
+
+The remaining options determine which field in the selected SMBIOS structure to
+return. Only one of these options may be specified at a time.
+
+@itemize @bullet
+@item
+When given @option{--get-byte}, return the value of the byte
+at @var{offset} bytes into the selected SMBIOS structure.
+@item
+When given @option{--get-word}, return the value of the word (two bytes)
+at @var{offset} bytes into the selected SMBIOS structure.
+@item
+When given @option{--get-dword}, return the value of the dword (four bytes)
+at @var{offset} bytes into the selected SMBIOS structure.
+@item
+When given @option{--get-qword}, return the value of the qword (eight bytes)
+at @var{offset} bytes into the selected SMBIOS structure.
+@item
+When given @option{--get-string}, return the string with its index found
+at @var{offset} bytes into the selected SMBIOS structure.
+@item
+When given @option{--get-uuid}, return the value of the UUID (sixteen bytes)
+at @var{offset} bytes into the selected SMBIOS structure.
+@end itemize
+
+The default action is to print the value of the requested field to the console,
+but a variable name can be specified with @option{--set} to store the value
+instead of printing it.
+
+For example, this will store and then display the system manufacturer's name.
+
+@example
+smbios --type 1 --get-string 4 --set system_manufacturer
+echo $system_manufacturer
+@end example
+@end deffn
+
+
@node source
@subsection source
diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am
index 104513847..d7a09417d 100644
--- a/grub-core/Makefile.am
+++ b/grub-core/Makefile.am
@@ -92,6 +92,7 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/term.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/time.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/mm_private.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/net.h
+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/tpm.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/memory.h
if COND_i386_pc
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index fc4767f19..3b5af98fa 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -129,6 +129,7 @@ kernel = {
common = kern/rescue_parser.c;
common = kern/rescue_reader.c;
common = kern/term.c;
+ common = kern/tpm.c;
noemu = kern/compiler-rt.c;
noemu = kern/mm.c;
@@ -191,6 +192,7 @@ kernel = {
efi = term/efi/console.c;
efi = kern/acpi.c;
efi = kern/efi/acpi.c;
+ efi = kern/efi/tpm.c;
i386_coreboot = kern/i386/pc/acpi.c;
i386_multiboot = kern/i386/pc/acpi.c;
i386_coreboot = kern/acpi.c;
@@ -237,6 +239,7 @@ kernel = {
i386_pc = kern/i386/pc/init.c;
i386_pc = kern/i386/pc/mmap.c;
+ i386_pc = kern/i386/pc/tpm.c;
i386_pc = term/i386/pc/console.c;
i386_qemu = bus/pci.c;
@@ -843,11 +846,32 @@ module = {
enable = x86_64_efi;
};
+module = {
+ name = getenv;
+ common = commands/efi/getenv.c;
+ enable = efi;
+};
+
module = {
name = gptsync;
common = commands/gptsync.c;
};
+module = {
+ name = gptrepair;
+ common = commands/gptrepair.c;
+};
+
+module = {
+ name = gptprio;
+ common = commands/gptprio.c;
+};
+
+module = {
+ name = gpt;
+ common = lib/gpt.c;
+};
+
module = {
name = halt;
nopc = commands/halt.c;
@@ -1022,6 +1046,21 @@ module = {
common = commands/search_label.c;
};
+module = {
+ name = search_part_uuid;
+ common = commands/search_part_uuid.c;
+};
+
+module = {
+ name = search_part_label;
+ common = commands/search_part_label.c;
+};
+
+module = {
+ name = search_disk_uuid;
+ common = commands/search_disk_uuid.c;
+};
+
module = {
name = setpci;
common = commands/setpci.c;
@@ -1039,6 +1078,21 @@ module = {
common = commands/sleep.c;
};
+module = {
+ name = smbios;
+
+ common = commands/smbios.c;
+ efi = commands/efi/smbios.c;
+ i386_pc = commands/i386/pc/smbios.c;
+ i386_coreboot = commands/i386/pc/smbios.c;
+ i386_multiboot = commands/i386/pc/smbios.c;
+
+ enable = efi;
+ enable = i386_pc;
+ enable = i386_coreboot;
+ enable = i386_multiboot;
+};
+
module = {
name = suspend;
ieee1275 = commands/ieee1275/suspend.c;
@@ -1758,6 +1812,14 @@ module = {
enable = x86_64_efi;
};
+module = {
+ name = linuxefi;
+ efi = loader/i386/efi/linux.c;
+ efi = lib/cmdline.c;
+ enable = i386_efi;
+ enable = x86_64_efi;
+};
+
module = {
name = chain;
efi = loader/efi/chainloader.c;
@@ -2386,3 +2448,9 @@ module = {
common = loader/i386/xen_file64.c;
extra_dist = loader/i386/xen_fileXX.c;
};
+
+module = {
+ name = fwconfig;
+ common = commands/fwconfig.c;
+ enable = x86;
+};
diff --git a/grub-core/boot/i386/pc/boot.S b/grub-core/boot/i386/pc/boot.S
index 2bd0b2d28..47a461ed5 100644
--- a/grub-core/boot/i386/pc/boot.S
+++ b/grub-core/boot/i386/pc/boot.S
@@ -24,11 +24,14 @@
* defines for the code go here
*/
+#define TPM 1
+
/* Print message string */
#define MSG(x) movw $x, %si; call LOCAL(message)
#define ERR(x) movw $x, %si; jmp LOCAL(error_message)
.macro floppy
+#ifndef TPM
part_start:
LOCAL(probe_values):
@@ -85,6 +88,7 @@ fd_probe_error_string: .asciz "Floppy"
movb MACRO_DOLLAR(79), %ch
jmp LOCAL(final_init)
+#endif
.endm
.macro scratch
@@ -255,6 +259,7 @@ real_start:
/* set %si to the disk address packet */
movw $disk_address_packet, %si
+#ifndef TPM
/* check if LBA is supported */
movb $0x41, %ah
movw $0x55aa, %bx
@@ -274,6 +279,7 @@ real_start:
andw $1, %cx
jz LOCAL(chs_mode)
+#endif
LOCAL(lba_mode):
xorw %ax, %ax
@@ -317,6 +323,9 @@ LOCAL(lba_mode):
jmp LOCAL(copy_buffer)
LOCAL(chs_mode):
+#ifdef TPM
+ jmp LOCAL(general_error)
+#else
/*
* Determine the hard disk geometry from the BIOS!
* We do this first, so that LS-120 IDE floppies work correctly.
@@ -428,7 +437,7 @@ setup_sectors:
jc LOCAL(read_error)
movw %es, %bx
-
+#endif /* TPM */
LOCAL(copy_buffer):
/*
* We need to save %cx and %si because the startup code in
@@ -451,6 +460,25 @@ LOCAL(copy_buffer):
popw %ds
popa
+#ifdef TPM
+ pusha
+
+ movw $0xBB00, %ax /* TCG_StatusCheck */
+ int $0x1A
+ test %eax, %eax
+ jnz boot /* No TPM or TPM deactivated */
+
+ movw $0xBB07, %ax /* TCG_CompactHashLogExtendEvent */
+ movw $GRUB_BOOT_MACHINE_KERNEL_ADDR, %di
+ xorl %esi, %esi
+ movl $0x41504354, %ebx /* TCPA */
+ movl $0x200, %ecx /* Measure 512 bytes */
+ movl $0x8, %edx /* PCR 8 */
+ int $0x1A
+
+boot:
+ popa
+#endif
/* boot kernel */
jmp *(LOCAL(kernel_address))
diff --git a/grub-core/boot/i386/pc/diskboot.S b/grub-core/boot/i386/pc/diskboot.S
index 1ee4cf5b2..3a324ea74 100644
--- a/grub-core/boot/i386/pc/diskboot.S
+++ b/grub-core/boot/i386/pc/diskboot.S
@@ -19,6 +19,8 @@
#include <grub/symbol.h>
#include <grub/machine/boot.h>
+#define TPM 1
+
/*
* defines for the code go here
*/
@@ -58,6 +60,21 @@ _start:
/* this sets up for the first run through "bootloop" */
movw $LOCAL(firstlist), %di
+#ifdef TPM
+ /* clear EAX to remove potential garbage */
+ xorl %eax, %eax
+ /* 8(%di) = number of sectors to read */
+ movw 8(%di), %ax
+
+ /* Multiply number of sectors to read with 512 bytes. EAX is 32bit
+ * which is large enough to hold values of up to 4GB. I doubt there
+ * will ever be a core.img larger than that. ;-) */
+ shll $9, %eax
+
+ /* write result to bytes_to_measure var */
+ movl %eax, bytes_to_measure
+#endif
+
/* save the sector number of the second sector in %ebp */
movl (%di), %ebp
@@ -295,6 +312,29 @@ LOCAL(copy_buffer):
/* END OF MAIN LOOP */
LOCAL(bootit):
+#ifdef TPM
+ pusha
+ movw $0xBB07, %ax /* TCG_CompactHashLogExtendEvent */
+
+ movw $0x0, %bx
+ movw %bx, %es
+
+ /* We've already measured the first 512 bytes, now measure the rest */
+ xorl %edi, %edi
+ movw $(GRUB_BOOT_MACHINE_KERNEL_ADDR + 0x200), %di
+
+ movl $0x41504354, %ebx /* EBX = "TCPA" */
+
+ /* %ecx = The length, in bytes, of the buffer to measure */
+ movl $bytes_to_measure, %esi
+ movl (%esi), %ecx
+ xorl %esi, %esi
+ movl $0x9, %edx /* PCR 9 */
+
+ int $0x1A
+
+ popa
+#endif
/* print a newline */
MSG(notification_done)
popw %dx /* this makes sure %dl is our "boot" drive */
@@ -329,6 +369,10 @@ geometry_error_string: .asciz "Geom"
read_error_string: .asciz "Read"
general_error_string: .asciz " Error"
+#ifdef TPM
+bytes_to_measure: .long 0
+#endif
+
/*
* message: write the string pointed to by %si
*
diff --git a/grub-core/commands/efi/getenv.c b/grub-core/commands/efi/getenv.c
new file mode 100644
index 000000000..7eb2c4506
--- /dev/null
+++ b/grub-core/commands/efi/getenv.c
@@ -0,0 +1,153 @@
+/* getenv.c - retrieve EFI variables. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ * Copyright (C) 2014 CoreOS, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/efi/efi.h>
+#include <grub/dl.h>
+#include <grub/env.h>
+#include <grub/err.h>
+#include <grub/extcmd.h>
+#include <grub/i18n.h>
+#include <grub/misc.h>
+#include <grub/mm.h>
+
+GRUB_MOD_LICENSE ("GPLv3+");
+
+static const struct grub_arg_option options_getenv[] = {
+ {"var-name", 'e', 0,
+ N_("Environment variable to query"),
+ N_("VARNAME"), ARG_TYPE_STRING},
+ {"var-guid", 'g', 0,
+ N_("GUID of environment variable to query"),
+ N_("GUID"), ARG_TYPE_STRING},
+ {"binary", 'b', 0,
+ N_("Read binary data and represent it as hex"),
+ 0, ARG_TYPE_NONE},
+ {0, 0, 0, 0, 0, 0}
+};
+
+enum options_getenv
+{
+ GETENV_VAR_NAME,
+ GETENV_VAR_GUID,
+ GETENV_BINARY,
+};
+
+static grub_err_t
+grub_cmd_getenv (grub_extcmd_context_t ctxt, int argc, char **args)
+{
+ struct grub_arg_list *state = ctxt->state;
+ char *envvar = NULL, *guid = NULL, *bindata = NULL, *data = NULL;
+ grub_size_t datasize;
+ grub_efi_guid_t efi_var_guid;
+ grub_efi_boolean_t binary = state[GETENV_BINARY].set;
+ unsigned int i;
+
+ if (!state[GETENV_VAR_NAME].set || !state[GETENV_VAR_GUID].set)
+ {
+ grub_error (GRUB_ERR_INVALID_COMMAND, N_("-e and -g are required"));
+ goto done;
+ }
+
+ if (argc != 1)
+ {
+ grub_error (GRUB_ERR_BAD_ARGUMENT, N_("unexpected arguments"));
+ goto done;
+ }
+
+ envvar = state[GETENV_VAR_NAME].arg;
+ guid = state[GETENV_VAR_GUID].arg;
+
+ if (grub_strlen(guid) != 36 ||
+ guid[8] != '-' ||
+ guid[13] != '-' ||
+ guid[18] != '-' ||
+ guid[23] != '-')
+ {
+ grub_error (GRUB_ERR_BAD_ARGUMENT, N_("invalid GUID"));
+ goto done;
+ }
+
+ /* Forgive me father for I have sinned */
+ guid[8] = 0;
+ efi_var_guid.data1 = grub_strtoul(guid, NULL, 16);
+ guid[13] = 0;
+ efi_var_guid.data2 = grub_strtoul(guid + 9, NULL, 16);
+ guid[18] = 0;
+ efi_var_guid.data3 = grub_strtoul(guid + 14, NULL, 16);
+ efi_var_guid.data4[7] = grub_strtoul(guid + 34, NULL, 16);
+ guid[34] = 0;
+ efi_var_guid.data4[6] = grub_strtoul(guid + 32, NULL, 16);
+ guid[32] = 0;
+ efi_var_guid.data4[5] = grub_strtoul(guid + 30, NULL, 16);
+ guid[30] = 0;
+ efi_var_guid.data4[4] = grub_strtoul(guid + 28, NULL, 16);
+ guid[28] = 0;
+ efi_var_guid.data4[3] = grub_strtoul(guid + 26, NULL, 16);
+ guid[26] = 0;
+ efi_var_guid.data4[2] = grub_strtoul(guid + 24, NULL, 16);
+ guid[23] = 0;
+ efi_var_guid.data4[1] = grub_strtoul(guid + 21, NULL, 16);
+ guid[21] = 0;
+ efi_var_guid.data4[0] = grub_strtoul(guid + 19, NULL, 16);
+
+ data = grub_efi_get_variable(envvar, &efi_var_guid, &datasize);
+
+ if (!data || !datasize)
+ {
+ grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("No such variable"));
+ goto done;
+ }
+
+ if (binary)
+ {
+ bindata = grub_zalloc(datasize * 2 + 1);
+ for (i=0; i<datasize; i++)
+ grub_snprintf(bindata + i*2, 3, "%02x", data[i] & 0xff);
+
+ if (grub_env_set (args[0], bindata))
+ goto done;
+ }
+ else if (grub_env_set (args[0], data))
+ {
+ goto done;
+ }
+
+ grub_errno = GRUB_ERR_NONE;
+
+done:
+ grub_free(bindata);
+ grub_free(data);
+ return grub_errno;
+}
+
+static grub_extcmd_t cmd_getenv;
+
+GRUB_MOD_INIT(getenv)
+{
+ cmd_getenv = grub_register_extcmd ("getenv", grub_cmd_getenv, 0,
+ N_("-e envvar -g guidenv setvar"),
+ N_("Read a firmware environment variable"),
+ options_getenv);
+}
+
+GRUB_MOD_FINI(getenv)
+{
+ grub_unregister_extcmd (cmd_getenv);
+}
diff --git a/grub-core/commands/efi/loadbios.c b/grub-core/commands/efi/loadbios.c
index 132cadbc7..b34cf15f9 100644
--- a/grub-core/commands/efi/loadbios.c
+++ b/grub-core/commands/efi/loadbios.c
@@ -30,6 +30,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
static grub_efi_guid_t acpi_guid = GRUB_EFI_ACPI_TABLE_GUID;
static grub_efi_guid_t acpi2_guid = GRUB_EFI_ACPI_20_TABLE_GUID;
static grub_efi_guid_t smbios_guid = GRUB_EFI_SMBIOS_TABLE_GUID;
+static grub_efi_guid_t smbios3_guid = GRUB_EFI_SMBIOS3_TABLE_GUID;
#define EBDA_SEG_ADDR 0x40e
#define LOW_MEM_ADDR 0x413
@@ -93,7 +94,7 @@ static void
fake_bios_data (int use_rom)
{
unsigned i;
- void *acpi, *smbios;
+ void *acpi, *smbios, *smbios3;
grub_uint16_t *ebda_seg_ptr, *low_mem_ptr;
ebda_seg_ptr = (grub_uint16_t *) EBDA_SEG_ADDR;
@@ -103,6 +104,7 @@ fake_bios_data (int use_rom)
acpi = 0;
smbios = 0;
+ smbios3 = 0;
for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
{
grub_efi_packed_guid_t *guid =
@@ -127,6 +129,11 @@ fake_bios_data (int use_rom)
smbios = grub_efi_system_table->configuration_table[i].vendor_table;
grub_dprintf ("efi", "SMBIOS: %p\n", smbios);
}
+ else if (! grub_memcmp (guid, &smbios3_guid, sizeof (grub_efi_guid_t)))
+ {
+ smbios3 = grub_efi_system_table->configuration_table[i].vendor_table;
+ grub_dprintf ("efi", "SMBIOS3: %p\n", smbios3);
+ }
}
*ebda_seg_ptr = FAKE_EBDA_SEG;
@@ -137,8 +144,13 @@ fake_bios_data (int use_rom)
if (acpi)
grub_memcpy ((char *) ((FAKE_EBDA_SEG << 4) + 16), acpi, 1024 - 16);
- if ((use_rom) && (smbios))
- grub_memcpy ((char *) SBIOS_ADDR, (char *) smbios + 16, 16);
+ if (use_rom)
+ {
+ if (smbios)
+ grub_memcpy ((char *) SBIOS_ADDR, (char *) smbios, 31);
+ if (smbios3)
+ grub_memcpy ((char *) SBIOS_ADDR + 32, (char *) smbios3, 24);
+ }
}
static grub_err_t
diff --git a/grub-core/commands/efi/lsefisystab.c b/grub-core/commands/efi/lsefisystab.c
index df1030221..7c039c509 100644
--- a/grub-core/commands/efi/lsefisystab.c
+++ b/grub-core/commands/efi/lsefisystab.c
@@ -48,6 +48,7 @@ static const struct guid_mapping guid_mappings[] =
{ GRUB_EFI_MPS_TABLE_GUID, "MPS"},
{ GRUB_EFI_SAL_TABLE_GUID, "SAL"},
{ GRUB_EFI_SMBIOS_TABLE_GUID, "SMBIOS"},
+ { GRUB_EFI_SMBIOS3_TABLE_GUID, "SMBIOS3"},
{ GRUB_EFI_SYSTEM_RESOURCE_TABLE_GUID, "SYSTEM RESOURCE TABLE"},
{ GRUB_EFI_TIANO_CUSTOM_DECOMPRESS_GUID, "TIANO CUSTOM DECOMPRESS"},
{ GRUB_EFI_TSC_FREQUENCY_GUID, "TSC FREQUENCY"},
diff --git a/grub-core/commands/efi/smbios.c b/grub-core/commands/efi/smbios.c
new file mode 100644
index 000000000..927702209
--- /dev/null
+++ b/grub-core/commands/efi/smbios.c
@@ -0,0 +1,59 @@
+/* smbios.c - get smbios tables. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2015 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/smbios.h>
+#include <grub/misc.h>
+#include <grub/efi/efi.h>
+#include <grub/efi/api.h>
+
+struct grub_smbios_eps *
+grub_machine_smbios_get_eps (void)
+{
+ unsigned i;
+ static grub_efi_packed_guid_t smbios_guid = GRUB_EFI_SMBIOS_TABLE_GUID;
+
+ for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
+ {
+ grub_efi_packed_guid_t *guid =
+ &grub_efi_system_table->configuration_table[i].vendor_guid;
+
+ if (! grub_memcmp (guid, &smbios_guid, sizeof (grub_efi_packed_guid_t)))
+ return (struct grub_smbios_eps *)
+ grub_efi_system_table->configuration_table[i].vendor_table;
+ }
+ return 0;
+}
+
+struct grub_smbios_eps3 *
+grub_machine_smbios_get_eps3 (void)
+{
+ unsigned i;
+ static grub_efi_packed_guid_t smbios3_guid = GRUB_EFI_SMBIOS3_TABLE_GUID;
+
+ for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
+ {
+ grub_efi_packed_guid_t *guid =
+ &grub_efi_system_table->configuration_table[i].vendor_guid;
+
+ if (! grub_memcmp (guid, &smbios3_guid, sizeof (grub_efi_packed_guid_t)))
+ return (struct grub_smbios_eps3 *)
+ grub_efi_system_table->configuration_table[i].vendor_table;
+ }
+ return 0;
+}
diff --git a/grub-core/commands/fwconfig.c b/grub-core/commands/fwconfig.c
new file mode 100644
index 000000000..3abe59f2b
--- /dev/null
+++ b/grub-core/commands/fwconfig.c
@@ -0,0 +1,122 @@
+/* fwconfig.c - command to read config from qemu fwconfig */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2015 CoreOS, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/dl.h>
+#include <grub/misc.h>
+#include <grub/extcmd.h>
+#include <grub/env.h>
+#include <grub/cpu/io.h>
+#include <grub/i18n.h>
+#include <grub/mm.h>
+
+GRUB_MOD_LICENSE ("GPLv3+");
+
+#define SELECTOR 0x510
+#define DATA 0x511
+
+#define SIGNATURE_INDEX 0x00
+#define DIRECTORY_INDEX 0x19
+
+static grub_extcmd_t cmd_read_fwconfig;
+
+struct grub_qemu_fwcfgfile {
+ grub_uint32_t size;
+ grub_uint16_t select;
+ grub_uint16_t reserved;
+ char name[56];
+};
+
+static const struct grub_arg_option options[] =
+ {
+ {0, 'v', 0, N_("Save read value into variable VARNAME."),
+ N_("VARNAME"), ARG_TYPE_STRING},
+ {0, 0, 0, 0, 0, 0}
+ };
+
+static grub_err_t
+grub_cmd_fwconfig (grub_extcmd_context_t ctxt __attribute__ ((unused)),
+ int argc, char **argv)
+{
+ grub_uint32_t i, j, value = 0;
+ struct grub_qemu_fwcfgfile file;
+ char fwsig[4], signature[4] = { 'Q', 'E', 'M', 'U' };
+
+ if (argc != 2)
+ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("two arguments expected"));
+
+ /* Verify that we have meaningful hardware here */
+ grub_outw(SIGNATURE_INDEX, SELECTOR);
+ for (i=0; i<sizeof(fwsig); i++)
+ fwsig[i] = grub_inb(DATA);
+
+ if (grub_memcmp(fwsig, signature, sizeof(signature)) != 0)
+ return grub_error (GRUB_ERR_BAD_DEVICE, N_("invalid fwconfig hardware signature: got 0x%x%x%x%x"), fwsig[0], fwsig[1], fwsig[2], fwsig[3]);
+
+ /* Find out how many file entries we have */
+ grub_outw(DIRECTORY_INDEX, SELECTOR);
+ value = grub_inb(DATA) | grub_inb(DATA) << 8 | grub_inb(DATA) << 16 | grub_inb(DATA) << 24;
+ value = grub_be_to_cpu32(value);
+ /* Read the file description for each file */
+ for (i=0; i<value; i++)
+ {
+ for (j=0; j<sizeof(file); j++)
+ {
+ ((char *)&file)[j] = grub_inb(DATA);
+ }
+ /* Check whether it matches what we're looking for, and if so read the file */
+ if (grub_strncmp(file.name, argv[0], sizeof(file.name)) == 0)
+ {
+ grub_uint32_t filesize = grub_be_to_cpu32(file.size);
+ grub_uint16_t location = grub_be_to_cpu16(file.select);
+ char *data = grub_malloc(filesize+1);
+
+ if (!data)
+ return grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate buffer for data"));
+
+ grub_outw(location, SELECTOR);
+ for (j=0; j<filesize; j++)
+ {
+ data[j] = grub_inb(DATA);
+ }
+
+ data[filesize] = '\0';
+
+ grub_env_set (argv[1], data);
+
+ grub_free(data);
+ return 0;
+ }
+ }
+
+ return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("couldn't find entry %s"), argv[0]);
+}
+
+GRUB_MOD_INIT(fwconfig)
+{
+ cmd_read_fwconfig =
+ grub_register_extcmd ("fwconfig", grub_cmd_fwconfig, 0,
+ N_("PATH VAR"),
+ N_("Set VAR to the contents of fwconfig PATH"),
+ options);
+}
+
+GRUB_MOD_FINI(fwconfig)
+{
+ grub_unregister_extcmd (cmd_read_fwconfig);
+}
diff --git a/grub-core/commands/gptprio.c b/grub-core/commands/gptprio.c
new file mode 100644
index 000000000..4a24fa62d
--- /dev/null
+++ b/grub-core/commands/gptprio.c
@@ -0,0 +1,223 @@
+/* gptprio.c - manage priority based partition selection. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ * Copyright (C) 2014 CoreOS, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/device.h>
+#include <grub/env.h>
+#include <grub/err.h>
+#include <grub/extcmd.h>
+#include <grub/gpt_partition.h>
+#include <grub/i18n.h>
+#include <grub/misc.h>
+
+GRUB_MOD_LICENSE ("GPLv3+");
+
+static const struct grub_arg_option options_next[] = {
+ {"set-device", 'd', 0,
+ N_("Set a variable to the name of selected partition."),
+ N_("VARNAME"), ARG_TYPE_STRING},
+ {"set-uuid", 'u', 0,
+ N_("Set a variable to the GPT UUID of selected partition."),
+ N_("VARNAME"), ARG_TYPE_STRING},
+ {0, 0, 0, 0, 0, 0}
+};
+
+enum options_next
+{
+ NEXT_SET_DEVICE,
+ NEXT_SET_UUID,
+};
+
+static unsigned int
+grub_gptprio_priority (struct grub_gpt_partentry *entry)
+{
+ return (unsigned int) grub_gpt_entry_attribute
+ (entry, GRUB_GPT_PART_ATTR_OFFSET_GPTPRIO_PRIORITY, 4);
+}
+
+static unsigned int
+grub_gptprio_tries_left (struct grub_gpt_partentry *entry)
+{
+ return (unsigned int) grub_gpt_entry_attribute
+ (entry, GRUB_GPT_PART_ATTR_OFFSET_GPTPRIO_TRIES_LEFT, 4);
+}
+
+static void
+grub_gptprio_set_tries_left (struct grub_gpt_partentry *entry,
+ unsigned int tries_left)
+{
+ grub_gpt_entry_set_attribute
+ (entry, tries_left, GRUB_GPT_PART_ATTR_OFFSET_GPTPRIO_TRIES_LEFT, 4);
+}
+
+static unsigned int
+grub_gptprio_successful (struct grub_gpt_partentry *entry)
+{
+ return (unsigned int) grub_gpt_entry_attribute
+ (entry, GRUB_GPT_PART_ATTR_OFFSET_GPTPRIO_SUCCESSFUL, 1);
+}
+
+static grub_err_t
+grub_find_next (const char *disk_name,
+ const grub_gpt_part_type_t *part_type,
+ char **part_name, char **part_guid)
+{
+ struct grub_gpt_partentry *part, *part_found = NULL;
+ grub_device_t dev = NULL;
+ grub_gpt_t gpt = NULL;
+ grub_uint32_t i, part_index;
+
+ dev = grub_device_open (disk_name);
+ if (!dev)
+ goto done;
+
+ gpt = grub_gpt_read (dev->disk);
+ if (!gpt)
+ goto done;
+
+ if (grub_gpt_repair (dev->disk, gpt))
+ goto done;
+
+ for (i = 0; (part = grub_gpt_get_partentry (gpt, i)) != NULL; i++)
+ {
+ if (grub_memcmp (part_type, &part->type, sizeof (*part_type)) == 0)
+ {
+ unsigned int priority, tries_left, successful, old_priority = 0;
+
+ priority = grub_gptprio_priority (part);
+ tries_left = grub_gptprio_tries_left (part);
+ successful = grub_gptprio_successful (part);
+
+ if (part_found)
+ old_priority = grub_gptprio_priority (part_found);
+
+ if ((tries_left || successful) && priority > old_priority)
+ {
+ part_index = i;