simpleboot.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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/libfdt.h"
  22. BSS_STACK(4*1024);
  23. void platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  24. unsigned long r6, unsigned long r7)
  25. {
  26. const u32 *na, *ns, *reg, *timebase;
  27. u64 memsize64;
  28. int node, size, i;
  29. /* Make sure FDT blob is sane */
  30. if (fdt_check_header(_dtb_start) != 0)
  31. fatal("Invalid device tree blob\n");
  32. /* Find the #address-cells and #size-cells properties */
  33. node = fdt_path_offset(_dtb_start, "/");
  34. if (node < 0)
  35. fatal("Cannot find root node\n");
  36. na = fdt_getprop(_dtb_start, node, "#address-cells", &size);
  37. if (!na || (size != 4))
  38. fatal("Cannot find #address-cells property");
  39. ns = fdt_getprop(_dtb_start, node, "#size-cells", &size);
  40. if (!ns || (size != 4))
  41. fatal("Cannot find #size-cells property");
  42. /* Find the memory range */
  43. node = fdt_node_offset_by_prop_value(_dtb_start, -1, "device_type",
  44. "memory", sizeof("memory"));
  45. if (node < 0)
  46. fatal("Cannot find memory node\n");
  47. reg = fdt_getprop(_dtb_start, node, "reg", &size);
  48. if (size < (*na+*ns) * sizeof(u32))
  49. fatal("cannot get memory range\n");
  50. /* Only interested in memory based at 0 */
  51. for (i = 0; i < *na; i++)
  52. if (*reg++ != 0)
  53. fatal("Memory range is not based at address 0\n");
  54. /* get the memsize and trucate it to under 4G on 32 bit machines */
  55. memsize64 = 0;
  56. for (i = 0; i < *ns; i++)
  57. memsize64 = (memsize64 << 32) | *reg++;
  58. if (sizeof(void *) == 4 && memsize64 >= 0x100000000ULL)
  59. memsize64 = 0xffffffff;
  60. /* finally, setup the timebase */
  61. node = fdt_node_offset_by_prop_value(_dtb_start, -1, "device_type",
  62. "cpu", sizeof("cpu"));
  63. if (!node)
  64. fatal("Cannot find cpu node\n");
  65. timebase = fdt_getprop(_dtb_start, node, "timebase-frequency", &size);
  66. if (timebase && (size == 4))
  67. timebase_period_ns = 1000000000 / *timebase;
  68. /* Now we have the memory size; initialize the heap */
  69. simple_alloc_init(_end, memsize64 - (unsigned long)_end, 32, 64);
  70. /* prepare the device tree and find the console */
  71. fdt_init(_dtb_start);
  72. serial_console_init();
  73. }