Пример #1
0
int fdt_nop_node(void *fdt, int nodeoffset)
{
	int endoffset;

	endoffset = _fdt_node_end_offset(fdt, nodeoffset);
	if (endoffset < 0)
		return endoffset;

	_fdt_nop_region(fdt_offset_ptr_w(fdt, nodeoffset, 0),
			endoffset - nodeoffset);
	return 0;
}
Пример #2
0
static void *_fdt_grab_space(void *fdt, int len)
{
	int offset = fdt_size_dt_struct(fdt);
	int spaceleft;

	spaceleft = fdt_totalsize(fdt) - fdt_off_dt_struct(fdt)
		- fdt_size_dt_strings(fdt);

	if ((offset + len < offset) || (offset + len > spaceleft))
		return NULL;

	fdt_set_size_dt_struct(fdt, offset + len);
	return fdt_offset_ptr_w(fdt, offset, len);
}
Пример #3
0
int fdt_finish(void *fdt)
{
    int err = check_header_sw(fdt);
    char *p = (char *)fdt;
    uint32_t *end;
    int oldstroffset, newstroffset;
    uint32_t tag;
    int offset, nextoffset;

    if (err)
        return err;

    /* Add terminator */
    end = grab_space(fdt, sizeof(*end));
    if (! end)
        return -FDT_ERR_NOSPACE;
    *end = cpu_to_fdt32(FDT_END);

    /* Relocate the string table */
    oldstroffset = fdt_totalsize(fdt) - fdt_size_dt_strings(fdt);
    newstroffset = fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt);
    memmove(p + newstroffset, p + oldstroffset, fdt_size_dt_strings(fdt));
    fdt_set_off_dt_strings(fdt, newstroffset);

    /* Walk the structure, correcting string offsets */
    offset = 0;
    while ((tag = fdt_next_tag(fdt, offset, &nextoffset)) != FDT_END) {
        if (tag == FDT_PROP) {
            struct fdt_property *prop =
                fdt_offset_ptr_w(fdt, offset, sizeof(*prop));
            int nameoff;

            if (! prop)
                return -FDT_ERR_BADSTRUCTURE;

            nameoff = fdt32_to_cpu(prop->nameoff);
            nameoff += fdt_size_dt_strings(fdt);
            prop->nameoff = cpu_to_fdt32(nameoff);
        }
        offset = nextoffset;
    }

    /* Finally, adjust the header */
    fdt_set_totalsize(fdt, newstroffset + fdt_size_dt_strings(fdt));
    fdt_set_magic(fdt, FDT_MAGIC);
    return 0;
}