Skip to content

Commit 7186da9

Browse files
WIP 2
Signed-off-by: Krystian Hebel <[email protected]>
1 parent 2b44084 commit 7186da9

File tree

5 files changed

+65
-67
lines changed

5 files changed

+65
-67
lines changed

Makefile

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,23 @@ all: skl.bin
5757
-include Makefile.local
5858

5959
# Generate a flat binary
60-
ifeq ($(AMDSL), n)
6160
# As a sanity check, look for the SKL UUID at its expected offset in the binary
6261
# image. One reason this might fail is if the linker decides to put an
6362
# unreferenced section ahead of .text, in which case link.lds needs adjusting.
6463
skl.bin: skl Makefile
65-
objcopy -O binary -S -R '.note.*' -R '.got.plt' $< $@
64+
@# first binary skips signature-related sections to ease up signing process
65+
objcopy -O binary -S -R '.note.*' -R '.got.plt' -R '.skl_sig' -R '.skl_pubkey_hdr' -R '.skl_pubkey_modulus' $< $@
66+
@./sanity_check.sh
67+
ifeq ($(AMDSL), y)
68+
# create signature
69+
openssl dgst -sha384 -sign testPrivateKey.pem -out signature_rev.bin -binary -sigopt rsa_padding_mode:pss $@
70+
# reverse byte order
71+
xxd -c1 -p signature_rev.bin | tac | xxd -r -p > signature.bin
72+
# get the modulus for pubkey header, reverse byte order
73+
openssl rsa -in testPrivateKey.pem -modulus -noout | sed -e "s/Modulus=//" -e "s/../&\n/g" | tac | xxd -r -p > pubkey_mod.bin
74+
# stitch binary again with all the pieces in place
75+
objcopy -O binary -S -R '.note.*' -R '.got.plt' --update-section .skl_sig=signature.bin --update-section .skl_pubkey_modulus=pubkey_mod.bin $< $@
6676
@./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-
./AmdSlSigningTool -i AmdSl_debug.BIN -o AmdSl_debug.BIN.sign
7277
endif
7378

7479
skl: link.lds $(OBJ) Makefile
@@ -109,6 +114,7 @@ cscope:
109114

110115
.PHONY: clean
111116
clean:
117+
# rm -f *.bin
112118
rm -f skl.bin skl $(TESTS) *.d *.o *.gcov *.gcda *.gcno tpmlib/*.d tpmlib/*.o cscope.*
113119

114120
# Compiler-generated header dependencies. Should be last.

head.S

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ GLOBAL(sl_header)
4646
.word _end_of_measured /* SL header SKL measured length */
4747
.byte 0xda, 0x75, 0xc4, 0x0e, 0xd0, 0xd3, 0x5d, 0x48, 0xb6, 0xae, 0x3c, 0xb2, 0xf, 0xb7, 0xad, 0x3a
4848
.long 0xffffffff /* Reserved */
49-
.long 0xaaaa5555 /* Total Length including signature and pubkey raw data */
49+
.long _end_of_signed + 0x640 /* Total Length including signature and pubkey raw data */
5050
.word soc_flag /* Offset to SOCFLAG Structure, see below */
5151
.word skl_info /* Offset to SKL info with UUID and version */
5252
.word bootloader_data /* Offset to SLRT filled by the bootloader */
@@ -320,11 +320,42 @@ gdt:
320320
.Lgdt_end:
321321
ENDDATA(gdt)
322322

323-
/*
324-
.section .skinit_reserved, "a", @progbits
325-
GLOBAL(skinit_reserved)
326-
.fill 0x740, 1, 0x00
327-
*/
323+
#ifdef AMDSL
324+
.section .skl_sig_hdr, "a", @progbits
325+
.fill 16, 1, 0x00 /* Nonce */
326+
.long 0x31534124 /* HeaderVersion, "$AS1" */
327+
.long _end_of_signed /* Signed Fw Size in bytes */
328+
.fill 4+4+16, 1, 0x00 /* Encryption options, algorithm ID and parameters */
329+
.long 1 /* SigOption, 1 - signed */
330+
.long 0 /* SigAlgID, unknown encoding */
331+
.byte KEY_ID /* Key ID */
332+
.long 0 /* Compression option */
333+
.long 1 /* Security patch level */
334+
.fill 4+4+8, 1, 0x00 /* Uncompr. size, compr. size, compr. parameters */
335+
.long 0x02000200 /* ImageVersion */
336+
.fill 4+4, 1, 0x00 /* APU Family ID and Firmware Load Address */
337+
.long _end_of_signed + 0x200 /* FW size with signature */
338+
.fill 4+4+4+1+1+2+16+16+96 /* The rest */
339+
340+
/* Signature is filled during final objcopy */
341+
.section .skl_sig, "a", @progbits
342+
.fill 0x200, 1, 0x00
343+
344+
.section .skl_pubkey_hdr, "a", @progbits
345+
.long 2 /* Version ID */
346+
.byte KEY_ID /* Key ID */
347+
.byte KEY_ID /* Certifying key ID */
348+
.fill 4+1+1+14, 1, 0x00 /* Key usage, platform vendor ID, model ID, reserved */
349+
.long 4096 /* Public exponent size in bits */
350+
.long 4096 /* Modulus size in bits */
351+
352+
.long 0x10001 /* Exponent */
353+
.fill 508, 1, 0x00 /* XXX: does it have to be so oversized? */
354+
355+
/* Modulus is stored in a dedicated section, filled during final objcopy */
356+
.section .skl_pubkey_modulus, "a", @progbits
357+
.fill 0x200, 1, 0x00
358+
#endif
328359

329360
#ifdef __x86_64__
330361
/* 64bit Pagetables, identity map of the first 4G of RAM. */

include/defs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,6 @@
128128

129129
#define MULTIBOOT2_BOOTLOADER_MAGIC 0x36d76289
130130

131+
#define KEY_ID 0x93, 0xE5, 0x43, 0x34, 0x3B, 0x41, 0x46, 0xFF, 0x96, 0x8A, 0xA2, 0x4D, 0xF5, 0x12, 0x02, 0x9A
132+
131133
#endif /* __DEFS_H__ */

link.lds

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ SECTIONS
3636
* PCR 17 is extended with SKL padded with zeros up to a size that is
3737
* aligned up to the multiply of 4B. To keep functions in util.sh
3838
* simple, _end_of_measured is explicitly aligned. This may increase
39-
* skl.bin size by up to 3 bytes, but since next section is aligned to
40-
* 4K anyway this doesn't reduce the amount of available space, neither
41-
* does it increase the real size of data sent to TPM to be measured.
39+
* skl.bin size by up to 3 bytes, but it doesn't increase the real size
40+
* of data sent to TPM to be measured.
4241
*
4342
* Note that this padding must be part of .rodata to be included in
4443
* skl.bin, both for 'dd' used in util.sh and for checks performed by
@@ -49,8 +48,6 @@ SECTIONS
4948

5049
_end_of_measured = .;
5150

52-
. = ALIGN(16);
53-
5451
.skl_sig_hdr : {
5552
*(.skl_sig_hdr)
5653
}
@@ -61,8 +58,12 @@ SECTIONS
6158
*(.skl_sig)
6259
}
6360

64-
.skl_pubkey : {
65-
*(.skl_pubkey)
61+
.skl_pubkey_hdr : {
62+
*(.skl_pubkey_hdr)
63+
}
64+
65+
.skl_pubkey_modulus : {
66+
*(.skl_pubkey_modulus)
6667
}
6768

6869
.bss : {
@@ -89,8 +90,6 @@ SECTIONS
8990
*(.bootloader_data)
9091
}
9192

92-
. = 0xFFF4;
93-
9493
_end = .;
9594

9695
/* This section is expected to be empty. */
@@ -121,6 +120,11 @@ ASSERT(_end <= 0x10000, "Landing Zone exceeds 64k");
121120
ASSERT(SIZEOF(.got) == 0, ".got section not empty - non-hidden symbols used?");
122121
ASSERT(SIZEOF(.data) == 0, ".data section not empty - initialized data used?");
123122

123+
ASSERT(!SIZEOF(.skl_sig_hdr) || SIZEOF(.skl_sig_hdr) == 0x100,
124+
".skl_sig_hdr size not 256 bytes");
125+
ASSERT(!SIZEOF(.skl_pubkey_hdr) || SIZEOF(.skl_pubkey_hdr) == 0x240,
126+
".skl_pubkey_hdr size not 0x240 bytes");
127+
124128
/*
125129
* At least GNU ld 2.30 and earlier fail to discard the generic part of
126130
* .got.plt when no actual entries were allocated. Permit this case alongside

main.c

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -40,51 +40,6 @@ const skl_info_t __used skl_info = {
4040
.version = 0,
4141
};
4242

43-
#if !defined(AMDSL)
44-
typedef struct tdFW_SIG_HEADER
45-
{
46-
u8 Nonce[16]; /* [0x00] Unique image id */
47-
u32 HeaderVersion; /* [0x10] Version of the header */
48-
u32 SizeFWSigned; /* [0x14] Signed Fw Size in bytes */
49-
u32 EncOption; /* [0x18] 0 - Not encrypted, 1 - encrypted */
50-
u32 EncAlgID; /* [0x1C] Encryption algorithm id */
51-
u8 EncParameters[16]; /* [0x20] Encryption Parameters */
52-
u32 SigOption; /* [0x30] 0 - not signed 1 - signed */
53-
u32 SigAlgID; /* [0x34] Signature algorithm ID */
54-
u8 SigParameters[16]; /* [0x38] Signature parameter */
55-
u32 CompOption; /* [0x48] Compression option */
56-
u32 SecPatchLevel; /* [0x4C] Security patch level */
57-
u32 UnCompImageSize; /* [0x50] Uncompressed Image Size */
58-
u32 CompImageSize; /* [0x54] compressed Image Size */
59-
u8 CompParameters[8]; /* [0x58] Compression Parameters */
60-
u32 ImageVersion; /* [0x60] Off Chip Firmware Version */
61-
u32 APUFamilyID; /* [0x64] APU Family ID or SoC ID */
62-
u32 FirmwareLoadAddr; /* [0x68] Firmware Load address (default 0) */
63-
u32 SizeImage; /* [0x6C] FW size with signature */
64-
u32 SizeFWUnSigned; /* [0x70] Size of Un-signed portion of the FW */
65-
u32 FirmwareSplitAddr; /* [0x74] Offset of Nwd OS */
66-
u32 SigFlags; /* [0x78] Flags for FW signing options, perm, etc */
67-
u8 FwType; /* [0x7C] FwType */
68-
u8 SubType; /* [0x7D] SubType identifies FW */
69-
u8 Reserved1[2]; /* [0x7E] *** RESERVED *** */
70-
u8 EncKey[16]; /* [0x80] Encryption Key (Wrapped MEK) */
71-
u8 SigningInfo[16]; /* [0x90] Signing tool specific information */
72-
u8 Padd[96]; /* [0xA0] *** RESERVED *** */
73-
} FW_SIG_HEADER; /* Total 256 bytes */
74-
75-
extern char _end_of_signed[];
76-
77-
FW_SIG_HEADER __section(".skl_sig_hdr") __used hdr = {
78-
.HeaderVersion = 0x31534124, /* "$AS1" */
79-
.SizeFWSigned = _u(_end_of_signed),
80-
.SigOption = 1,
81-
.SigParameters = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
82-
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}, /* TBD! */
83-
.ImageVersion = 0x02000200,
84-
.SizeImage = _u(_end_of_signed) + 0x200,
85-
};
86-
#endif
87-
8843
#if !defined(AMDSL)
8944
static void extend_pcr(struct tpm *tpm, void *data, u32 size, u32 pcr, char *ev)
9045
{

0 commit comments

Comments
 (0)