|
55 | 55 | #define MPCIE1_SATA2 16
|
56 | 56 | #define IPXE 17
|
57 | 57 |
|
| 58 | +#define WRITE_BYTE_CMD 0x10 |
| 59 | +#define READ_ARRAY_CMD 0xFF |
| 60 | + |
58 | 61 | #define RESET() outb(0x06, 0x0cf9)
|
59 | 62 |
|
60 | 63 | /*** prototypes ***/
|
@@ -168,10 +171,13 @@ int main(void) {
|
168 | 171 | printf("\n### PC Engines %s setup %s ###\n", apu_id_string,
|
169 | 172 | SORTBOOTORDER_VER);
|
170 | 173 |
|
| 174 | + char *is_qemu = strstr((char*)apu_id_string, "QEMU"); |
171 | 175 |
|
172 |
| - if (init_flash()) { |
| 176 | + if (init_flash() && !is_qemu) { |
173 | 177 | printf("Can't initialize flash device!\n");
|
174 | 178 | RESET();
|
| 179 | + } else { |
| 180 | + printf("QEMU detected. SPI flash initialization skipped.\n"); |
175 | 181 | }
|
176 | 182 |
|
177 | 183 | // Find out where the bootorder file is in rom
|
@@ -266,7 +272,11 @@ int main(void) {
|
266 | 272 | token += strlen("uartd");
|
267 | 273 | uartd_toggle = token ? strtoul(token, NULL, 10) : 0;
|
268 | 274 |
|
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 | + } |
270 | 280 |
|
271 | 281 | show_boot_device_list( bootlist, max_lines, bootlist_def_ln );
|
272 | 282 | int_ids( bootlist, max_lines, bootlist_def_ln );
|
@@ -366,8 +376,39 @@ int main(void) {
|
366 | 376 | case 's':
|
367 | 377 | case 'S':
|
368 | 378 | update_tags(bootlist, &max_lines);
|
369 |
| - save_flash((u32)flash_address, bootlist, |
| 379 | + if (!is_qemu) { |
| 380 | + save_flash((u32)flash_address, bootlist, |
370 | 381 | 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 | + } |
371 | 412 | __attribute__((fallthrough));
|
372 | 413 | // fall through to exit ...
|
373 | 414 | case 'x':
|
|
0 commit comments