diff --git a/boot_rom/2bBootStartBios.c b/boot_rom/2bBootStartBios.c index b576b60..8fa1e9d 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 copied to RAM, so 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 077e026..4099360 100644 --- a/boot_rom/2bBootStartup.S +++ b/boot_rom/2bBootStartup.S @@ -211,8 +211,12 @@ cld - // copy everything into RAM + // Set the stack pointer to give us a valid stack + movl $0x1ffff0, %esp + + call pic_challenge_response + // Copy 2BL into RAM mov $_ram_location, %edi mov $_start_ramcopy, %esi mov $(_size_ramcopy + 100), %ecx @@ -309,9 +313,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 8149240..685e07e 100644 --- a/boot_rom/2bPicResponseAction.c +++ b/boot_rom/2bPicResponseAction.c @@ -14,6 +14,36 @@ #include "2bload.h" +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 */ + smbus_read_start(0x1c); + if (!smbus_cycle_completed()) return; + x1c = smbus_read_data(); + 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); +} // ---------------------------- I2C ----------------------------------------------------------- // @@ -85,65 +115,6 @@ int I2CTransmitWord(u8 bPicAddressI2cFormat, u16 wDataToWrite) return ERR_I2C_ERROR_BUS; } -// ---------------------------- PIC challenge/response ----------------------------------------------------------- -// -// given four bytes, returns a u16 -// LSB of return is the 'first' byte, MSB is the 'second' response byte - -u16 BootPicManipulation( - u8 bC, - u8 bD, - u8 bE, - u8 bF -) { - int n=4; - u8 - b1 = 0x33, - b2 = 0xed, - b3 = ((bC<<2) ^ (bD +0x39) ^ (bE >>2) ^ (bF +0x63)), - b4 = ((bC+0x0b) ^ (bD>>2) ^ (bE +0x1b)) - ; - - while(n--) { - b1 += b2 ^ b3; - b2 += b1 ^ b4; - } - - return (u16) ((((u16)b2)<<8) | b1); -} - -// actual business of getting I2C data from PIC and reissuing munged version -// returns zero if all okay, else error code - -int BootPerformPicChallengeResponseAction() -{ - u8 bC, bD, bE, bF; - int n; - - n=I2CTransmitByteGetReturn( 0x10, 0x1c ); - if(n<0) return n; - bC=n; - n=I2CTransmitByteGetReturn( 0x10, 0x1d ); - if(n<0) return n; - bD=n; - n=I2CTransmitByteGetReturn( 0x10, 0x1e ); - if(n<0) return n; - bE=n; - n=I2CTransmitByteGetReturn( 0x10, 0x1f ); - if(n<0) return n; - bF=n; - - { - u16 w=BootPicManipulation(bC, bD, bE, bF); - - I2CTransmitWord( 0x10, 0x2000 | (w&0xff)); - I2CTransmitWord( 0x10, 0x2100 | (w>>8) ); - } - - // continues as part of video setup.... - return ERR_SUCCESS; -} - extern int I2cSetFrontpanelLed(u8 b) { I2CTransmitWord( 0x10, 0x800 | b); // sequencing thanks to Jarin the Penguin! diff --git a/boot_rom/2bload.h b/boot_rom/2bload.h index 499fe47..c81dff5 100644 --- a/boot_rom/2bload.h +++ b/boot_rom/2bload.h @@ -14,23 +14,6 @@ #include "stdint.h" #include "cromwell_types.h" - -///////////////////////////////// -// LED-flashing codes -// or these together as argument to I2cSetFrontpanelLed - -enum { - I2C_LED_RED0 = 0x80, - I2C_LED_RED1 = 0x40, - I2C_LED_RED2 = 0x20, - I2C_LED_RED3 = 0x10, - I2C_LED_GREEN0 = 0x08, - I2C_LED_GREEN1 = 0x04, - I2C_LED_GREEN2 = 0x02, - I2C_LED_GREEN3 = 0x01 -}; - -/////////////////////////////// /* BIOS-wide error codes all have b31 set */ enum { @@ -42,10 +25,7 @@ enum { ERR_BOOT_PIC_ALG_BROKEN = 0x80000101 // PIC algorithm did not pass its self-test }; -//////// BootPerformPicChallengeResponseAction.c - -/* ---------------------------- IO primitives ----------------------------------------------------------- -*/ +// ---------------------------- IO primitives ----------------------------------------------------------- static INLINE void IoOutputByte(u16 wAds, u8 bValue) { @@ -167,21 +147,27 @@ static INLINE u8 smbus_read(u8 cmd) return smbus_read_data(); } -// boot process -int BootPerformPicChallengeResponseAction(void); -// LED control (see associated enum above) -int I2cSetFrontpanelLed(u8 b); -int I2cResetFrontpanelLed(void); - -////////// 2bBootStartBios.c - +/* 2bBootStartBios.c */ void BootSystemInitialization(void) __attribute__((section(".reset_vector.1bl"),aligned(16),naked)); void BootStartBiosLoader(void); -///////// BootPerformPicChallengeResponseAction.c - +/* 2bPicResponseAction.c */ +void pic_challenge_response(void) __attribute__((section(".low_rom"),aligned(16))); int I2CTransmitWord(u8 bPicAddressI2cFormat, u16 wDataToWrite); int I2CTransmitByteGetReturn(u8 bPicAddressI2cFormat, u8 bDataToWrite); +/* LED control; see associated enum as argument to I2cSetFrontpanelLed */ +enum { + I2C_LED_RED0 = 0x80, + I2C_LED_RED1 = 0x40, + I2C_LED_RED2 = 0x20, + I2C_LED_RED3 = 0x10, + I2C_LED_GREEN0 = 0x08, + I2C_LED_GREEN1 = 0x04, + I2C_LED_GREEN2 = 0x02, + I2C_LED_GREEN3 = 0x01 +}; +int I2cSetFrontpanelLed(u8 b); +int I2cResetFrontpanelLed(void); void *memcpy(void *dest, const void *src, size_t size); void *memset(void *dest, int data, size_t size); @@ -191,3 +177,4 @@ extern unsigned char *BufferIN; extern int BufferINlen; extern unsigned char *BufferOUT; extern int BufferOUTPos; +