66 off_t initrd_start,
size_t initrd_len)
68 const char *root_path =
"/";
69 const char *node_name =
"chosen";
70 const char *full_path_node_name =
"/chosen";
71 const char *bootargs_property_name =
"bootargs";
72 const char *linux_initrd_start_property_name =
"linux,initrd-start";
73 const char *linux_initrd_end_property_name =
"linux,initrd-end";
77 uint8_t *fdt_buf_w_space =
new uint8_t[newLen];
79 int ret = fdt_open_into((
void *)
fileData, (
void *)fdt_buf_w_space, newLen);
81 warn(
"Error resizing buffer of flattened device tree, "
83 delete [] fdt_buf_w_space;
88 int offset = fdt_path_offset((
void *)fdt_buf_w_space, full_path_node_name);
91 offset = fdt_path_offset((
void *)fdt_buf_w_space, root_path);
92 offset = fdt_add_subnode((
void *)fdt_buf_w_space,
offset, node_name);
95 offset = fdt_path_offset((
void *)fdt_buf_w_space,
99 warn(
"Error finding or adding \"chosen\" subnode to flattened "
100 "device tree, errno: %d\n",
offset);
101 delete [] fdt_buf_w_space;
107 ret = fdt_setprop((
void *)fdt_buf_w_space,
offset, bootargs_property_name,
108 (
const void *)_cmdline, cmdline_len+1);
110 warn(
"Error setting \"bootargs\" property to flattened device tree, "
112 delete [] fdt_buf_w_space;
116 if (initrd_len != 0) {
118 ret = fdt_setprop_u64((
void *)fdt_buf_w_space,
offset,
119 linux_initrd_start_property_name,
120 (uint64_t)initrd_start);
122 warn(
"Error setting \"linux,initrd-start\" property to flattened "
123 "device tree, errno: %d\n", ret);
124 delete [] fdt_buf_w_space;
129 ret = fdt_setprop_u64((
void *)fdt_buf_w_space,
offset,
130 linux_initrd_end_property_name,
131 (uint64_t)initrd_start + initrd_len);
133 warn(
"Error setting \"linux,initrd-len\" property to flattened "
134 "device tree, errno: %d\n", ret);
135 delete [] fdt_buf_w_space;
141 ret = fdt_pack((
void *)fdt_buf_w_space);
143 warn(
"Error re-packing flattened device tree structure, "
145 delete [] fdt_buf_w_space;
bool addBootData(const char *_cmdline, size_t cmdline_len, off_t initrd_addr, size_t initrd_len)
Adds the passed in Command Line options and initrd for the kernel to the proper location in the devic...