mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-21 11:56:58 +07: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>
248 lines
7.0 KiB
C
248 lines
7.0 KiB
C
/*
|
|
* (C) Copyright Linaro, Ltd. 2018
|
|
* (C) Copyright Arm Holdings. 2017
|
|
* (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 <stdlib.h>
|
|
#include <yaml.h>
|
|
#include "dtc.h"
|
|
#include "srcpos.h"
|
|
|
|
char *yaml_error_name[] = {
|
|
[YAML_NO_ERROR] = "no error",
|
|
[YAML_MEMORY_ERROR] = "memory error",
|
|
[YAML_READER_ERROR] = "reader error",
|
|
[YAML_SCANNER_ERROR] = "scanner error",
|
|
[YAML_PARSER_ERROR] = "parser error",
|
|
[YAML_COMPOSER_ERROR] = "composer error",
|
|
[YAML_WRITER_ERROR] = "writer error",
|
|
[YAML_EMITTER_ERROR] = "emitter error",
|
|
};
|
|
|
|
#define yaml_emitter_emit_or_die(emitter, event) ( \
|
|
{ \
|
|
if (!yaml_emitter_emit(emitter, event)) \
|
|
die("yaml '%s': %s in %s, line %i\n", \
|
|
yaml_error_name[(emitter)->error], \
|
|
(emitter)->problem, __func__, __LINE__); \
|
|
})
|
|
|
|
static void yaml_propval_int(yaml_emitter_t *emitter, struct marker *markers, char *data, int len, int width)
|
|
{
|
|
yaml_event_t event;
|
|
void *tag;
|
|
int off, start_offset = markers->offset;
|
|
|
|
switch(width) {
|
|
case 1: tag = "!u8"; break;
|
|
case 2: tag = "!u16"; break;
|
|
case 4: tag = "!u32"; break;
|
|
case 8: tag = "!u64"; break;
|
|
default:
|
|
die("Invalid width %i", width);
|
|
}
|
|
assert(len % width == 0);
|
|
|
|
yaml_sequence_start_event_initialize(&event, NULL,
|
|
(yaml_char_t *)tag, width == 4, YAML_FLOW_SEQUENCE_STYLE);
|
|
yaml_emitter_emit_or_die(emitter, &event);
|
|
|
|
for (off = 0; off < len; off += width) {
|
|
char buf[32];
|
|
struct marker *m;
|
|
bool is_phandle = false;
|
|
|
|
switch(width) {
|
|
case 1:
|
|
sprintf(buf, "0x%"PRIx8, *(uint8_t*)(data + off));
|
|
break;
|
|
case 2:
|
|
sprintf(buf, "0x%"PRIx16, fdt16_to_cpu(*(fdt16_t*)(data + off)));
|
|
break;
|
|
case 4:
|
|
sprintf(buf, "0x%"PRIx32, fdt32_to_cpu(*(fdt32_t*)(data + off)));
|
|
m = markers;
|
|
is_phandle = false;
|
|
for_each_marker_of_type(m, REF_PHANDLE) {
|
|
if (m->offset == (start_offset + off)) {
|
|
is_phandle = true;
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
case 8:
|
|
sprintf(buf, "0x%"PRIx64, fdt64_to_cpu(*(fdt64_t*)(data + off)));
|
|
break;
|
|
}
|
|
|
|
if (is_phandle)
|
|
yaml_scalar_event_initialize(&event, NULL,
|
|
(yaml_char_t*)"!phandle", (yaml_char_t *)buf,
|
|
strlen(buf), 0, 0, YAML_PLAIN_SCALAR_STYLE);
|
|
else
|
|
yaml_scalar_event_initialize(&event, NULL,
|
|
(yaml_char_t*)YAML_INT_TAG, (yaml_char_t *)buf,
|
|
strlen(buf), 1, 1, YAML_PLAIN_SCALAR_STYLE);
|
|
yaml_emitter_emit_or_die(emitter, &event);
|
|
}
|
|
|
|
yaml_sequence_end_event_initialize(&event);
|
|
yaml_emitter_emit_or_die(emitter, &event);
|
|
}
|
|
|
|
static void yaml_propval_string(yaml_emitter_t *emitter, char *str, int len)
|
|
{
|
|
yaml_event_t event;
|
|
int i;
|
|
|
|
assert(str[len-1] == '\0');
|
|
|
|
/* Make sure the entire string is in the lower 7-bit ascii range */
|
|
for (i = 0; i < len; i++)
|
|
assert(isascii(str[i]));
|
|
|
|
yaml_scalar_event_initialize(&event, NULL,
|
|
(yaml_char_t *)YAML_STR_TAG, (yaml_char_t*)str,
|
|
len-1, 0, 1, YAML_DOUBLE_QUOTED_SCALAR_STYLE);
|
|
yaml_emitter_emit_or_die(emitter, &event);
|
|
}
|
|
|
|
static void yaml_propval(yaml_emitter_t *emitter, struct property *prop)
|
|
{
|
|
yaml_event_t event;
|
|
int len = prop->val.len;
|
|
struct marker *m = prop->val.markers;
|
|
|
|
/* Emit the property name */
|
|
yaml_scalar_event_initialize(&event, NULL,
|
|
(yaml_char_t *)YAML_STR_TAG, (yaml_char_t*)prop->name,
|
|
strlen(prop->name), 1, 1, YAML_PLAIN_SCALAR_STYLE);
|
|
yaml_emitter_emit_or_die(emitter, &event);
|
|
|
|
/* Boolean properties are easiest to deal with. Length is zero, so just emit 'true' */
|
|
if (len == 0) {
|
|
yaml_scalar_event_initialize(&event, NULL,
|
|
(yaml_char_t *)YAML_BOOL_TAG,
|
|
(yaml_char_t*)"true",
|
|
strlen("true"), 1, 0, YAML_PLAIN_SCALAR_STYLE);
|
|
yaml_emitter_emit_or_die(emitter, &event);
|
|
return;
|
|
}
|
|
|
|
if (!m)
|
|
die("No markers present in property '%s' value\n", prop->name);
|
|
|
|
yaml_sequence_start_event_initialize(&event, NULL,
|
|
(yaml_char_t *)YAML_SEQ_TAG, 1, YAML_FLOW_SEQUENCE_STYLE);
|
|
yaml_emitter_emit_or_die(emitter, &event);
|
|
|
|
for_each_marker(m) {
|
|
int chunk_len;
|
|
char *data = &prop->val.val[m->offset];
|
|
|
|
if (m->type < TYPE_UINT8)
|
|
continue;
|
|
|
|
chunk_len = type_marker_length(m) ? : len;
|
|
assert(chunk_len > 0);
|
|
len -= chunk_len;
|
|
|
|
switch(m->type) {
|
|
case TYPE_UINT16:
|
|
yaml_propval_int(emitter, m, data, chunk_len, 2);
|
|
break;
|
|
case TYPE_UINT32:
|
|
yaml_propval_int(emitter, m, data, chunk_len, 4);
|
|
break;
|
|
case TYPE_UINT64:
|
|
yaml_propval_int(emitter, m, data, chunk_len, 8);
|
|
break;
|
|
case TYPE_STRING:
|
|
yaml_propval_string(emitter, data, chunk_len);
|
|
break;
|
|
default:
|
|
yaml_propval_int(emitter, m, data, chunk_len, 1);
|
|
break;
|
|
}
|
|
}
|
|
|
|
yaml_sequence_end_event_initialize(&event);
|
|
yaml_emitter_emit_or_die(emitter, &event);
|
|
}
|
|
|
|
|
|
static void yaml_tree(struct node *tree, yaml_emitter_t *emitter)
|
|
{
|
|
struct property *prop;
|
|
struct node *child;
|
|
yaml_event_t event;
|
|
|
|
if (tree->deleted)
|
|
return;
|
|
|
|
yaml_mapping_start_event_initialize(&event, NULL,
|
|
(yaml_char_t *)YAML_MAP_TAG, 1, YAML_ANY_MAPPING_STYLE);
|
|
yaml_emitter_emit_or_die(emitter, &event);
|
|
|
|
for_each_property(tree, prop)
|
|
yaml_propval(emitter, prop);
|
|
|
|
/* Loop over all the children, emitting them into the map */
|
|
for_each_child(tree, child) {
|
|
yaml_scalar_event_initialize(&event, NULL,
|
|
(yaml_char_t *)YAML_STR_TAG, (yaml_char_t*)child->name,
|
|
strlen(child->name), 1, 0, YAML_PLAIN_SCALAR_STYLE);
|
|
yaml_emitter_emit_or_die(emitter, &event);
|
|
yaml_tree(child, emitter);
|
|
}
|
|
|
|
yaml_mapping_end_event_initialize(&event);
|
|
yaml_emitter_emit_or_die(emitter, &event);
|
|
}
|
|
|
|
void dt_to_yaml(FILE *f, struct dt_info *dti)
|
|
{
|
|
yaml_emitter_t emitter;
|
|
yaml_event_t event;
|
|
|
|
yaml_emitter_initialize(&emitter);
|
|
yaml_emitter_set_output_file(&emitter, f);
|
|
yaml_stream_start_event_initialize(&event, YAML_UTF8_ENCODING);
|
|
yaml_emitter_emit_or_die(&emitter, &event);
|
|
|
|
yaml_document_start_event_initialize(&event, NULL, NULL, NULL, 0);
|
|
yaml_emitter_emit_or_die(&emitter, &event);
|
|
|
|
yaml_sequence_start_event_initialize(&event, NULL, (yaml_char_t *)YAML_SEQ_TAG, 1, YAML_ANY_SEQUENCE_STYLE);
|
|
yaml_emitter_emit_or_die(&emitter, &event);
|
|
|
|
yaml_tree(dti->dt, &emitter);
|
|
|
|
yaml_sequence_end_event_initialize(&event);
|
|
yaml_emitter_emit_or_die(&emitter, &event);
|
|
|
|
yaml_document_end_event_initialize(&event, 0);
|
|
yaml_emitter_emit_or_die(&emitter, &event);
|
|
|
|
yaml_stream_end_event_initialize(&event);
|
|
yaml_emitter_emit_or_die(&emitter, &event);
|
|
|
|
yaml_emitter_delete(&emitter);
|
|
}
|