simpleboot.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * The simple platform -- for booting when firmware doesn't supply a device
  3. * tree or any platform configuration information.
  4. * All data is extracted from an embedded device tree
  5. * blob.
  6. *
  7. * Authors: Scott Wood <scottwood@freescale.com>
  8. * Grant Likely <grant.likely@secretlab.ca>
  9. *
  10. * Copyright (c) 2007 Freescale Semiconductor, Inc.
  11. * Copyright (c) 2008 Secret Lab Technologies Ltd.
  12. *
  13. * This program is free software; you can redistribute it and/or modify it
  14. * under the terms of the GNU General Public License version 2 as published
  15. * by the Free Software Foundation.
  16. */
  17. #include "ops.h"
  18. #include "types.h"
  19. #include "io.h"
  20. #include "stdio.h"
  21. #include <libfdt.h>
  22. BSS_STACK(4*1024);
  23. extern int platform_specific_init(void) __attribute__((weak));
  24. void platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  25. unsigned long r6, unsigned long r7)
  26. {
  27. const u32 *na, *ns, *reg, *timebase;
  28. u64 memsize64;
  29. int node, size, i;
  30. /* Make sure FDT blob is sane */
  31. if (fdt_check_header(_dtb_start) != 0)
  32. fatal("Invalid device tree blob\n");
  33. /* Find the #address-cells and #size-cells properties */
  34. node = fdt_path_offset(_dtb_start, "/");
  35. if (node < 0)
  36. fatal("Cannot find root node\n");
  37. na = fdt_getprop(_dtb_start, node, "#address-cells", &size);
  38. if (!na || (size != 4))
  39. fatal("Cannot find #address-cells property");
  40. ns = fdt_getprop(_dtb_start, node, "#size-cells", &size);
  41. if (!ns || (size != 4))
  42. fatal("Cannot find #size-cells property");
  43. /* Find the memory range */
  44. node = fdt_node_offset_by_prop_value(_dtb_start, -1, "device_type",
  45. "memory", sizeof("memory"));
  46. if (node < 0)
  47. fatal("Cannot find memory node\n");
  48. reg = fdt_getprop(_dtb_start, node, "reg", &size);
  49. if (size < (*na+*ns) * sizeof(u32))
  50. fatal("cannot get memory range\n");
  51. /* Only interested in memory based at 0 */
  52. for (i = 0; i < *na; i++)
  53. if (*reg++ != 0)
  54. fatal("Memory range is not based at address 0\n");
  55. /* get the memsize and truncate it to under 4G on 32 bit machines */
  56. memsize64 = 0;
  57. for (i = 0; i < *ns; i++)
  58. memsize64 = (memsize64 << 32) | *reg++;
  59. if (sizeof(void *) == 4 && memsize64 >= 0x100000000ULL)
  60. memsize64 = 0xffffffff;
  61. /* finally, setup the timebase */
  62. node = fdt_node_offset_by_prop_value(_dtb_start, -1, "device_type",
  63. "cpu", sizeof("cpu"));
  64. if (!node)
  65. fatal("Cannot find cpu node\n");
  66. timebase = fdt_getprop(_dtb_start, node, "timebase-frequency", &size);
  67. if (timebase && (size == 4))
  68. timebase_period_ns = 1000000000 / *timebase;
  69. /* Now we have the memory size; initialize the heap */
  70. simple_alloc_init(_end, memsize64 - (unsigned long)_end, 32, 64);
  71. /* prepare the device tree and find the console */
  72. fdt_init(_dtb_start);
  73. if (platform_specific_init)
  74. platform_specific_init();
  75. serial_console_init();
  76. }