Skip to content

Commit f3b07c0

Browse files
committed
boot: Move PIC challenge to 1BL low ROM, before 2BL RAM copy
1 parent f1ad8cf commit f3b07c0

File tree

4 files changed

+56
-103
lines changed

4 files changed

+56
-103
lines changed

boot_rom/2bBootStartBios.c

+3-9
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,9 @@ void BootStartBiosLoader(void)
261261
SHA1Input(&context,(void*)(PROGRAMM_Memory_2bl+20),bootloadersize-20);
262262
SHA1Result(&context,SHA1_result);
263263

264-
if (memcmp(&bootloaderChecksum[0],&SHA1_result[0],20)==0) {
265-
// HEHE, the Image we copy'd into ram is SHA-1 hash identical, this is Optimum
266-
BootPerformPicChallengeResponseAction();
267-
268-
} else {
269-
// Bad, the checksum does not match, but we can nothing do now, we wait until PIC kills us
264+
if (memcmp(&bootloaderChecksum[0],&SHA1_result[0],20)) {
265+
// Bad, the checksum does not match, we did not get a valid image copied to RAM, so we stop and display an error.
266+
setLED("rrrr");
270267
while(1);
271268
}
272269

@@ -358,9 +355,6 @@ void BootStartBiosLoader(void)
358355
// We are not Longer here
359356
}
360357

361-
// Bad, we did not get a valid im age to RAM, we stop and display a error
362-
//setLED("rrrr");
363-
364358
setLED("oooo");
365359

366360
// I2CTransmitWord(0x10, 0x1901); // no reset on eject

boot_rom/2bBootStartup.S

+5-4
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,12 @@
211211

212212
cld
213213

214-
// copy everything into RAM
214+
// Set the stack pointer to give us a valid stack
215+
movl $0x1ffff0, %esp
216+
217+
call pic_challenge_response
215218

219+
// Copy 2BL into RAM
216220
mov $_ram_location, %edi
217221
mov $_start_ramcopy, %esi
218222
mov $(_size_ramcopy + 100), %ecx
@@ -309,9 +313,6 @@ reload_cs:
309313
mov %eax, %fs
310314
mov %eax, %gs
311315

312-
// Set the stack pointer to give us a valid stack
313-
movl $0x1ffff0, %esp
314-
315316
// Clear out .bss
316317
xor %eax, %eax
317318
mov $BSS_SIZE_L, %ecx

boot_rom/2bPicResponseAction.c

+30-59
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,36 @@
1414

1515
#include "2bload.h"
1616

17+
void pic_challenge_response(void)
18+
{
19+
register u8 x1c, x1d, x1e, x1f;
20+
register u8 b1, b2, b3, b4;
21+
register int i;
22+
23+
smbus_set_addr(0x21); /* set PIC address; read command */
24+
smbus_read_start(0x1c);
25+
if (!smbus_cycle_completed()) return;
26+
x1c = smbus_read_data();
27+
x1d = smbus_read(0x1d);
28+
x1e = smbus_read(0x1e);
29+
x1f = smbus_read(0x1f);
30+
31+
b1 = 0x33;
32+
b2 = 0xed;
33+
b3 = x1c << 2;
34+
b3 ^= x1d + 0x39;
35+
b3 ^= x1e >> 2;
36+
b3 ^= x1f + 0x63;
37+
b4 = x1c + 0x0b;
38+
b4 ^= x1d >> 2;
39+
b4 ^= x1e + 0x1b;
40+
41+
for (i = 0; i < 4; b1 += b2 ^ b3, b2 += b1 ^ b4, ++i);
42+
43+
smbus_set_addr(0x20); /* set PIC address; write command */
44+
smbus_write(0x20, b1);
45+
smbus_write(0x21, b2);
46+
}
1747

1848
// ---------------------------- I2C -----------------------------------------------------------
1949
//
@@ -85,65 +115,6 @@ int I2CTransmitWord(u8 bPicAddressI2cFormat, u16 wDataToWrite)
85115
return ERR_I2C_ERROR_BUS;
86116
}
87117

88-
// ---------------------------- PIC challenge/response -----------------------------------------------------------
89-
//
90-
// given four bytes, returns a u16
91-
// LSB of return is the 'first' byte, MSB is the 'second' response byte
92-
93-
u16 BootPicManipulation(
94-
u8 bC,
95-
u8 bD,
96-
u8 bE,
97-
u8 bF
98-
) {
99-
int n=4;
100-
u8
101-
b1 = 0x33,
102-
b2 = 0xed,
103-
b3 = ((bC<<2) ^ (bD +0x39) ^ (bE >>2) ^ (bF +0x63)),
104-
b4 = ((bC+0x0b) ^ (bD>>2) ^ (bE +0x1b))
105-
;
106-
107-
while(n--) {
108-
b1 += b2 ^ b3;
109-
b2 += b1 ^ b4;
110-
}
111-
112-
return (u16) ((((u16)b2)<<8) | b1);
113-
}
114-
115-
// actual business of getting I2C data from PIC and reissuing munged version
116-
// returns zero if all okay, else error code
117-
118-
int BootPerformPicChallengeResponseAction()
119-
{
120-
u8 bC, bD, bE, bF;
121-
int n;
122-
123-
n=I2CTransmitByteGetReturn( 0x10, 0x1c );
124-
if(n<0) return n;
125-
bC=n;
126-
n=I2CTransmitByteGetReturn( 0x10, 0x1d );
127-
if(n<0) return n;
128-
bD=n;
129-
n=I2CTransmitByteGetReturn( 0x10, 0x1e );
130-
if(n<0) return n;
131-
bE=n;
132-
n=I2CTransmitByteGetReturn( 0x10, 0x1f );
133-
if(n<0) return n;
134-
bF=n;
135-
136-
{
137-
u16 w=BootPicManipulation(bC, bD, bE, bF);
138-
139-
I2CTransmitWord( 0x10, 0x2000 | (w&0xff));
140-
I2CTransmitWord( 0x10, 0x2100 | (w>>8) );
141-
}
142-
143-
// continues as part of video setup....
144-
return ERR_SUCCESS;
145-
}
146-
147118
extern int I2cSetFrontpanelLed(u8 b)
148119
{
149120
I2CTransmitWord( 0x10, 0x800 | b); // sequencing thanks to Jarin the Penguin!

boot_rom/2bload.h

+18-31
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,6 @@
1414
#include "stdint.h"
1515
#include "cromwell_types.h"
1616

17-
18-
/////////////////////////////////
19-
// LED-flashing codes
20-
// or these together as argument to I2cSetFrontpanelLed
21-
22-
enum {
23-
I2C_LED_RED0 = 0x80,
24-
I2C_LED_RED1 = 0x40,
25-
I2C_LED_RED2 = 0x20,
26-
I2C_LED_RED3 = 0x10,
27-
I2C_LED_GREEN0 = 0x08,
28-
I2C_LED_GREEN1 = 0x04,
29-
I2C_LED_GREEN2 = 0x02,
30-
I2C_LED_GREEN3 = 0x01
31-
};
32-
33-
///////////////////////////////
3417
/* BIOS-wide error codes all have b31 set */
3518

3619
enum {
@@ -42,10 +25,7 @@ enum {
4225
ERR_BOOT_PIC_ALG_BROKEN = 0x80000101 // PIC algorithm did not pass its self-test
4326
};
4427

45-
//////// BootPerformPicChallengeResponseAction.c
46-
47-
/* ---------------------------- IO primitives -----------------------------------------------------------
48-
*/
28+
// ---------------------------- IO primitives -----------------------------------------------------------
4929

5030
static INLINE void IoOutputByte(u16 wAds, u8 bValue)
5131
{
@@ -167,21 +147,27 @@ static INLINE u8 smbus_read(u8 cmd)
167147
return smbus_read_data();
168148
}
169149

170-
// boot process
171-
int BootPerformPicChallengeResponseAction(void);
172-
// LED control (see associated enum above)
173-
int I2cSetFrontpanelLed(u8 b);
174-
int I2cResetFrontpanelLed(void);
175-
176-
////////// 2bBootStartBios.c
177-
150+
/* 2bBootStartBios.c */
178151
void BootSystemInitialization(void) __attribute__((section(".reset_vector.1bl"),aligned(16),naked));
179152
void BootStartBiosLoader(void);
180153

181-
///////// BootPerformPicChallengeResponseAction.c
182-
154+
/* 2bPicResponseAction.c */
155+
void pic_challenge_response(void) __attribute__((section(".low_rom"),aligned(16)));
183156
int I2CTransmitWord(u8 bPicAddressI2cFormat, u16 wDataToWrite);
184157
int I2CTransmitByteGetReturn(u8 bPicAddressI2cFormat, u8 bDataToWrite);
158+
/* LED control; see associated enum as argument to I2cSetFrontpanelLed */
159+
enum {
160+
I2C_LED_RED0 = 0x80,
161+
I2C_LED_RED1 = 0x40,
162+
I2C_LED_RED2 = 0x20,
163+
I2C_LED_RED3 = 0x10,
164+
I2C_LED_GREEN0 = 0x08,
165+
I2C_LED_GREEN1 = 0x04,
166+
I2C_LED_GREEN2 = 0x02,
167+
I2C_LED_GREEN3 = 0x01
168+
};
169+
int I2cSetFrontpanelLed(u8 b);
170+
int I2cResetFrontpanelLed(void);
185171

186172
void *memcpy(void *dest, const void *src, size_t size);
187173
void *memset(void *dest, int data, size_t size);
@@ -191,3 +177,4 @@ extern unsigned char *BufferIN;
191177
extern int BufferINlen;
192178
extern unsigned char *BufferOUT;
193179
extern int BufferOUTPos;
180+

0 commit comments

Comments
 (0)