Skip to content

Commit de1448d

Browse files
committed
[lib][boot] Wrap all device tree actions around the dtre api
1 parent 83d682c commit de1448d

File tree

7 files changed

+69
-10
lines changed

7 files changed

+69
-10
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Project name and version
22
export RC_ProjectName := xBoot
33
export RC_ProjectSourceVersion := 57
4-
export RC_ProjectBuildVersion := 1
4+
export RC_ProjectBuildVersion := 2
55

66
export SRCROOT := $(CURDIR)
77
export OBJROOT := $(SRCROOT)

arch/arm/init/start.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* Start of xBoot
22
*
33
* Copyright 2013, winocm. <[email protected]>
4+
* Copyright 2017, Brian McKenzie. <[email protected]>
45
* All rights reserved.
56
*
67
* Redistribution and use in source and binary forms, with or without modification,

include/boot/device_tree.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ void DT__Initialize(void);
6969
*/
7070
extern void DT__Finalize(void);
7171

72+
void DT__GetDeviceTreeSize(uint32_t *size);
73+
7274
void DT__FlattenDeviceTree(void **result, uint32_t * length);
7375

7476
void DTInit(void *base);

include/boot/dtre.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@
3333
#include <boot/device_tree.h>
3434

3535
extern void dtre_init(void);
36+
extern uint32_t dtre_get_size(void);
37+
extern Node *dtre_root_node(void);
38+
extern Node *dtre_find_node(const char *path, bool create);
3639
extern int dtre_create_node(Node *node, char *name, void* datap, int size);
3740
extern int dtre_allocate_memory_range(char *name, long start, long length, long type);
41+
extern void dtre_flatten(void *data, uint32_t length);
3842

3943
#endif /* !DTRE_H */

lib/boot/boot.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ void publish_device_tree(void)
5959
uint32_t dtre_length;
6060
Node *root, *chosen, *options;
6161

62-
root = DT__RootNode();
63-
chosen = DT__FindNode("/chosen", 1);
64-
options = DT__FindNode("/options", 1);
62+
root = dtre_root_node();
63+
chosen = dtre_find_node("/chosen", 1);
64+
options = dtre_find_node("/options", 1);
6565

6666
assert(root != NULL);
6767
assert(chosen != NULL);
@@ -101,9 +101,9 @@ void publish_device_tree(void)
101101
dtre_create_node(root, firmware_version, &firmware_version, sizeof(firmware_version));
102102

103103
/* Flatten the device tree. */
104-
DT__FlattenDeviceTree(NULL, &dtre_length);
104+
dtre_length = dtre_get_size();
105105
dtre_data = memory_region_reserve(&kernel_region, dtre_length, 0);
106-
DT__FlattenDeviceTree(dtre_data, &dtre_length);
106+
dtre_flatten(dtre_data, dtre_length);
107107

108108
/* Add boot-args entry. */
109109
gBootArgs.deviceTreeLength = dtre_length;

lib/boot/device_tree.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,24 @@ static void *FlattenNodes(Node * node, void *buffer)
304304
return buffer;
305305
}
306306

307+
void DT__GetDeviceTreeSize(uint32_t *size)
308+
{
309+
uint32_t totalSize;
310+
311+
totalSize = DTInfo.numNodes * sizeof(DeviceTreeNode) +
312+
DTInfo.numProperties * sizeof(DeviceTreeNodeProperty) +
313+
DTInfo.totalPropertySize;
314+
315+
*size = totalSize;
316+
}
317+
307318
/*
308319
* Flatten the in-memory representation of the device tree
309320
* into a binary DT block.
310321
* To get the buffer size needed, call with result = 0.
311322
* To have a buffer allocated for you, call with *result = 0.
312323
* To use your own buffer, call with *result = &buffer.
313324
*/
314-
315325
void DT__FlattenDeviceTree(void **buffer_p, uint32_t * length)
316326
{
317327
uint32_t totalSize;
@@ -323,9 +333,7 @@ void DT__FlattenDeviceTree(void **buffer_p, uint32_t * length)
323333
DT__PrintTree(rootNode);
324334
#endif
325335

326-
totalSize = DTInfo.numNodes * sizeof(DeviceTreeNode) +
327-
DTInfo.numProperties * sizeof(DeviceTreeNodeProperty) +
328-
DTInfo.totalPropertySize;
336+
DT__GetDeviceTreeSize(&totalSize);
329337

330338
DPRINTF("Total size 0x%x\n", totalSize);
331339
if (buffer_p != 0) {

lib/boot/dtre.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,50 @@ int dtre_create_node(Node *node, char *name, void* datap, int size)
9393
return 0;
9494
}
9595

96+
/**
97+
* dtre_root_node
98+
*
99+
* Returns a pointer to the root node of the device tree.
100+
*/
101+
Node *dtre_root_node(void)
102+
{
103+
return DT__RootNode();
104+
}
105+
106+
/**
107+
* dtre_find_node
108+
*
109+
* Searches the device tree for the requested node.
110+
*/
111+
Node *dtre_find_node(const char *path, bool create)
112+
{
113+
return DT__FindNode(path, create);
114+
}
115+
116+
/**
117+
* dtre_get_size
118+
*
119+
* Returns the size of the device tree in bytes.
120+
*/
121+
uint32_t dtre_get_size(void)
122+
{
123+
uint32_t size;
124+
125+
DT__GetDeviceTreeSize(&size);
126+
127+
return size;
128+
}
129+
130+
/**
131+
* dtre_flatten
132+
*
133+
* Flatten the device tree.
134+
*/
135+
void dtre_flatten(void *data, uint32_t length)
136+
{
137+
return DT__FlattenDeviceTree(data, &length);
138+
}
139+
96140
/**
97141
* dtre_init
98142
*

0 commit comments

Comments
 (0)