mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-25 05:04:09 +08:00
f858927fd6
Major changes are I2C and SPI bus checks, YAML output format (for future validation), some new libfdt functions, and more libfdt validation of dtbs. The YAML addition adds an optional dependency on libyaml. pkg-config is used to test for it and pkg-config became a kconfig dependency in 4.18. This adds the following commits from upstream: c86da84d30e4 Add support for YAML encoded output 361b5e7d8067 Make type_marker_length helper public bfbfab047e45 pylibfdt: Add a means to add and delete notes 9005f4108e7c pylibfdt: Allow delprop() to return errors b94c056b137e Make valgrind optional fd06c54d4711 tests: Better testing of dtc -I fs mode c3f50c9a86d9 tests: Allow dtbs_equal_unordered to ignore mem reserves 0ac9fdee37c7 dtc: trivial '-I fs -O dts' test 0fd1c8c783f3 pylibfdt: fdt_get_mem_rsv returns 2 uint64_t values 04853cad18f4 pylibfdt: Don't incorrectly / unnecessarily override uint64_t typemap 9619c8619c37 Kill bogus TYPE_BLOB marker type ac68ff92ae20 parser: add TYPE_STRING marker to path references 90a190eb04d9 checks: add SPI bus checks 53a1bd546905 checks: add I2C bus checks 88f18909db73 dtc: Bump version to v1.4.7 85bce8b2f06d tests: Correction to vg_prepare_blob() 57f7f9e7bc7c tests: Don't call memcmp() with NULL arguments c12b2b0c20eb libfdt: fdt_address_cells() and fdt_size_cells() 3fe0eeda0b7f livetree: Set phandle properties type to uint32 853649acceba pylibfdt: Support the sequential-write interface 9b0e4fe26093 tests: Improve fdt_resize() tests 1087504bb3e8 libfdt: Add necessary header padding in fdt_create() c72fa777e613 libfdt: Copy the struct region in fdt_resize() 32b9c6130762 Preserve datatype markers when emitting dts format 6dcb8ba408ec libfdt: Add helpers for accessing unaligned words 42607f21d43e tests: Fix incorrect check name 'prop_name_chars' 9d78c33bf8a1 tests: fix grep for checks error messages b770f3d1c13f pylibfdt: Support setting the name of a node 2f0d07e678e0 pylibfdt: Add functions to set and get properties as strings 354d3dc55939 pylibfdt: Update the bytearray size with pack() 3c374d46acce pylibfdt: Allow reading integer values from properties 49d32ce40bb4 pylibfdt: Use an unsigned type for fdt32_t 481246a0c13a pylibfdt: Avoid accessing the internal _fdt member in tests 9aafa33d99ed pylibfdt: Add functions to update properties 5a598671fdbf pylibfdt: Support device-tree creation/expansion 483e170625e1 pylibfdt: Add support for reading the memory reserve map 29bb05aa4200 pylibfdt: Add support for the rest of the header functions 582a7159a5d0 pylibfdt: Add support for fdt_next_node() f0f8c9169819 pylibfdt: Reorder functions to match libfdt.h 64a69d123935 pylibfdt: Return string instead of bytearray from getprop() 4d09a83420df fdtput: Add documentation e617cbe1bd67 fdtget: Add documentation 180a93924014 Use <inttypes.h> format specifiers in a bunch of places we should b9af3b396576 scripts/dtc: Fixed format mismatch in fprintf 4b8fcc3d015c libfdt: Add fdt_check_full() function c14223fb2292 tests: Use valgrind client requests for better checking 5b67d2b955a3 tests: Better handling of valgrind errors saving blobs e2556aaeb506 tests: Remove unused #define fb9c6abddaa8 Use size_t for blob lengths in utilfdt_read* 0112fda03bf6 libfdt: Add fdt_header_size() 6473a21d8bfe Consolidate utilfdt_read_len() variants d5db5382c5e5 libfdt: Safer access to memory reservations 719d582e98ec libfdt: Propagate name errors in fdt_getprop_by_offset() 70166d62a27f libfdt: Safer access to strings section eb890c0f77dc libfdt: Make fdt_check_header() more thorough 899d6fad93f3 libfdt: Improve sequential write state checking 04b5b4062ccd libfdt: Clean up header checking functions 44d3efedc816 Preserve datatype information when parsing dts f0be81bd8de0 Make Property a subclass of bytearray 24b1f3f064d4 pylibfdt: Add a method to access the device tree directly Signed-off-by: Rob Herring <robh@kernel.org>
272 lines
5.2 KiB
C
272 lines
5.2 KiB
C
/*
|
|
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
|
|
*
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License as
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
* License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
* USA
|
|
*/
|
|
|
|
#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, int xlen)
|
|
{
|
|
struct data nd;
|
|
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 == -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 = xmalloc(sizeof(*m));
|
|
m->offset = d.len;
|
|
m->type = type;
|
|
m->ref = ref;
|
|
m->next = NULL;
|
|
|
|
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;
|
|
}
|