Skip to contentSkip to conversation

TCG Bios extensions

PATCH In review Stefan Berger 2 participants 3 messages Jan 3, 2007 – Jan 26, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 2/3 TCG Bios extensions

This patch adds TCG BIOS extensions to the high memory area along with some often-used libc utility functions. The TCG extensions are described here:

https://www.trustedcomputinggroup.org/specs/PCClient/TCG_PCClientImplementationforBIOS_1-20_1-00.pdf

I have tried to keep the patching with rombios.c to a minimum, but some amount of code needs to be inserted at various locations.

The code is currently deactivated, but can be activated by setting BX_TCGBIOS to '1'.

xen-unstable.hg/tools/firmware/rombios/rombios.c +61 -1
Index: root/xen-unstable.hg/tools/firmware/rombios/rombios.c
===================================================================
@@ -154,6 +154,8 @@
 #define BX_USE_ATADRV    1
 #define BX_ELTORITO_BOOT 1
 
+#define BX_TCGBIOS       0              /* main switch for TCG BIOS ext. */
+
 #define BX_MAX_ATA_INTERFACES   4
 #define BX_MAX_ATA_DEVICES      (BX_MAX_ATA_INTERFACES*2)
 
@@ -1847,6 +1849,9 @@ print_bios_banner()
 {
   printf(BX_APPNAME" BIOS, %d cpu%s, ", BX_SMP_PROCESSORS, BX_SMP_PROCESSORS>1?"s":"");
   printf("%s %s\n", bios_cvs_version_string, bios_date_string);
+#if BX_TCGBIOS
+  printf("TCG-enabled BIOS.\n");
+#endif
   printf("\n");
   test_gateway();
 }
@@ -7658,7 +7663,9 @@ ASM_END
       return 0x00000000;
       }
     }
-
+#if BX_TCGBIOS
+    tcpa_add_bootdevice((Bit32u)0, (Bit32u)bootdrv);
+#endif
   // check signature if instructed by cmos reg 0x38, only for floppy
   // bootchk = 1 : signature check disabled
   // bootchk = 0 : signature check enabled
@@ -7677,6 +7684,10 @@ ASM_END
       return 0x00000000;
       }
     }
+
+#if BX_TCGBIOS
+  tcpa_ipl((Bit32u)bootseg);               /* specs: 8.2.3 steps 4 and 5 */
+#endif
   
 #if BX_ELTORITO_BOOT
   // Print out the boot string
@@ -9408,6 +9419,9 @@ rom_scan:
   ;;   2         ROM length in 512-byte blocks
   ;;   3         ROM initialization entry point (FAR CALL)
 
+#if BX_TCGBIOS
+  call _tcpa_start_option_rom_scan    /* specs: 3.2.3.3 + 10.4.3 */
+#endif
   mov  cx, #0xc000
 rom_scan_loop:
   mov  ds, cx
@@ -9426,6 +9440,20 @@ rom_scan_loop:
   add  al, #0x04
 block_count_rounded:
 
+#if BX_TCGBIOS
+  push ax
+  push ds
+  push ecx
+  xor ax, ax
+  mov ds, ax
+  and ecx, #0xffff
+  push ecx       ;; segment where option rom is located at
+  call _tcpa_option_rom                   /* specs: 3.2.3.3 */
+  add sp, #4    ;; pop segment
+  pop ecx	;; original ecx
+  pop ds
+  pop ax
+#endif
   xor  bx, bx   ;; Restore DS back to 0000:
   mov  ds, bx
   push ax       ;; Save AX
@@ -9691,6 +9719,16 @@ post_default_ints:
   in   al, 0x71
   mov  0x0410, ax
 
+#if BX_TCGBIOS
+  call _tcpa_acpi_init
+
+  push dword #0
+  call _tcpa_initialize_tpm
+  add sp, #4
+
+  call _tcpa_do_measure_POSTs
+  call _tcpa_wake_event     /* specs: 3.2.3.7 */
+#endif
 
   ;; Parallel setup
   SET_INT_VECTOR(0x0F, #0xF000, #dummy_iret_handler)
@@ -9811,9 +9849,16 @@ post_default_ints:
   ;;
 #endif // BX_ELTORITO_BOOT
  
+#if BX_TCGBIOS
+  call _tcpa_calling_int19h          /* specs: 8.2.3 step 1 */
+  call _tcpa_add_event_separators    /* specs: 8.2.3 step 2 */
+#endif
   int  #0x19
   //JMP_EP(0x0064) ; INT 19h location
 
+#if BX_TCGBIOS
+  call _tcpa_returned_int19h         /* specs: 8.2.3 step 3/7 */
+#endif
 
 .org 0xe2c3 ; NMI Handler Entry Point
 nmi:
@@ -10296,6 +10341,21 @@ db 0x00    ;; base  23:16
 ;----------
 .org 0xfe6e ; INT 1Ah Time-of-day Service Entry Point
 int1a_handler:
+#if BX_TCGBIOS
+  cmp  ah, #0xbb
+  jne  no_tcg
+  pushf
+  push ds
+  push es
+  pushad
+  call _int1a_function32
+  popad
+  pop es
+  pop ds
+  popf
+  iret
+no_tcg:
+#endif
 #if BX_PCIBIOS
   cmp  ah, #0xb1
   jne  int1a_normal
xen-unstable.hg/tools/firmware/rombios/tcgbios.c new file +263 -0

263 lines not on this page · raw message

xen-unstable.hg/tools/firmware/rombios/Makefile +1 -1
Index: root/xen-unstable.hg/tools/firmware/rombios/Makefile
===================================================================
@@ -12,7 +12,7 @@ clean:
 	rm -f  rombios*.txt rombios*.sym usage biossums
 	rm -f  BIOS-bochs-*
 
-BIOS-bochs-latest: rombios.c biossums 32bitgateway.c
+BIOS-bochs-latest: rombios.c biossums 32bitgateway.c tcgbios.c
 	gcc -DBX_SMP_PROCESSORS=1 -E -P $< > _rombios_.c
 	bcc -o rombios.s -C-c -D__i86__ -0 -S _rombios_.c
 	sed -e 's/^\.text//' -e 's/^\.data//' rombios.s > _rombios_.s
xen-unstable.hg/tools/firmware/rombios/32bit/32bitbios.c +16 -0
Index: root/xen-unstable.hg/tools/firmware/rombios/32bit/32bitbios.c
===================================================================
@@ -55,6 +55,22 @@ uint32_t jumptable[IDX_LAST+1] __attribu
 	TABLE_ENTRY(IDX_ADD        , add),
 	TABLE_ENTRY(IDX_SET_STATIC , set_static),
 
+	TABLE_ENTRY(IDX_TCPA_ACPI_INIT, tcpa_acpi_init),
+	TABLE_ENTRY(IDX_TCPA_EXTEND_ACPI_LOG, tcpa_extend_acpi_log),
+
+	TABLE_ENTRY(IDX_TCGINTERRUPTHANDLER, TCGInterruptHandler),
+
+	TABLE_ENTRY(IDX_TCPA_CALLING_INT19H, tcpa_calling_int19h),
+	TABLE_ENTRY(IDX_TCPA_RETURNED_INT19H, tcpa_returned_int19h),
+	TABLE_ENTRY(IDX_TCPA_ADD_EVENT_SEPARATORS, tcpa_add_event_separators),
+	TABLE_ENTRY(IDX_TCPA_WAKE_EVENT, tcpa_wake_event),
+	TABLE_ENTRY(IDX_TCPA_ADD_BOOTDEVICE, tcpa_add_bootdevice),
+	TABLE_ENTRY(IDX_TCPA_START_OPTION_ROM_SCAN, tcpa_start_option_rom_scan),
+	TABLE_ENTRY(IDX_TCPA_OPTION_ROM, tcpa_option_rom),
+	TABLE_ENTRY(IDX_TCPA_IPL, tcpa_ipl),
+	TABLE_ENTRY(IDX_TCPA_MEASURE_POST, tcpa_measure_post),
+
+	TABLE_ENTRY(IDX_TCPA_INITIALIZE_TPM, tcpa_initialize_tpm),
 
 	TABLE_ENTRY(IDX_LAST       , 0)     /* keep last */
 };
xen-unstable.hg/tools/firmware/rombios/32bit/Makefile +16 -3
Index: root/xen-unstable.hg/tools/firmware/rombios/32bit/Makefile
===================================================================
@@ -1,17 +1,30 @@
+SOURCES = util.c
 TARGET = 32bitbios_flat.h
 
 CFLAGS = -Wall -Werror -Wunused -Werror-implicit-function-declaration
 CFLAGS += -fomit-frame-pointer -fno-builtin
 CFLAGS += -I../
 
+SUBDIRS = tcgbios
+
 MODULES = 32bitbios.o
+MODULES += tcgbios/tcgbiosext.o
+MODULES += util.o
+
+.PHONY: all subdirs
 
-.PHONY: all
+all : subdirs $(TARGET)
 
-all : $(TARGET)
+subdirs :
+	@for subdir in $(SUBDIRS); do \
+		$(MAKE) -C $$subdir all; \
+	done; \
 
 clean ::
 	rm -rf *.o $(TARGET)
+	@for subdir in $(SUBDIRS); do \
+		$(MAKE) -C $$subdir $@; \
+	done; \
 
 $(TARGET) : 32bitbios_all.o $(SOURCES)
 	unref=`nm -u 32bitbios_all.o`
@@ -22,5 +35,5 @@ $(TARGET) : 32bitbios_all.o $(SOURCES)
 		bash mkhex highbios_array 32bitbios_all.o > $(TARGET); \
 	fi
 
-32bitbios_all.o : 32bitbios.o $(MODULES)
+32bitbios_all.o : $(MODULES)
 	ld -r $(MODULES) -o 32bitbios_all.o
xen-unstable.hg/tools/firmware/rombios/32bit/tcgbios/Makefile new file +18 -0
Index: root/xen-unstable.hg/tools/firmware/rombios/32bit/tcgbios/Makefile
===================================================================
@@ -0,0 +1,18 @@
+TARGET=tcgbiosext.o
+FILES=tcgbios tpm_drivers
+OBJECTS=$(foreach f,$(FILES),$(f).o)
+
+CFLAGS  = -Wall -Werror -Wunused -Werror-implicit-function-declaration
+CFLAGS += -fomit-frame-pointer -fno-builtin -nostdlib
+CFLAGS += -I../ -I../../
+
+all : $(TARGET)
+
+clean::
+	rm -rf *.o $(TARGET)
+
+%.o : %.c
+	gcc $(CFLAGS) -c $^ -o $@
+
+$(TARGET): $(OBJECTS)
+	ld -r $^ -o $@
xen-unstable.hg/tools/firmware/rombios/32bit/tcgbios/tcgbios.c new file +1526 -0

1,526 lines not on this page · raw message

xen-unstable.hg/tools/firmware/rombios/32bit/tcgbios/tcgbios.h new file +288 -0

288 lines not on this page · raw message

xen-unstable.hg/tools/firmware/rombios/32bit/tcgbios/tpm_drivers.c new file +180 -0

180 lines not on this page · raw message

xen-unstable.hg/tools/firmware/rombios/32bit/tcgbios/tpm_drivers.h new file +18 -0
Index: root/xen-unstable.hg/tools/firmware/rombios/32bit/tcgbios/tpm_drivers.h
===================================================================
@@ -0,0 +1,18 @@
+#ifndef TPM_DRIVER_H
+/* low level driver implementation */
+struct tpm_driver {
+	uint32_t baseaddr;
+	uint32_t (*activate)(uint32_t baseaddr);
+	uint32_t (*ready)(uint32_t baseaddr);
+	uint32_t (*senddata)(uint32_t baseaddr, unsigned char *data, uint32_t len);
+	uint32_t (*readresp)(uint32_t baseaddr, unsigned char *buffer, uint32_t len);
+	uint32_t (*waitdatavalid)(uint32_t baseaddr);
+	uint32_t (*waitrespready)(uint32_t baseaddr, uint32_t timeout);
+	uint32_t (*probe)(uint32_t baseaddr);
+};
+
+#define TPM_NUM_DRIVERS      1
+
+#define TPM_INVALID_DRIVER  -1
+
+#endif
xen-unstable.hg/tools/firmware/rombios/32bit/util.c new file +450 -0

450 lines not on this page · raw message

xen-unstable.hg/tools/firmware/rombios/32bit/util.h new file +28 -0
Index: root/xen-unstable.hg/tools/firmware/rombios/32bit/util.h
===================================================================
@@ -0,0 +1,28 @@
+#ifndef UTIL_H
+#define UTIL_H
+
+void outb(uint16_t addr, uint8_t val);
+void outw(uint16_t addr, uint16_t val);
+void outl(uint16_t addr, uint32_t val);
+uint8_t inb(uint16_t addr);
+uint16_t inw(uint16_t addr);
+uint32_t inl(uint16_t addr);
+void mssleep(uint32_t time);
+
+char *itoa(char *a, unsigned int i);
+int strcmp(const char *cs, const char *ct);
+int strncmp(const char *s1, const char *s2, uint32_t n);
+void *memcpy(void *dest, const void *src, unsigned n);
+void *memmove(void *dest, const void *src, unsigned n);
+char *strcpy(char *dest, const char *src);
+char *strncpy(char *dest, const char *src, unsigned n);
+unsigned strlen(const char *s);
+void * memset(void *s, int c, unsigned n);
+int memcmp(const void *s1, const void *s2, unsigned n);
+void cpuid(uint32_t idx, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx);
+void byte_to_hex(char *digits, uint8_t byte);
+void uuid_to_string(char *dest, uint8_t *uuid);
+int printf(const char *fmt, ...);
+
+
+#endif
xen-unstable.hg/tools/firmware/rombios/32bitprotos.h +37 -4

42 lines not on this page · raw message

xen-unstable.hg/tools/firmware/rombios/32bitgateway.c +2 -0
Index: root/xen-unstable.hg/tools/firmware/rombios/32bitgateway.c
===================================================================

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

Part of the diff is not shown here. View the raw message.

#1 lore raw

All this stuff is now applied, but one chunk failed. The area of code where you added the call to tcpa_add_bootdevice() has gone away, probably due to Tim Deegan's changes to support network boot. You'll have to work out the new place to put it.

-- Keir

Quoted 12 lines · Stefan Berger

This patch adds TCG BIOS extensions to the high memory area along with some often-used libc utility functions. The TCG extensions are described here:

https://www.trustedcomputinggroup.org/specs/PCClient/TCG_PCClientImplementatio
nforBIOS_1-20_1-00.pdf

I have tried to keep the patching with rombios.c to a minimum, but some amount of code needs to be inserted at various locations.

The code is currently deactivated, but can be activated by setting BX_TCGBIOS to '1'.

#2 lore raw

Thanks. I will have a look.

Stefan

Keir Fraser <[email protected]> wrote on 01/26/2007 11:47:51 AM:

Quoted 1 line

All this stuff is now applied, but one chunk failed. The area of code

where

Quoted 1 line

you added the call to tcpa_add_bootdevice() has gone away, probably due

to

Quoted 1 line

Tim Deegan's changes to support network boot. You'll have to work out

the

Quoted 8 lines

new place to put it.

-- Keir

Quoted 2 lines · Stefan Berger

This patch adds TCG BIOS extensions to the high memory area along with some often-used libc utility functions. The TCG extensions are

described

Quoted 7 lines
Quoted 3 lines

here:

https://www.trustedcomputinggroup.

org/specs/PCClient/TCG_PCClientImplementatio

Quoted 3 lines

nforBIOS_1-20_1-00.pdf

I have tried to keep the patching with rombios.c to a minimum, but

some

Quoted 6 lines
Quoted 4 lines

amount of code needs to be inserted at various locations.

The code is currently deactivated, but can be activated by setting BX_TCGBIOS to '1'.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel