summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJulius Werner <jwerner@chromium.org>2019-05-07 17:38:12 -0700
committerPatrick Georgi <pgeorgi@google.com>2019-05-23 08:44:34 +0000
commita5ea3a271bbaa10f03115ffe3f473a07ca95c5ab (patch)
tree072ddb0753caac8b7b82b0517e165c33a8d42b8d /src
parentb3f852fba3cfd4ebde8cd7a34df069ba4cebe7a1 (diff)
downloadcoreboot-a5ea3a271bbaa10f03115ffe3f473a07ca95c5ab.tar.xz
device_tree: Use be32dec/be32enc where appropriate
This patch rewrites some of the device tree code to use the new be32dec/be32enc helpers where they can make the code cleaner. Change-Id: I437bbd6645a556ae9a0cfe6ea14638098e4c3606 Signed-off-by: Julius Werner <jwerner@chromium.org> Reviewed-on: https://review.coreboot.org/c/coreboot/+/32860 Reviewed-by: Hung-Te Lin <hungte@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'src')
-rw-r--r--src/lib/device_tree.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/lib/device_tree.c b/src/lib/device_tree.c
index 79561a69b8..8dbc510c10 100644
--- a/src/lib/device_tree.c
+++ b/src/lib/device_tree.c
@@ -56,7 +56,7 @@ int fdt_next_property(const void *blob, uint32_t offset,
int fdt_node_name(const void *blob, uint32_t offset, const char **name)
{
uint8_t *ptr = ((uint8_t *)blob) + offset;
- if (be32toh(*(uint32_t *)ptr) != FDT_TOKEN_BEGIN_NODE)
+ if (be32dec(ptr) != FDT_TOKEN_BEGIN_NODE)
return 0;
ptr += 4;
@@ -358,14 +358,14 @@ static void dt_flatten_prop(struct device_tree_property *prop,
uint8_t *dstruct = (uint8_t *)*struct_start;
uint8_t *dstrings = (uint8_t *)*strings_start;
- *((uint32_t *)dstruct) = htobe32(FDT_TOKEN_PROPERTY);
+ be32enc(dstruct, FDT_TOKEN_PROPERTY);
dstruct += sizeof(uint32_t);
- *((uint32_t *)dstruct) = htobe32(prop->prop.size);
+ be32enc(dstruct, prop->prop.size);
dstruct += sizeof(uint32_t);
uint32_t name_offset = (uintptr_t)dstrings - (uintptr_t)strings_base;
- *((uint32_t *)dstruct) = htobe32(name_offset);
+ be32enc(dstruct, name_offset);
dstruct += sizeof(uint32_t);
strcpy((char *)dstrings, prop->prop.name);
@@ -385,7 +385,7 @@ static void dt_flatten_node(const struct device_tree_node *node,
uint8_t *dstruct = (uint8_t *)*struct_start;
uint8_t *dstrings = (uint8_t *)*strings_start;
- *((uint32_t *)dstruct) = htobe32(FDT_TOKEN_BEGIN_NODE);
+ be32enc(dstruct, FDT_TOKEN_BEGIN_NODE);
dstruct += sizeof(uint32_t);
strcpy((char *)dstruct, node->name);
@@ -401,7 +401,7 @@ static void dt_flatten_node(const struct device_tree_node *node,
dt_flatten_node(child, (void **)&dstruct, strings_base,
(void **)&dstrings);
- *((uint32_t *)dstruct) = htobe32(FDT_TOKEN_END_NODE);
+ be32enc(dstruct, FDT_TOKEN_END_NODE);
dstruct += sizeof(uint32_t);
*struct_start = dstruct;
@@ -489,9 +489,9 @@ void dt_read_cell_props(const struct device_tree_node *node, u32 *addrcp,
struct device_tree_property *prop;
list_for_each(prop, node->properties, list_node) {
if (addrcp && !strcmp("#address-cells", prop->prop.name))
- *addrcp = be32toh(*(u32 *)prop->prop.data);
+ *addrcp = be32dec(prop->prop.data);
if (sizecp && !strcmp("#size-cells", prop->prop.name))
- *sizecp = be32toh(*(u32 *)prop->prop.data);
+ *sizecp = be32dec(prop->prop.data);
}
}