diff --git a/headers/private/kernel/platform/u-boot/fdt_support.h b/headers/private/kernel/platform/u-boot/fdt_support.h index 5a5d5e4ed2..c2d5a89158 100644 --- a/headers/private/kernel/platform/u-boot/fdt_support.h +++ b/headers/private/kernel/platform/u-boot/fdt_support.h @@ -15,8 +15,9 @@ void dump_fdt(const void *fdt); status_t fdt_get_cell_count(int node, int32 &addressCells, int32 &sizeCells); -addr_t fdt_get_device_reg_byname(const char* name); -addr_t fdt_get_device_reg_byalias(const char* alias); +phys_addr_t fdt_get_device_reg(int node); +phys_addr_t fdt_get_device_reg_byname(const char* name); +phys_addr_t fdt_get_device_reg_byalias(const char* alias); #endif /*__FDT_SUPPORT_H*/ diff --git a/src/system/kernel/platform/u-boot/fdt_serial.cpp b/src/system/kernel/platform/u-boot/fdt_serial.cpp index 628fee72aa..e1059b4978 100644 --- a/src/system/kernel/platform/u-boot/fdt_serial.cpp +++ b/src/system/kernel/platform/u-boot/fdt_serial.cpp @@ -18,6 +18,8 @@ extern "C" { #include }; +#include "fdt_support.h" + extern "C" DebugUART *debug_uart_from_fdt(const void *fdt); @@ -26,7 +28,7 @@ DebugUART * debug_uart_from_fdt(const void *fdt) { const char *name; - const char *type; + //const char *type; int node; int len; phys_addr_t regs; @@ -43,6 +45,8 @@ debug_uart_from_fdt(const void *fdt) name = fdt_get_alias(fdt, "serial0"); if (name == NULL) name = fdt_get_alias(fdt, "serial1"); + if (name == NULL) + name = fdt_get_alias(fdt, "uart0"); // TODO: else use /chosen linux,stdout-path if (name == NULL) return NULL; @@ -52,27 +56,11 @@ debug_uart_from_fdt(const void *fdt) if (node < 0) return NULL; - type = (const char *)fdt_getprop(fdt, node, "device_type", &len); - //dprintf("serial: type: '%s'\n", type); - if (type == NULL || strcmp(type, "serial")) - return NULL; - // determine the MMIO address - // TODO: ppc460 use 64bit addressing, but U-Boot seems to map it below 4G, - // and the FDT is not very clear. libfdt is also getting 64bit addr support. - // so FIXME someday. - prop = fdt_getprop(fdt, node, "virtual-reg", &len); - if (prop && len == 4) { - regs = fdt32_to_cpu(*(uint32_t *)prop); - //dprintf("serial: virtual-reg 0x%08llx\n", (int64)regs); - } else { - prop = fdt_getprop(fdt, node, "reg", &len); - if (prop && len >= 4) { - regs = fdt32_to_cpu(*(uint32_t *)prop); - //dprintf("serial: reg 0x%08llx\n", (int64)regs); - } else - return NULL; - } + regs = fdt_get_device_reg(node); + + if (regs == 0) + return NULL; // get the UART clock rate prop = fdt_getprop(fdt, node, "clock-frequency", &len); @@ -96,8 +84,7 @@ debug_uart_from_fdt(const void *fdt) (void)speed; } else { // TODO: handle more UART types - // for when we can use U-Boot's console - panic("Unknown UART type %s", type); + return NULL; } return uart; diff --git a/src/system/kernel/platform/u-boot/fdt_support.cpp b/src/system/kernel/platform/u-boot/fdt_support.cpp index 697abb75cc..ad789a1cf8 100644 --- a/src/system/kernel/platform/u-boot/fdt_support.cpp +++ b/src/system/kernel/platform/u-boot/fdt_support.cpp @@ -210,7 +210,7 @@ fdt_get_cell_count(int node, int32 &addressCells, int32 &sizeCells) } -static addr_t +phys_addr_t fdt_get_device_reg(int node) { const void *prop; @@ -220,6 +220,8 @@ fdt_get_device_reg(int node) int32 regSizeCells = 1; fdt_get_cell_count(node, regAddressCells, regSizeCells); + // TODO: check for virtual-reg, and don't -= fdt_get_range_offset? + prop = fdt_getprop(gFDT, node, "reg", &len); if (!prop) { @@ -248,11 +250,11 @@ fdt_get_device_reg(int node) baseDevice -= fdt_get_range_offset(node); - return (addr_t)baseDevice; + return baseDevice; } -addr_t +phys_addr_t fdt_get_device_reg_byname(const char* name) { // Find device in FDT @@ -277,7 +279,7 @@ fdt_get_device_reg_byname(const char* name) } -addr_t +phys_addr_t fdt_get_device_reg_byalias(const char* alias) { const char* name = fdt_get_alias(gFDT, alias); @@ -287,6 +289,6 @@ fdt_get_device_reg_byalias(const char* alias) return 0; } - addr_t deviceReg = fdt_get_device_reg_byname(name); + phys_addr_t deviceReg = fdt_get_device_reg_byname(name); return deviceReg; }