mirror of
https://github.com/torvalds/linux.git
synced 2025-10-30 08:08:27 +02:00
This adds the following commits from upstream: 52f07dcca47c dtc: Add informative error for stray identifier 9cabae6b0351 checks: Fix detection of 'i2c-bus' node 605dc044c3fe New helper to add markers 7da5d106c740 fdtput: Fix documentation about existing nodes 53c63dd421d7 dtdiff: Use input format dtb for dtbo files 84d9dd2fcbc8 dtc: Add data_insert_data function 97011d1f4e98 meson: use override_find_program/override_dependency b841391bbd08 srcpos: Define srcpos_free e0b7749c26a9 Add alloc_marker ecb21febfdd3 meson: port python bindings to build natively via meson and meson-python 7ebfcac8520e Makefile: deprecate in favor of Meson f4c53f4ebf78 Use __ASSEMBLER__ instead of __ASSEMBLY__ 205fbef17b7b Fix some typos da85f91931e5 Remove duplicated words in documentation and comments dd1b3e532d22 meson: support building libfdt without static library 1ccd232709d4 meson: don't build test programs by default ce1d8588880a tests: When building .so from -O asm output mark as non-executable stack 915daadbb62d Start with empty __local_fixups__ and __fixups__ nodes 4ea851f5a44d Let get_subnode() not return deleted nodes 175d2a564c47 Use build_root_node() instead of open-coding it 18f4f305fdd7 build: fix -Dtools=false build 267efc7d4694 checks: Warn about missing #address-cells for interrupt parents 755db115355b libfdt: Add fdt_setprop_namelen_string() bdca8612009e libfdt: Add fdt_setprop_namelen() 0f69cedc08fc libfdt_internal: fdt_find_string_len_() 56b2b30c5bd0 libfdt: add fdt_get_property_namelen_w() 1e8c5f60e127 Add clang-format config 6f183c7d9246 checks: Relax avoid_unnecessary_addr_size check to allow child ranges properties 66c7d0e6f4f3 tests/sw_tree1.c: fix unitialized saveptr 9a969f3b70b0 pylibfdt/libfdt.i: fix backwards compatibility of return values 4292b072a23a .github/workflows: update ubuntu runner to supported version 1c745a9bd169 libfdt: Remove fdt parameter from overlay_fixup_one_phandle b3bbee6b1242 libfdt: Move the SBOM authors section d1656730abfb Add a SBOM file in CycloneDX format b75515af4576 libfdt: Remove extra semi-colons outside functions 2d10aa2afe35 Bump version to v1.7.2 48795c82bdb6 pylibfdt: Don't emit warnings from swig generate C code 838f11e830e3 fdtoverlay: provide better error message for missing `/__symbols__` d1e2384185c5 pylibfdt/libfdt.i: Use SWIG_AppendOutput 18aa49a9f68d Escape spaces in depfile with backslashes. f9968fa06921 libfdt.h: whitespace consistency fixups 9b5f65fb3d8d libfdt.h: typo and consistency fixes 99031e3a4a6e Bump version to v1.7.1 3d5e376925fd setup: Move setting of srcdir down to the bottom e277553b9880 setup: Collect top-level code together 7e5a88984081 setup: Move version and full_description into a function 78b6a85c113b Tidy up some pylint warnings 3501d373f0a2 Require Python 3 The added include of string.h in libfdt_internal.h breaks the kernel overriding libfdt_env.h with its own string functions, so it is dropped. An upstream fix is pending. Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
293 lines
5.2 KiB
C
293 lines
5.2 KiB
C
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
/*
|
|
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
|
|
*/
|
|
|
|
#include "dtc.h"
|
|
|
|
void data_free(struct data d)
|
|
{
|
|
struct marker *m, *nm;
|
|
|
|
m = d.markers;
|
|
while (m) {
|
|
nm = m->next;
|
|
free(m->ref);
|
|
free(m);
|
|
m = nm;
|
|
}
|
|
|
|
if (d.val)
|
|
free(d.val);
|
|
}
|
|
|
|
struct data data_grow_for(struct data d, unsigned int xlen)
|
|
{
|
|
struct data nd;
|
|
unsigned int newsize;
|
|
|
|
if (xlen == 0)
|
|
return d;
|
|
|
|
nd = d;
|
|
|
|
newsize = xlen;
|
|
|
|
while ((d.len + xlen) > newsize)
|
|
newsize *= 2;
|
|
|
|
nd.val = xrealloc(d.val, newsize);
|
|
|
|
return nd;
|
|
}
|
|
|
|
struct data data_copy_mem(const char *mem, int len)
|
|
{
|
|
struct data d;
|
|
|
|
d = data_grow_for(empty_data, len);
|
|
|
|
d.len = len;
|
|
memcpy(d.val, mem, len);
|
|
|
|
return d;
|
|
}
|
|
|
|
struct data data_copy_escape_string(const char *s, int len)
|
|
{
|
|
int i = 0;
|
|
struct data d;
|
|
char *q;
|
|
|
|
d = data_add_marker(empty_data, TYPE_STRING, NULL);
|
|
d = data_grow_for(d, len + 1);
|
|
|
|
q = d.val;
|
|
while (i < len) {
|
|
char c = s[i++];
|
|
|
|
if (c == '\\')
|
|
c = get_escape_char(s, &i);
|
|
|
|
q[d.len++] = c;
|
|
}
|
|
|
|
q[d.len++] = '\0';
|
|
return d;
|
|
}
|
|
|
|
struct data data_copy_file(FILE *f, size_t maxlen)
|
|
{
|
|
struct data d = empty_data;
|
|
|
|
d = data_add_marker(d, TYPE_NONE, NULL);
|
|
while (!feof(f) && (d.len < maxlen)) {
|
|
size_t chunksize, ret;
|
|
|
|
if (maxlen == (size_t)-1)
|
|
chunksize = 4096;
|
|
else
|
|
chunksize = maxlen - d.len;
|
|
|
|
d = data_grow_for(d, chunksize);
|
|
ret = fread(d.val + d.len, 1, chunksize, f);
|
|
|
|
if (ferror(f))
|
|
die("Error reading file into data: %s", strerror(errno));
|
|
|
|
if (d.len + ret < d.len)
|
|
die("Overflow reading file into data\n");
|
|
|
|
d.len += ret;
|
|
}
|
|
|
|
return d;
|
|
}
|
|
|
|
struct data data_append_data(struct data d, const void *p, int len)
|
|
{
|
|
d = data_grow_for(d, len);
|
|
memcpy(d.val + d.len, p, len);
|
|
d.len += len;
|
|
return d;
|
|
}
|
|
|
|
struct data data_insert_at_marker(struct data d, struct marker *m,
|
|
const void *p, int len)
|
|
{
|
|
d = data_grow_for(d, len);
|
|
memmove(d.val + m->offset + len, d.val + m->offset, d.len - m->offset);
|
|
memcpy(d.val + m->offset, p, len);
|
|
d.len += len;
|
|
|
|
/* Adjust all markers after the one we're inserting at */
|
|
m = m->next;
|
|
for_each_marker(m)
|
|
m->offset += len;
|
|
return d;
|
|
}
|
|
|
|
static struct data data_append_markers(struct data d, struct marker *m)
|
|
{
|
|
struct marker **mp = &d.markers;
|
|
|
|
/* Find the end of the markerlist */
|
|
while (*mp)
|
|
mp = &((*mp)->next);
|
|
*mp = m;
|
|
return d;
|
|
}
|
|
|
|
struct data data_merge(struct data d1, struct data d2)
|
|
{
|
|
struct data d;
|
|
struct marker *m2 = d2.markers;
|
|
|
|
d = data_append_markers(data_append_data(d1, d2.val, d2.len), m2);
|
|
|
|
/* Adjust for the length of d1 */
|
|
for_each_marker(m2)
|
|
m2->offset += d1.len;
|
|
|
|
d2.markers = NULL; /* So data_free() doesn't clobber them */
|
|
data_free(d2);
|
|
|
|
return d;
|
|
}
|
|
|
|
struct data data_append_integer(struct data d, uint64_t value, int bits)
|
|
{
|
|
uint8_t value_8;
|
|
fdt16_t value_16;
|
|
fdt32_t value_32;
|
|
fdt64_t value_64;
|
|
|
|
switch (bits) {
|
|
case 8:
|
|
value_8 = value;
|
|
return data_append_data(d, &value_8, 1);
|
|
|
|
case 16:
|
|
value_16 = cpu_to_fdt16(value);
|
|
return data_append_data(d, &value_16, 2);
|
|
|
|
case 32:
|
|
value_32 = cpu_to_fdt32(value);
|
|
return data_append_data(d, &value_32, 4);
|
|
|
|
case 64:
|
|
value_64 = cpu_to_fdt64(value);
|
|
return data_append_data(d, &value_64, 8);
|
|
|
|
default:
|
|
die("Invalid literal size (%d)\n", bits);
|
|
}
|
|
}
|
|
|
|
struct data data_append_re(struct data d, uint64_t address, uint64_t size)
|
|
{
|
|
struct fdt_reserve_entry re;
|
|
|
|
re.address = cpu_to_fdt64(address);
|
|
re.size = cpu_to_fdt64(size);
|
|
|
|
return data_append_data(d, &re, sizeof(re));
|
|
}
|
|
|
|
struct data data_append_cell(struct data d, cell_t word)
|
|
{
|
|
return data_append_integer(d, word, sizeof(word) * 8);
|
|
}
|
|
|
|
struct data data_append_addr(struct data d, uint64_t addr)
|
|
{
|
|
return data_append_integer(d, addr, sizeof(addr) * 8);
|
|
}
|
|
|
|
struct data data_append_byte(struct data d, uint8_t byte)
|
|
{
|
|
return data_append_data(d, &byte, 1);
|
|
}
|
|
|
|
struct data data_append_zeroes(struct data d, int len)
|
|
{
|
|
d = data_grow_for(d, len);
|
|
|
|
memset(d.val + d.len, 0, len);
|
|
d.len += len;
|
|
return d;
|
|
}
|
|
|
|
struct data data_append_align(struct data d, int align)
|
|
{
|
|
int newlen = ALIGN(d.len, align);
|
|
return data_append_zeroes(d, newlen - d.len);
|
|
}
|
|
|
|
struct data data_add_marker(struct data d, enum markertype type, char *ref)
|
|
{
|
|
struct marker *m;
|
|
|
|
m = alloc_marker(d.len, type, ref);
|
|
|
|
return data_append_markers(d, m);
|
|
}
|
|
|
|
bool data_is_one_string(struct data d)
|
|
{
|
|
int i;
|
|
int len = d.len;
|
|
|
|
if (len == 0)
|
|
return false;
|
|
|
|
for (i = 0; i < len-1; i++)
|
|
if (d.val[i] == '\0')
|
|
return false;
|
|
|
|
if (d.val[len-1] != '\0')
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
struct data data_insert_data(struct data d, struct marker *m, struct data old)
|
|
{
|
|
unsigned int offset = m->offset;
|
|
struct marker *next = m->next;
|
|
struct marker *marker;
|
|
struct data new_data;
|
|
char *ref;
|
|
|
|
new_data = data_insert_at_marker(d, m, old.val, old.len);
|
|
|
|
/* Copy all markers from old value */
|
|
marker = old.markers;
|
|
for_each_marker(marker) {
|
|
ref = NULL;
|
|
|
|
if (marker->ref)
|
|
ref = xstrdup(marker->ref);
|
|
|
|
m->next = alloc_marker(marker->offset + offset, marker->type,
|
|
ref);
|
|
m = m->next;
|
|
}
|
|
m->next = next;
|
|
|
|
return new_data;
|
|
}
|
|
|
|
struct marker *alloc_marker(unsigned int offset, enum markertype type,
|
|
char *ref)
|
|
{
|
|
struct marker *m;
|
|
|
|
m = xmalloc(sizeof(*m));
|
|
m->offset = offset;
|
|
m->type = type;
|
|
m->ref = ref;
|
|
m->next = NULL;
|
|
|
|
return m;
|
|
}
|