1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include "ops.h"
19#include "types.h"
20#include "io.h"
21#include "stdio.h"
22#include <libfdt.h>
23
24BSS_STACK(4*1024);
25
26extern int platform_specific_init(void) __attribute__((weak));
27
28void platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
29 unsigned long r6, unsigned long r7)
30{
31 const u32 *na, *ns, *reg, *timebase;
32 u64 memsize64;
33 int node, size, i;
34
35
36 if (fdt_check_header(_dtb_start) != 0)
37 fatal("Invalid device tree blob\n");
38
39
40 node = fdt_path_offset(_dtb_start, "/");
41 if (node < 0)
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");
49
50
51 node = fdt_node_offset_by_prop_value(_dtb_start, -1, "device_type",
52 "memory", sizeof("memory"));
53 if (node < 0)
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");
58
59
60 for (i = 0; i < *na; i++)
61 if (*reg++ != 0)
62 fatal("Memory range is not based at address 0\n");
63
64
65 memsize64 = 0;
66 for (i = 0; i < *ns; i++)
67 memsize64 = (memsize64 << 32) | *reg++;
68 if (sizeof(void *) == 4 && memsize64 >= 0x100000000ULL)
69 memsize64 = 0xffffffff;
70
71
72 node = fdt_node_offset_by_prop_value(_dtb_start, -1, "device_type",
73 "cpu", sizeof("cpu"));
74 if (!node)
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;
79
80
81 simple_alloc_init(_end, memsize64 - (unsigned long)_end, 32, 64);
82
83
84 fdt_init(_dtb_start);
85
86 if (platform_specific_init)
87 platform_specific_init();
88
89 serial_console_init();
90}
91