From 1a258b1caf1e7e9fa7f8099e74efc1078ff3336d Mon Sep 17 00:00:00 2001 From: haxar Date: Thu, 6 Oct 2022 17:48:25 -0700 Subject: [PATCH] boot: Move PIC challenge to 1BL low ROM, before 2BL RAM copy --- boot_rom/2bBootStartBios.c | 12 +++--------- boot_rom/2bBootStartup.S | 8 +++++--- boot_rom/2bPicResponseAction.c | 31 ++++++++++++++++++++++++++++++- boot_rom/2bload.h | 3 ++- 4 files changed, 40 insertions(+), 14 deletions(-) diff --git a/boot_rom/2bBootStartBios.c b/boot_rom/2bBootStartBios.c index b576b607..2ab065ca 100644 --- a/boot_rom/2bBootStartBios.c +++ b/boot_rom/2bBootStartBios.c @@ -261,12 +261,9 @@ void BootStartBiosLoader(void) SHA1Input(&context,(void*)(PROGRAMM_Memory_2bl+20),bootloadersize-20); SHA1Result(&context,SHA1_result); - if (memcmp(&bootloaderChecksum[0],&SHA1_result[0],20)==0) { - // HEHE, the Image we copy'd into ram is SHA-1 hash identical, this is Optimum - BootPerformPicChallengeResponseAction(); - - } else { - // Bad, the checksum does not match, but we can nothing do now, we wait until PIC kills us + if (memcmp(&bootloaderChecksum[0],&SHA1_result[0],20)) { + // Bad, the checksum does not match, we did not get a valid image to RAM, we stop and display an error + setLED("rrrr"); while(1); } @@ -358,9 +355,6 @@ void BootStartBiosLoader(void) // We are not Longer here } - // Bad, we did not get a valid im age to RAM, we stop and display a error - //setLED("rrrr"); - setLED("oooo"); // I2CTransmitWord(0x10, 0x1901); // no reset on eject diff --git a/boot_rom/2bBootStartup.S b/boot_rom/2bBootStartup.S index 077e0264..68b306a2 100644 --- a/boot_rom/2bBootStartup.S +++ b/boot_rom/2bBootStartup.S @@ -211,6 +211,11 @@ cld + // Set the stack pointer to give us a valid stack + movl $0x1ffff0, %esp + + call pic_challenge_response + // copy everything into RAM mov $_ram_location, %edi @@ -309,9 +314,6 @@ reload_cs: mov %eax, %fs mov %eax, %gs - // Set the stack pointer to give us a valid stack - movl $0x1ffff0, %esp - // Clear out .bss xor %eax, %eax mov $BSS_SIZE_L, %ecx diff --git a/boot_rom/2bPicResponseAction.c b/boot_rom/2bPicResponseAction.c index 8149240f..463ef8f6 100644 --- a/boot_rom/2bPicResponseAction.c +++ b/boot_rom/2bPicResponseAction.c @@ -84,7 +84,7 @@ int I2CTransmitWord(u8 bPicAddressI2cFormat, u16 wDataToWrite) } return ERR_I2C_ERROR_BUS; } - +#if 0 // ---------------------------- PIC challenge/response ----------------------------------------------------------- // // given four bytes, returns a u16 @@ -143,6 +143,35 @@ int BootPerformPicChallengeResponseAction() // continues as part of video setup.... return ERR_SUCCESS; } +#endif +void pic_challenge_response(void) +{ + register u8 x1c, x1d, x1e, x1f; + register u8 b1, b2, b3, b4; + register int i; + + smbus_set_addr(0x21); /* set PIC address; read command */ + x1c = smbus_read(0x1c); + x1d = smbus_read(0x1d); + x1e = smbus_read(0x1e); + x1f = smbus_read(0x1f); + + b1 = 0x33; + b2 = 0xed; + b3 = x1c << 2; + b3 ^= x1d + 0x39; + b3 ^= x1e >> 2; + b3 ^= x1f + 0x63; + b4 = x1c + 0x0b; + b4 ^= x1d >> 2; + b4 ^= x1e + 0x1b; + + for (i = 0; i < 4; b1 += b2 ^ b3, b2 += b1 ^ b4, ++i); + + smbus_set_addr(0x20); /* set PIC address; write command */ + smbus_write(0x20, b1); + smbus_write(0x21, b2); +} extern int I2cSetFrontpanelLed(u8 b) { diff --git a/boot_rom/2bload.h b/boot_rom/2bload.h index 499fe475..695067d7 100644 --- a/boot_rom/2bload.h +++ b/boot_rom/2bload.h @@ -168,7 +168,8 @@ static INLINE u8 smbus_read(u8 cmd) } // boot process -int BootPerformPicChallengeResponseAction(void); +//int BootPerformPicChallengeResponseAction(void); +void pic_challenge_response(void) __attribute__((section(".low_rom"),aligned(16))); // LED control (see associated enum above) int I2cSetFrontpanelLed(u8 b); int I2cResetFrontpanelLed(void);