Skip to content

Commit

Permalink
uefi stub: uart add format print
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasschwoebel committed Nov 4, 2022
1 parent 1d480b5 commit 98902b2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
30 changes: 30 additions & 0 deletions drivers/firmware/efi/libstub/efi-stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
}
}
*/
uint8_t *base = (uint8_t*) 0x6000d000;

/*
* Figure out on which Windows RT device is booted.
Expand Down Expand Up @@ -359,10 +360,39 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
}

install_memreserve_table();
/*
for (i = 0; i < 0x1000; i++) {
if (i % 16 == 0) {
tegra_uart_print("\n");
tegra_uart_print("%02x: ", i);
}
tegra_uart_print("%02x ", *(base+i));
}
*/
/**
* @brief lock Vbus GPIO
* locks the VBus GPIO so ExitBootService call can't turn it off.
*/
/*
uint16_t *gpio = (uint16_t*) 0x6000d208;
uint16_t cur_val = *gpio;
cur_val = cur_val | 0x200;
*gpio = cur_val;
*/
status = allocate_new_fdt_and_exit_boot(handle, &fdt_addr,
initrd_addr, initrd_size,
cmdline_ptr, fdt_addr, fdt_size);
/*
for (i = 0; i < 0x1000; i++) {
if (i % 16 == 0) {
tegra_uart_print("\n");
tegra_uart_print("%02x: ", i);
}
tegra_uart_print("%02x ", *(base+i));
}
*/
if (status != EFI_SUCCESS)
goto fail_free_initrd;

Expand Down
2 changes: 1 addition & 1 deletion drivers/firmware/efi/libstub/efistub.h
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ enum winrt_device_names winrt_setup(void);
/**
* Tegra specific UART stuff
*/
void tegra_uart_print(const char *string);
void tegra_uart_print(const char *string, ...);
void tegra_uart_init(void);

/**
Expand Down
20 changes: 13 additions & 7 deletions drivers/firmware/efi/libstub/tegra_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,28 +98,34 @@ void tegra_uart_init()
tegra_uart_print("hi from tegra_uart_init :)\n");
}

void tegra_uart_print(const char *string)
void tegra_uart_print(const char *fmt, ...)
{
char printf_buf[256];
va_list args;
int printed_size;
int i;

/* If uart isn't setup (yet); send nothing */
if (reg_read(PMC_BASE, APBDEV_PMC_SCRATCH42_0) != MAGIC_VALUE)
return;

va_start(args, fmt);
printed_size = vsnprintf(printf_buf, sizeof(printf_buf), fmt, args);
va_end(args);

/* send all characters until NULL to uart-N */
while (*string) {
for (i = 0; i < printed_size; i++) {
/* put the char into the tx fifo */
if (*string == '\n') {
if (printf_buf[i] == '\n') {
reg_write(UART_BASE, UART_THR_DLAB, '\r');
while (!((reg_read(UART_BASE, UART_LSR) >> 5) & 0x01))
;
}

reg_write(UART_BASE, UART_THR_DLAB, (char) *string);
reg_write(UART_BASE, UART_THR_DLAB, (char) printf_buf[i]);

/* wait for tx fifo to clear */
while (!((reg_read(UART_BASE, UART_LSR) >> 5) & 0x01))
;

/* move on to next char */
++string;
}
}

0 comments on commit 98902b2

Please sign in to comment.