1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2016 Freescale Semiconductor, Inc.
6 #include <fsl_qe.h> /* For struct qe_firmware */
8 #ifdef CONFIG_SYS_DPAA_FMAN
10 * fdt_fixup_fman_firmware -- insert the Fman firmware into the device tree
12 * The binding for an Fman firmware node is documented in
13 * Documentation/powerpc/dts-bindings/fsl/dpaa/fman.txt. This node contains
14 * the actual Fman firmware binary data. The operating system is expected to
15 * be able to parse the binary data to determine any attributes it needs.
17 void fdt_fixup_fman_firmware(void *blob)
19 int rc, fmnode, fwnode = -1;
21 struct qe_firmware *fmanfw;
22 const struct qe_header *hdr;
27 /* The first Fman we find will contain the actual firmware. */
28 fmnode = fdt_node_offset_by_compatible(blob, -1, "fsl,fman");
30 /* Exit silently if there are no Fman devices */
33 /* If we already have a firmware node, then also exit silently. */
34 if (fdt_node_offset_by_compatible(blob, -1, "fsl,fman-firmware") > 0)
37 /* If the environment variable is not set, then exit silently */
38 p = env_get("fman_ucode");
42 fmanfw = (struct qe_firmware *)simple_strtoul(p, NULL, 16);
46 hdr = &fmanfw->header;
47 length = fdt32_to_cpu(hdr->length);
49 /* Verify the firmware. */
50 if ((hdr->magic[0] != 'Q') || (hdr->magic[1] != 'E') ||
51 (hdr->magic[2] != 'F')) {
52 printf("Data at %p is not an Fman firmware\n", fmanfw);
56 if (length > CONFIG_SYS_QE_FMAN_FW_LENGTH) {
57 printf("Fman firmware at %p is too large (size=%u)\n",
62 length -= sizeof(u32); /* Subtract the size of the CRC */
63 crc = fdt32_to_cpu(*(u32 *)((void *)fmanfw + length));
64 if (crc != crc32_no_comp(0, (void *)fmanfw, length)) {
65 printf("Fman firmware at %p has invalid CRC\n", fmanfw);
69 length += sizeof(u32);
71 /* Increase the size of the fdt to make room for the node. */
72 rc = fdt_increase_size(blob, length);
74 printf("Unable to make room for Fman firmware: %s\n",
79 /* Create the firmware node. */
80 fwnode = fdt_add_subnode(blob, fmnode, "fman-firmware");
83 fdt_get_path(blob, fmnode, s, sizeof(s));
84 printf("Could not add firmware node to %s: %s\n", s,
85 fdt_strerror(fwnode));
88 rc = fdt_setprop_string(blob, fwnode, "compatible",
92 fdt_get_path(blob, fwnode, s, sizeof(s));
93 printf("Could not add compatible property to node %s: %s\n", s,
97 phandle = fdt_create_phandle(blob, fwnode);
100 fdt_get_path(blob, fwnode, s, sizeof(s));
101 printf("Could not add phandle property to node %s: %s\n", s,
105 rc = fdt_setprop(blob, fwnode, "fsl,firmware", fmanfw, length);
108 fdt_get_path(blob, fwnode, s, sizeof(s));
109 printf("Could not add firmware property to node %s: %s\n", s,
114 /* Find all other Fman nodes and point them to the firmware node. */
115 while ((fmnode = fdt_node_offset_by_compatible(blob, fmnode,
117 rc = fdt_setprop_cell(blob, fmnode, "fsl,firmware-phandle",
121 fdt_get_path(blob, fmnode, s, sizeof(s));
122 printf("Could not add pointer property to node %s: %s\n",
123 s, fdt_strerror(rc));