Skip to content

Commit 9569285

Browse files
committed
detect QEMU and skip SPI initialization
Add support for QEMU pflash writing. Signed-off-by: Piotr Król <[email protected]>
1 parent bac32d1 commit 9569285

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed

sortbootorder.c

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
#define MPCIE1_SATA2 16
5656
#define IPXE 17
5757

58+
#define WRITE_BYTE_CMD 0x10
59+
#define READ_ARRAY_CMD 0xFF
60+
5861
#define RESET() outb(0x06, 0x0cf9)
5962

6063
/*** prototypes ***/
@@ -168,10 +171,13 @@ int main(void) {
168171
printf("\n### PC Engines %s setup %s ###\n", apu_id_string,
169172
SORTBOOTORDER_VER);
170173

174+
char *is_qemu = strstr((char*)apu_id_string, "QEMU");
171175

172-
if (init_flash()) {
176+
if (init_flash() && !is_qemu) {
173177
printf("Can't initialize flash device!\n");
174178
RESET();
179+
} else {
180+
printf("QEMU detected. SPI flash initialization skipped.\n");
175181
}
176182

177183
// Find out where the bootorder file is in rom
@@ -266,7 +272,11 @@ int main(void) {
266272
token += strlen("uartd");
267273
uartd_toggle = token ? strtoul(token, NULL, 10) : 0;
268274

269-
spi_wp_toggle = is_flash_locked();
275+
if (!is_qemu) {
276+
spi_wp_toggle = is_flash_locked();
277+
} else {
278+
printf("QEMU detected. SPI flash flash lock check skipped.\n");
279+
}
270280

271281
show_boot_device_list( bootlist, max_lines, bootlist_def_ln );
272282
int_ids( bootlist, max_lines, bootlist_def_ln );
@@ -366,8 +376,39 @@ int main(void) {
366376
case 's':
367377
case 'S':
368378
update_tags(bootlist, &max_lines);
369-
save_flash((u32)flash_address, bootlist,
379+
if (!is_qemu) {
380+
save_flash((u32)flash_address, bootlist,
370381
max_lines, spi_wp_toggle);
382+
} else {
383+
printf("QEMU detected. save_flash not implemented.\n");
384+
// Compact the table into the expected packed list
385+
char cbfs_formatted_list[MAX_DEVICES * MAX_LENGTH];
386+
int i, j, k = 0;
387+
volatile char *ptr;
388+
flash_address = (void *)(uintptr_t)(0x100000000ULL - 0x800000);
389+
for (j = 0; j < max_lines; j++) {
390+
for (k = 0; k < MAX_LENGTH; k++) {
391+
cbfs_formatted_list[i++] = bootlist[j][k];
392+
if (bootlist[j][k] == NEWLINE )
393+
break;
394+
}
395+
}
396+
cbfs_formatted_list[i++] = NUL;
397+
printf("Writing %d bytes @ %p\n", i, flash_address);
398+
ptr = flash_address;
399+
400+
for (j = 0; j < i; j++) {
401+
write8(ptr, WRITE_BYTE_CMD);
402+
write8(ptr, cbfs_formatted_list[j]);
403+
ptr++;
404+
}
405+
406+
/* Restore flash to read mode. */
407+
if (i > 0) {
408+
write8(ptr - 1, READ_ARRAY_CMD);
409+
}
410+
printf("Done\n");
411+
}
371412
__attribute__((fallthrough));
372413
// fall through to exit ...
373414
case 'x':

0 commit comments

Comments
 (0)