early_printf.c 985 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include <common.h>
  2. #include <stdarg.h>
  3. #include <asm/io.h>
  4. #define UART_BASE CONFIG_DEBUG_UART_BASE
  5. #define UART_DR 0x00
  6. #define UART_FR 0x18
  7. static void uart_puts(const char *str)
  8. {
  9. int i = 0;
  10. while (str[i] != 0) {
  11. while (!(readl(UART_BASE + UART_FR) & 0x20)) {
  12. if (str[i] == '\n') {
  13. writel('\r', UART_BASE + UART_DR);
  14. while (readl(UART_BASE + UART_FR) & 0x20);
  15. }
  16. writel(str[i++], UART_BASE + UART_DR);
  17. if (str[i] == 0)
  18. return;
  19. }
  20. while (readl(UART_BASE + UART_FR) & 0x20);
  21. }
  22. }
  23. int early_printf(const char *fmt, ...)
  24. {
  25. va_list args;
  26. uint i;
  27. char printbuffer[CONFIG_SYS_PBSIZE];
  28. va_start(args, fmt);
  29. /*
  30. * For this to work, printbuffer must be larger than
  31. * anything we ever want to print.
  32. */
  33. i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args);
  34. va_end(args);
  35. /* Handle error */
  36. if (i <= 0)
  37. return i;
  38. /* Print the string */
  39. uart_puts(printbuffer);
  40. return i;
  41. }