From bac32d189b69646be8479d5f7bc8f8026713ede7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kr=C3=B3l?= Date: Tue, 5 Nov 2024 01:03:44 +0100 Subject: [PATCH 1/3] sortbootorder,utils/rtc_clock_menu: allow fall through in switch case MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Piotr Król --- sortbootorder.c | 1 + utils/rtc_clock_menu.c | 1 + 2 files changed, 2 insertions(+) diff --git a/sortbootorder.c b/sortbootorder.c index 2a34a77..be012aa 100644 --- a/sortbootorder.c +++ b/sortbootorder.c @@ -368,6 +368,7 @@ int main(void) { update_tags(bootlist, &max_lines); save_flash((u32)flash_address, bootlist, max_lines, spi_wp_toggle); + __attribute__((fallthrough)); // fall through to exit ... case 'x': case 'X': diff --git a/utils/rtc_clock_menu.c b/utils/rtc_clock_menu.c index 20c0da4..7ffa927 100644 --- a/utils/rtc_clock_menu.c +++ b/utils/rtc_clock_menu.c @@ -160,6 +160,7 @@ void handle_rtc_clock_menu(void) break; case 'w': rtc_write_clock(&time); + __attribute__((fallthrough)); case 'x': end = TRUE; break; From 95692853947e0b36e4d7fb57bf6a951baa9f78c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kr=C3=B3l?= Date: Thu, 7 Nov 2024 14:52:17 +0100 Subject: [PATCH 2/3] detect QEMU and skip SPI initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add support for QEMU pflash writing. Signed-off-by: Piotr Król --- sortbootorder.c | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/sortbootorder.c b/sortbootorder.c index be012aa..b5cf6a9 100644 --- a/sortbootorder.c +++ b/sortbootorder.c @@ -55,6 +55,9 @@ #define MPCIE1_SATA2 16 #define IPXE 17 +#define WRITE_BYTE_CMD 0x10 +#define READ_ARRAY_CMD 0xFF + #define RESET() outb(0x06, 0x0cf9) /*** prototypes ***/ @@ -168,10 +171,13 @@ int main(void) { printf("\n### PC Engines %s setup %s ###\n", apu_id_string, SORTBOOTORDER_VER); + char *is_qemu = strstr((char*)apu_id_string, "QEMU"); - if (init_flash()) { + if (init_flash() && !is_qemu) { printf("Can't initialize flash device!\n"); RESET(); + } else { + printf("QEMU detected. SPI flash initialization skipped.\n"); } // Find out where the bootorder file is in rom @@ -266,7 +272,11 @@ int main(void) { token += strlen("uartd"); uartd_toggle = token ? strtoul(token, NULL, 10) : 0; - spi_wp_toggle = is_flash_locked(); + if (!is_qemu) { + spi_wp_toggle = is_flash_locked(); + } else { + printf("QEMU detected. SPI flash flash lock check skipped.\n"); + } show_boot_device_list( bootlist, max_lines, bootlist_def_ln ); int_ids( bootlist, max_lines, bootlist_def_ln ); @@ -366,8 +376,39 @@ int main(void) { case 's': case 'S': update_tags(bootlist, &max_lines); - save_flash((u32)flash_address, bootlist, + if (!is_qemu) { + save_flash((u32)flash_address, bootlist, max_lines, spi_wp_toggle); + } else { + printf("QEMU detected. save_flash not implemented.\n"); + // Compact the table into the expected packed list + char cbfs_formatted_list[MAX_DEVICES * MAX_LENGTH]; + int i, j, k = 0; + volatile char *ptr; + flash_address = (void *)(uintptr_t)(0x100000000ULL - 0x800000); + for (j = 0; j < max_lines; j++) { + for (k = 0; k < MAX_LENGTH; k++) { + cbfs_formatted_list[i++] = bootlist[j][k]; + if (bootlist[j][k] == NEWLINE ) + break; + } + } + cbfs_formatted_list[i++] = NUL; + printf("Writing %d bytes @ %p\n", i, flash_address); + ptr = flash_address; + + for (j = 0; j < i; j++) { + write8(ptr, WRITE_BYTE_CMD); + write8(ptr, cbfs_formatted_list[j]); + ptr++; + } + + /* Restore flash to read mode. */ + if (i > 0) { + write8(ptr - 1, READ_ARRAY_CMD); + } + printf("Done\n"); + } __attribute__((fallthrough)); // fall through to exit ... case 'x': From dab0a14d1c4e866e1f1dcab82613e37333846457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kr=C3=B3l?= Date: Mon, 25 Nov 2024 13:06:42 +0100 Subject: [PATCH 3/3] Makefile: add -ffile-prefix-map to improve reproducibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Piotr Król --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 2a4861a..2dd541b 100644 --- a/Makefile +++ b/Makefile @@ -77,7 +77,7 @@ OBJCOPY := $(OBJCOPY_$(ARCH-y)) LPCC := CC="$(CC)" $(LIBPAYLOAD_OBJ)/bin/lpgcc LPAS := AS="$(AS)" $(LIBPAYLOAD_OBJ)/bin/lpas -CFLAGS += -Wall -Werror -Os -fno-builtin $(CFLAGS_$(ARCH-y)) $(INCLUDES) +CFLAGS += -Wall -Werror -Os -fno-builtin -ffile-prefix-map=$(PWD)=. $(CFLAGS_$(ARCH-y)) $(INCLUDES) ifeq ($(COREBOOT_REL),legacy) CFLAGS += -DCOREBOOT_LEGACY endif