MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / fdt_install_initrd

Function fdt_install_initrd

components/drivers/ofw/raw.c:130–197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

128}
129
130int fdt_install_initrd(void *fdt, char *os_name, size_t initrd_addr, size_t initrd_size)
131{
132 int err = -FDT_ERR_NOTFOUND;
133 int chosen_offset = -1, root_off = fdt_path_offset(fdt, "/");
134
135 if (root_off >= 0)
136 {
137 chosen_offset = fdt_subnode_offset(fdt, root_off, "chosen");
138
139 if (chosen_offset == -FDT_ERR_NOTFOUND)
140 {
141 chosen_offset = fdt_add_subnode_possible(fdt, root_off, "chosen");
142 }
143 }
144
145 if (chosen_offset >= 0)
146 {
147 uint64_t addr, size;
148
149 err = 0;
150
151 /* Update the entry */
152 for (int i = fdt_num_mem_rsv(fdt) - 1; i >= 0; --i)
153 {
154 fdt_get_mem_rsv(fdt, i, &addr, &size);
155
156 if (addr == initrd_addr)
157 {
158 fdt_del_mem_rsv(fdt, i);
159 break;
160 }
161 }
162
163 /* Add the memory */
164 if (fdt_add_mem_rsv(fdt, initrd_addr, initrd_size) < 0)
165 {
166 /* Move the memory */
167 fdt_open_into(fdt, fdt, fdt_totalsize(fdt) + FDT_PADDING_SIZE);
168
169 if (fdt_add_mem_rsv(fdt, initrd_addr, initrd_size) < 0)
170 {
171 err = -FDT_ERR_NOSPACE;
172 }
173 }
174
175 if (!err)
176 {
177 size_t name_len;
178 char initrd_name[64];
179 bool is_u64 = (fdt_io_addr_cells(fdt, root_off) == 2);
180
181 if (!os_name)
182 {
183 os_name = "rt-thread";
184 }
185
186 name_len = strlen(initrd_name);
187

Callers

nothing calls this directly

Calls 10

fdt_add_subnode_possibleFunction · 0.85
fdt_io_addr_cellsFunction · 0.85
fdt_setprop_uxxFunction · 0.85
fdt_path_offsetFunction · 0.50
fdt_subnode_offsetFunction · 0.50
fdt_num_mem_rsvFunction · 0.50
fdt_get_mem_rsvFunction · 0.50
fdt_del_mem_rsvFunction · 0.50
fdt_add_mem_rsvFunction · 0.50
fdt_open_intoFunction · 0.50

Tested by

no test coverage detected