Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QEMU pflash support #84

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 45 additions & 3 deletions sortbootorder.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ***/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -366,8 +376,40 @@ 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':
case 'X':
Expand Down
1 change: 1 addition & 0 deletions utils/rtc_clock_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ void handle_rtc_clock_menu(void)
break;
case 'w':
rtc_write_clock(&time);
__attribute__((fallthrough));
case 'x':
end = TRUE;
break;
Expand Down