Skip to content

Commit 4d6c8d1

Browse files
committed
SKL header: add AMD-specific header information
Add AMD-supplied SKL header values. We are waiting for AMD to provide a definition for this header, which is unavailable in the DRTM spec. SKINIT instruction fails without these header values Signed-off-by: Jagannathan Raman <[email protected]>
1 parent 602d0d4 commit 4d6c8d1

File tree

5 files changed

+125
-2
lines changed

5 files changed

+125
-2
lines changed

Makefile

+6-1
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,18 @@ all: skl.bin
5757
-include Makefile.local
5858

5959
# Generate a flat binary
60-
#
60+
ifeq ($(AMDSL), n)
6161
# As a sanity check, look for the SKL UUID at its expected offset in the binary
6262
# image. One reason this might fail is if the linker decides to put an
6363
# unreferenced section ahead of .text, in which case link.lds needs adjusting.
6464
skl.bin: skl Makefile
6565
objcopy -O binary -S -R '.note.*' -R '.got.plt' $< $@
6666
@./sanity_check.sh
67+
else
68+
skl.bin: skl Makefile
69+
objcopy -O binary -S $< $@
70+
python3 header_tool.py --image=skl.bin --version=0x02000200 --spl=0x00000001 --output=AmdSl_debug.BIN
71+
endif
6772

6873
skl: link.lds $(OBJ) Makefile
6974
$(CC) -Wl,-T,link.lds $(LDFLAGS) $(OBJ) -o $@

head.S

+24
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,33 @@
3030

3131
.section .headers, "ax", @progbits
3232

33+
/**
34+
* sl_header: AMD-SL header
35+
*
36+
* We only know about some of the fields in this header, such as the
37+
* entry point and AMD-SL length. The remaining portions are assumed
38+
* to be proprietary information, and we don't have access to them.
39+
*
40+
* We received the following values from AMD and needed to know what
41+
* they meant. AMD did not respond to our query for details about this
42+
* header, and the DRTM spec does not define the fields.
43+
*/
3344
GLOBAL(sl_header)
3445
.word _entry /* SL header SKL offset to code start */
3546
.word _end_of_measured /* SL header SKL measured length */
47+
.byte 0xda, 0x75, 0xc4, 0x0e, 0xd0, 0xd3, 0x5d, 0x48, 0xb6, 0xae, 0x3c, 0xb2, 0xf, 0xb7, 0xad, 0x3a
48+
.long 0xffffffff
49+
.long 0xaaaa5555
50+
.word 0x1E
51+
.long 0x00000008
52+
.long 0x00860f00
53+
.long 0x00a50f00
54+
.long 0x00a40f00
55+
.long 0x00a70f00
56+
.long 0x00a00f00
57+
.long 0x00a10f00
58+
.long 0x00a80f00
59+
.long 0x00aa0f00
3660
.word skl_info /* Offset to SKL info with UUID and version */
3761
.word bootloader_data /* Offset to SLRT filled by the bootloader */
3862
ENDDATA(sl_header)

header_tool.py

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/usr/bin/env python
2+
3+
#
4+
# Copyright (C) 2018 Advanced Micro Devices, Inc. All rights reserved.
5+
#
6+
# The purpose of this script is to prepend a provided psp signature header to
7+
# a provided binary and update the psp header with the provided firmware
8+
# version and optionally type
9+
# The tool can also be used just to update an existing header
10+
#
11+
12+
import sys
13+
import getopt
14+
import os
15+
import binascii
16+
from array import array
17+
18+
HEADER_VERSION = 0x31534124
19+
HEADER_VERSION_OFFSET_IN_BYTES = 0x10
20+
SIZEFWSIGNED_HEADER_OFFSET_IN_BYTES = 0x14
21+
SECURITY_PATCH_LEVEL_HEADER_OFFSET_IN_BYTES = 0x4C
22+
IMAGEVERSION_HEADER_OFFSET_IN_BYTES = 0x60
23+
HEADER_SIZE_BYTES = 0x100
24+
25+
def main(argv):
26+
# Process the command line for the parameters for the build
27+
try:
28+
opts, args = getopt.getopt(argv, "i:v:s:o:",
29+
["image=", "version=", "spl=", "output="])
30+
except getopt.GetoptError:
31+
print("header_tool.py --image=<firmware image> --version=<firmware version> --spl=<spl version> --output=<output filename>")
32+
sys.exit(2)
33+
34+
# Save the arguments
35+
for opt, arg in opts:
36+
if opt in ("-i", "--image"):
37+
image_filename = arg
38+
elif opt in ("-v", "--version"):
39+
version = arg
40+
elif opt in ("-o", "--output"):
41+
output_filename = arg
42+
elif opt in ("-s", "--spl"):
43+
spl = arg
44+
45+
# Check that all parameters were correctly received
46+
try:
47+
image_filename
48+
version
49+
spl
50+
output_filename
51+
except NameError:
52+
print("header_tool.py --image=<firmware image> --version=<firmware version> --spl=<security patch level> --output=<output filename>")
53+
sys.exit(2)
54+
55+
if os.path.isfile(image_filename) != True:
56+
print("header_tool.py ERROR: " + image_filename + " does not exist")
57+
sys.exit(2)
58+
59+
image = array('I')
60+
input_file = open(image_filename, "rb")
61+
62+
image.frombytes(input_file.read())
63+
AmdSlSize = image[0]
64+
AmdSlSize = AmdSlSize >> 16
65+
66+
if (AmdSlSize % 16 != 0):
67+
AmdSlSize = AmdSlSize + (16 - (AmdSlSize % 16))
68+
image[0] = image[0] & 0xFF
69+
image[0] = image[0] | (AmdSlSize << 16)
70+
71+
if (os.path.getsize(image_filename) != (64 * 1024)):
72+
print("Error: AmdSL binary is not size is not equal to 64K ")
73+
74+
AmdSlSizeInInt = AmdSlSize >> 2
75+
76+
# Store the ASCI of "$AS1" in header version
77+
image[AmdSlSizeInInt + int(HEADER_VERSION_OFFSET_IN_BYTES/4)] = HEADER_VERSION
78+
# Store the AmdSL Size
79+
image[AmdSlSizeInInt + int(SIZEFWSIGNED_HEADER_OFFSET_IN_BYTES/4)] = AmdSlSize
80+
image[AmdSlSizeInInt + int(IMAGEVERSION_HEADER_OFFSET_IN_BYTES/4)] = int(version, 16)
81+
image[AmdSlSizeInInt + int(SECURITY_PATCH_LEVEL_HEADER_OFFSET_IN_BYTES/4)] = int(spl, 16)
82+
83+
# Since Input and output files may be the same close all files before doing output
84+
output_file = open(output_filename, "wb")
85+
86+
# Write the output
87+
output_file.write(image)
88+
output_file.close()
89+
90+
print("header_tool: completed successfully")
91+
92+
if __name__ == "__main__":
93+
main(sys.argv[1:])

include/boot.h

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ extern const char _end_of_measured[];
4545
typedef struct __packed sl_header {
4646
u16 skl_entry_point;
4747
u16 skl_measured_size;
48+
u8 reserved[62];
4849
u16 skl_info_offset;
4950
u16 bootloader_data_offset;
5051
} sl_header_t;

sanity_check.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
. util.sh
33

4-
SKL_INFO=`hexdump "$SLB_FILE" -s4 -n2 -e '/2 "%u"'`
4+
SKL_INFO=`hexdump "$SLB_FILE" -s66 -n2 -e '/2 "%u"'`
55

66
if ! od --format=x8 --skip-bytes=$SKL_INFO --read-bytes=16 $SLB_FILE | grep -q "e91192048e26f178 02ccc4765bc82a83"; then
77
echo "ERROR: SKL UUID missing or misplaced in $SLB_FILE" >&2

0 commit comments

Comments
 (0)