diff --git a/src/include/device_tree.h b/src/include/device_tree.h index 4c1a37c00c..14be8322c6 100644 --- a/src/include/device_tree.h +++ b/src/include/device_tree.h @@ -50,7 +50,7 @@ struct fdt_header { struct fdt_property { const char *name; - void *data; + const void *data; uint32_t size; }; @@ -88,7 +88,7 @@ struct device_tree_reserve_map_entry struct device_tree { - void *header; + const void *header; uint32_t header_size; struct list_node reserve_map; @@ -104,17 +104,18 @@ struct device_tree */ // Read the property, if any, at offset offset. -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); // Read the name of the node, if any, at offset offset. -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); -void fdt_print_node(void *blob, uint32_t offset); -int fdt_skip_node(void *blob, uint32_t offset); +void fdt_print_node(const void *blob, uint32_t offset); +int fdt_skip_node(const void *blob, uint32_t offset); // Read a flattened device tree into a heirarchical structure which refers to // the contents of the flattened tree in place. Modifying the flat tree // invalidates the unflattened one. -struct device_tree *fdt_unflatten(void *blob); +struct device_tree *fdt_unflatten(const void *blob); @@ -123,12 +124,13 @@ struct device_tree *fdt_unflatten(void *blob); */ // Figure out how big a device tree would be if it were flattened. -uint32_t dt_flat_size(struct device_tree *tree); +uint32_t dt_flat_size(const struct device_tree *tree); // Flatten a device tree into the buffer pointed to by dest. -void dt_flatten(struct device_tree *tree, void *dest); -void dt_print_node(struct device_tree_node *node); +void dt_flatten(const struct device_tree *tree, void *dest); +void dt_print_node(const struct device_tree_node *node); // Read #address-cells and #size-cells properties from a node. -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); // Look up or create a node relative to a parent node, through its path // represented as an array of strings. struct device_tree_node *dt_find_node(struct device_tree_node *parent, const char **path, @@ -148,15 +150,16 @@ struct device_tree_node *dt_find_next_compat_child(struct device_tree_node *pare struct device_tree_node *dt_find_prop_value(struct device_tree_node *parent, const char *name, void *data, size_t size); // Return the phandle -uint32_t dt_get_phandle(struct device_tree_node *node); +uint32_t dt_get_phandle(const struct device_tree_node *node); // Write src into *dest as a 'length'-byte big-endian integer. void dt_write_int(u8 *dest, u64 src, size_t length); // Delete a property void dt_delete_prop(struct device_tree_node *node, const char *name); // Add different kinds of properties to a node, or update existing ones. -void dt_add_bin_prop(struct device_tree_node *node, const char *name, void *data, - size_t size); -void dt_add_string_prop(struct device_tree_node *node, const char *name, char *str); +void dt_add_bin_prop(struct device_tree_node *node, const char *name, + const void *data, size_t size); +void dt_add_string_prop(struct device_tree_node *node, const char *name, + const char *str); void dt_add_u32_prop(struct device_tree_node *node, const char *name, u32 val); void dt_add_u64_prop(struct device_tree_node *node, const char *name, u64 val); void dt_add_reg_prop(struct device_tree_node *node, u64 *addrs, u64 *sizes, @@ -164,9 +167,10 @@ void dt_add_reg_prop(struct device_tree_node *node, u64 *addrs, u64 *sizes, int dt_set_bin_prop_by_path(struct device_tree *tree, const char *path, void *data, size_t size, int create); -void dt_find_bin_prop(struct device_tree_node *node, const char *name, void **data, - size_t *size); -const char *dt_find_string_prop(struct device_tree_node *node, const char *name); +void dt_find_bin_prop(const struct device_tree_node *node, const char *name, + const void **data, size_t *size); +const char *dt_find_string_prop(const struct device_tree_node *node, + const char *name); /* * Fixups to apply to a kernel's device tree before booting it. diff --git a/src/include/fit.h b/src/include/fit.h index eb51b50edb..6e0667f6cf 100644 --- a/src/include/fit.h +++ b/src/include/fit.h @@ -27,7 +27,7 @@ struct fit_image_node { const char *name; - void *data; + const void *data; uint32_t size; int compression; @@ -54,7 +54,7 @@ struct fit_config_node /* * Updates the cmdline in the devicetree. */ -void fit_update_chosen(struct device_tree *tree, char *cmd_line); +void fit_update_chosen(struct device_tree *tree, const char *cmd_line); /* * Add a compat string to the list of supported board ids. 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); diff --git a/src/soc/cavium/cn81xx/soc.c b/src/soc/cavium/cn81xx/soc.c index 8efcb1374c..dfb06e0f37 100644 --- a/src/soc/cavium/cn81xx/soc.c +++ b/src/soc/cavium/cn81xx/soc.c @@ -64,9 +64,9 @@ static const char *QLM_BGX_MODE_MAP[BDK_QLM_MODE_LAST] = { static void dt_platform_fixup_phy(struct device_tree_node *node, char *path, int64_t phy_address, bdk_qlm_modes_t qlm_mode) { - char *data = NULL; + const char *data = NULL; size_t size = 0; - dt_find_bin_prop(node, "qlm-mode", (void **)&data, &size); + dt_find_bin_prop(node, "qlm-mode", (const void **)&data, &size); if (!data || strncmp(data, path, 6) != 0) return; /* No key prefix match. */ @@ -127,10 +127,10 @@ static void dt_iterate_phy(struct device_tree_node *parent, static void dt_platform_fixup_mac(struct device_tree_node *node) { const char *name = "local-mac-address"; - u64 *localmac = NULL; + const u64 *localmac = NULL; size_t size = 0; - dt_find_bin_prop(node, name, (void **)&localmac, &size); + dt_find_bin_prop(node, name, (const void **)&localmac, &size); if (!localmac) return; @@ -150,8 +150,8 @@ static void dt_platform_fixup_mac(struct device_tree_node *node) if (*localmac) return; if (used_mac < num_free_mac_addresses) { - *localmac = next_free_mac_address + used_mac; - dt_add_bin_prop(node, name, (void *)&localmac, 6); + const u64 genmac = next_free_mac_address + used_mac; + dt_add_bin_prop(node, name, &genmac, 6); used_mac++; return; } @@ -232,9 +232,10 @@ static int dt_platform_fixup(struct device_tree_fixup *fixup, __func__); continue; } - u32 *data = NULL; + const u32 *data = NULL; size_t size = 0; - dt_find_bin_prop(dt_node, "mmu-masters", (void **)&data, &size); + dt_find_bin_prop(dt_node, "mmu-masters", (const void **)&data, + &size); if (!size) { printk(BIOS_ERR, "%s: mmu-masters entry not found\n", __func__);