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
7 * Authors: Scott Wood <scottwood@freescale.com>
8 * Grant Likely <grant.likely@secretlab.ca>
10 * Copyright (c) 2007 Freescale Semiconductor, Inc.
11 * Copyright (c) 2008 Secret Lab Technologies Ltd.
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.
26 extern int platform_specific_init(void) __attribute__((weak));
28 void platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
29 unsigned long r6, unsigned long r7)
31 const u32 *na, *ns, *reg, *timebase;
35 /* Make sure FDT blob is sane */
36 if (fdt_check_header(_dtb_start) != 0)
37 fatal("Invalid device tree blob\n");
39 /* Find the #address-cells and #size-cells properties */
40 node = fdt_path_offset(_dtb_start, "/");
42 fatal("Cannot find root node\n");
43 na = fdt_getprop(_dtb_start, node, "#address-cells", &size);
44 if (!na || (size != 4))
45 fatal("Cannot find #address-cells property");
46 ns = fdt_getprop(_dtb_start, node, "#size-cells", &size);
47 if (!ns || (size != 4))
48 fatal("Cannot find #size-cells property");
50 /* Find the memory range */
51 node = fdt_node_offset_by_prop_value(_dtb_start, -1, "device_type",
52 "memory", sizeof("memory"));
54 fatal("Cannot find memory node\n");
55 reg = fdt_getprop(_dtb_start, node, "reg", &size);
56 if (size < (*na+*ns) * sizeof(u32))
57 fatal("cannot get memory range\n");
59 /* Only interested in memory based at 0 */
60 for (i = 0; i < *na; i++)
62 fatal("Memory range is not based at address 0\n");
64 /* get the memsize and truncate it to under 4G on 32 bit machines */
66 for (i = 0; i < *ns; i++)
67 memsize64 = (memsize64 << 32) | *reg++;
68 if (sizeof(void *) == 4 && memsize64 >= 0x100000000ULL)
69 memsize64 = 0xffffffff;
71 /* finally, setup the timebase */
72 node = fdt_node_offset_by_prop_value(_dtb_start, -1, "device_type",
73 "cpu", sizeof("cpu"));
75 fatal("Cannot find cpu node\n");
76 timebase = fdt_getprop(_dtb_start, node, "timebase-frequency", &size);
77 if (timebase && (size == 4))
78 timebase_period_ns = 1000000000 / *timebase;
80 /* Now we have the memory size; initialize the heap */
81 simple_alloc_init(_end, memsize64 - (unsigned long)_end, 32, 64);
83 /* prepare the device tree and find the console */
86 if (platform_specific_init)
87 platform_specific_init();
89 serial_console_init();