Skip to content

Commit

Permalink
boot: Move PIC challenge to 1BL low ROM, before 2BL RAM copy
Browse files Browse the repository at this point in the history
  • Loading branch information
haxar committed Oct 7, 2022
1 parent f1ad8cf commit 1a258b1
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
12 changes: 3 additions & 9 deletions boot_rom/2bBootStartBios.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions boot_rom/2bBootStartup.S
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
31 changes: 30 additions & 1 deletion boot_rom/2bPicResponseAction.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down
3 changes: 2 additions & 1 deletion boot_rom/2bload.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1a258b1

Please sign in to comment.