summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/device_tree.c66
-rw-r--r--src/lib/fit.c10
-rw-r--r--src/lib/fit_payload.c2
3 files changed, 42 insertions, 36 deletions
diff --git a/src/lib/device_tree.c b/src/lib/device_tree.c
index 89387ffdbf..79561a69b8 100644
--- a/src/lib/device_tree.c
+++ b/src/lib/device_tree.c
@@ -28,7 +28,8 @@
* Functions for picking apart flattened trees.
*/
-int fdt_next_property(void *blob, uint32_t offset, struct fdt_property *prop)
+int fdt_next_property(const void *blob, uint32_t offset,
+ struct fdt_property *prop)
{
struct fdt_header *header = (struct fdt_header *)blob;
uint32_t *ptr = (uint32_t *)(((uint8_t *)blob) + offset);
@@ -52,7 +53,7 @@ int fdt_next_property(void *blob, uint32_t offset, struct fdt_property *prop)
return index * sizeof(uint32_t);
}
-int fdt_node_name(void *blob, uint32_t offset, const char **name)
+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)
@@ -76,7 +77,7 @@ static void print_indent(int depth)
printk(BIOS_DEBUG, " ");
}
-static void print_property(struct fdt_property *prop, int depth)
+static void print_property(const struct fdt_property *prop, int depth)
{
print_indent(depth);
printk(BIOS_DEBUG, "prop \"%s\" (%d bytes).\n", prop->name, prop->size);
@@ -89,7 +90,7 @@ static void print_property(struct fdt_property *prop, int depth)
printk(BIOS_DEBUG, "\n");
}
-static int print_flat_node(void *blob, uint32_t start_offset, int depth)
+static int print_flat_node(const void *blob, uint32_t start_offset, int depth)
{
int offset = start_offset;
const char *name;
@@ -116,7 +117,7 @@ static int print_flat_node(void *blob, uint32_t start_offset, int depth)
return offset - start_offset + sizeof(uint32_t);
}
-void fdt_print_node(void *blob, uint32_t offset)
+void fdt_print_node(const void *blob, uint32_t offset)
{
print_flat_node(blob, offset, 0);
}
@@ -127,7 +128,7 @@ void fdt_print_node(void *blob, uint32_t offset)
* A utility function to skip past nodes in flattened trees.
*/
-int fdt_skip_node(void *blob, uint32_t start_offset)
+int fdt_skip_node(const void *blob, uint32_t start_offset)
{
int offset = start_offset;
int size;
@@ -171,7 +172,7 @@ static struct device_tree_property *alloc_prop(void)
return buf;
}
-static int fdt_unflatten_node(void *blob, uint32_t start_offset,
+static int fdt_unflatten_node(const void *blob, uint32_t start_offset,
struct device_tree_node **new_node)
{
struct list_node *last;
@@ -216,12 +217,12 @@ static int fdt_unflatten_node(void *blob, uint32_t start_offset,
return offset - start_offset + sizeof(uint32_t);
}
-static int fdt_unflatten_map_entry(void *blob, uint32_t offset,
+static int fdt_unflatten_map_entry(const void *blob, uint32_t offset,
struct device_tree_reserve_map_entry **new)
{
- uint64_t *ptr = (uint64_t *)(((uint8_t *)blob) + offset);
- uint64_t start = be64toh(ptr[0]);
- uint64_t size = be64toh(ptr[1]);
+ const uint64_t *ptr = (const uint64_t *)(((uint8_t *)blob) + offset);
+ const uint64_t start = be64toh(ptr[0]);
+ const uint64_t size = be64toh(ptr[1]);
if (!size)
return 0;
@@ -237,10 +238,10 @@ static int fdt_unflatten_map_entry(void *blob, uint32_t offset,
return sizeof(uint64_t) * 2;
}
-struct device_tree *fdt_unflatten(void *blob)
+struct device_tree *fdt_unflatten(const void *blob)
{
struct device_tree *tree = malloc(sizeof(*tree));
- struct fdt_header *header = (struct fdt_header *)blob;
+ const struct fdt_header *header = (const struct fdt_header *)blob;
if (!tree)
return NULL;
memset(tree, 0, sizeof(*tree));
@@ -315,7 +316,7 @@ static void dt_flat_node_size(struct device_tree_node *node,
*struct_size += sizeof(uint32_t);
}
-uint32_t dt_flat_size(struct device_tree *tree)
+uint32_t dt_flat_size(const struct device_tree *tree)
{
uint32_t size = tree->header_size;
struct device_tree_reserve_map_entry *entry;
@@ -377,8 +378,9 @@ static void dt_flatten_prop(struct device_tree_property *prop,
*strings_start = dstrings;
}
-static void dt_flatten_node(struct device_tree_node *node, void **struct_start,
- void *strings_base, void **strings_start)
+static void dt_flatten_node(const struct device_tree_node *node,
+ void **struct_start, void *strings_base,
+ void **strings_start)
{
uint8_t *dstruct = (uint8_t *)*struct_start;
uint8_t *dstrings = (uint8_t *)*strings_start;
@@ -406,7 +408,7 @@ static void dt_flatten_node(struct device_tree_node *node, void **struct_start,
*strings_start = dstrings;
}
-void dt_flatten(struct device_tree *tree, void *start_dest)
+void dt_flatten(const struct device_tree *tree, void *start_dest)
{
uint8_t *dest = (uint8_t *)start_dest;
@@ -449,7 +451,7 @@ void dt_flatten(struct device_tree *tree, void *start_dest)
* Functions for printing a non-flattened device tree.
*/
-static void print_node(struct device_tree_node *node, int depth)
+static void print_node(const struct device_tree_node *node, int depth)
{
print_indent(depth);
printk(BIOS_DEBUG, "name = %s\n", node->name);
@@ -463,7 +465,7 @@ static void print_node(struct device_tree_node *node, int depth)
print_node(child, depth + 1);
}
-void dt_print_node(struct device_tree_node *node)
+void dt_print_node(const struct device_tree_node *node)
{
print_node(node, 0);
}
@@ -481,7 +483,8 @@ void dt_print_node(struct device_tree_node *node)
* @param addrcp Pointer to store #address-cells in, skipped if NULL.
* @param sizecp Pointer to store #size-cells in, skipped if NULL.
*/
-void dt_read_cell_props(struct device_tree_node *node, u32 *addrcp, u32 *sizecp)
+void dt_read_cell_props(const struct device_tree_node *node, u32 *addrcp,
+ u32 *sizecp)
{
struct device_tree_property *prop;
list_for_each(prop, node->properties, list_node) {
@@ -706,7 +709,7 @@ struct device_tree_node *dt_find_prop_value(struct device_tree_node *parent,
list_for_each(prop, parent->properties, list_node) {
if (!strcmp(name, prop->prop.name)) {
size_t bytes = prop->prop.size;
- void *prop_data = prop->prop.data;
+ const void *prop_data = prop->prop.data;
if (size != bytes)
break;
if (!memcmp(data, prop_data, size))
@@ -731,16 +734,16 @@ struct device_tree_node *dt_find_prop_value(struct device_tree_node *parent,
* @param node Pointer to node containing the phandle
* @return Zero on error, the phandle on success
*/
-uint32_t dt_get_phandle(struct device_tree_node *node)
+uint32_t dt_get_phandle(const struct device_tree_node *node)
{
- uint32_t *phandle;
+ const uint32_t *phandle;
size_t len;
- dt_find_bin_prop(node, "phandle", (void **)&phandle, &len);
+ dt_find_bin_prop(node, "phandle", (const void **)&phandle, &len);
if (phandle != NULL && len == sizeof(*phandle))
return be32_to_cpu(*phandle);
- dt_find_bin_prop(node, "linux,phandle", (void **)&phandle, &len);
+ dt_find_bin_prop(node, "linux,phandle", (const void **)&phandle, &len);
if (phandle != NULL && len == sizeof(*phandle))
return be32_to_cpu(*phandle);
@@ -789,7 +792,7 @@ void dt_delete_prop(struct device_tree_node *node, const char *name)
* @param size The size of data in bytes.
*/
void dt_add_bin_prop(struct device_tree_node *node, const char *name,
- void *data, size_t size)
+ const void *data, size_t size)
{
struct device_tree_property *prop;
@@ -817,9 +820,10 @@ void dt_add_bin_prop(struct device_tree_node *node, const char *name,
* @param name The name of the property.
* @return The found string, or NULL.
*/
-const char *dt_find_string_prop(struct device_tree_node *node, const char *name)
+const char *dt_find_string_prop(const struct device_tree_node *node,
+ const char *name)
{
- void *content;
+ const void *content;
size_t size;
dt_find_bin_prop(node, name, &content, &size);
@@ -835,8 +839,8 @@ const char *dt_find_string_prop(struct device_tree_node *node, const char *name)
* @param data Pointer to return raw data blob in the property.
* @param size Pointer to return the size of data in bytes.
*/
-void dt_find_bin_prop(struct device_tree_node *node, const char *name,
- void **data, size_t *size)
+void dt_find_bin_prop(const struct device_tree_node *node, const char *name,
+ const void **data, size_t *size)
{
struct device_tree_property *prop;
@@ -860,7 +864,7 @@ void dt_find_bin_prop(struct device_tree_node *node, const char *name,
* @param str The zero-terminated string to be stored in the property.
*/
void dt_add_string_prop(struct device_tree_node *node, const char *name,
- char *str)
+ const char *str)
{
dt_add_bin_prop(node, name, str, strlen(str) + 1);
}
diff --git a/src/lib/fit.c b/src/lib/fit.c
index 68f5bed2b8..da550723d2 100644
--- a/src/lib/fit.c
+++ b/src/lib/fit.c
@@ -158,7 +158,7 @@ static struct fit_image_node *find_image(const char *name)
return NULL;
}
-static int fdt_find_compat(void *blob, uint32_t start_offset,
+static int fdt_find_compat(const void *blob, uint32_t start_offset,
struct fdt_property *prop)
{
int offset = start_offset;
@@ -196,7 +196,7 @@ static int fit_check_compat(struct fdt_property *compat_prop,
return -1;
}
-void fit_update_chosen(struct device_tree *tree, char *cmd_line)
+void fit_update_chosen(struct device_tree *tree, const char *cmd_line)
{
const char *path[] = { "chosen", NULL };
struct device_tree_node *node;
@@ -388,10 +388,12 @@ void fit_update_memory(struct device_tree *tree)
* @param fdt_blob Pointer to FDT
* @param config The current config node to operate on
*/
-static void fit_update_compat(void *fdt_blob, struct fit_config_node *config)
+static void fit_update_compat(const void *fdt_blob,
+ struct fit_config_node *config)
{
struct compat_string_entry *compat_node;
- struct fdt_header *fdt_header = (struct fdt_header *)fdt_blob;
+ const struct fdt_header *fdt_header =
+ (const struct fdt_header *)fdt_blob;
uint32_t fdt_offset = be32_to_cpu(fdt_header->structure_offset);
size_t i = 0;
diff --git a/src/lib/fit_payload.c b/src/lib/fit_payload.c
index ec947c060e..3e1819d931 100644
--- a/src/lib/fit_payload.c
+++ b/src/lib/fit_payload.c
@@ -119,7 +119,7 @@ static void add_cb_fdt_data(struct device_tree *tree)
struct device_tree_node *coreboot_node = dt_find_node(firmware_node,
coreboot_path, &addr_cells, &size_cells, 1);
- dt_add_string_prop(coreboot_node, "compatible", strdup("coreboot"));
+ dt_add_string_prop(coreboot_node, "compatible", "coreboot");
/* Fetch CB tables from cbmem */
void *cbtable = cbmem_find(CBMEM_ID_CBTABLE);