// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 2013, Google Inc.
* Written by Simon Glass <sjg@chromium.org>
*
* Perform a grep of an FDT either displaying the source subset or producing
* a new .dtb subset which can be used as required.
*/
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <getopt.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "fdt_host.h"
#include "libfdt_internal.h"
/* Define DEBUG to get some debugging output on stderr */
#ifdef DEBUG
#define debug(a, b...) fprintf(stderr, a, ## b)
#else
#define debug(a, b...)
#endif
/* A linked list of values we are grepping for */
struct value_node {
int type; /* Types this value matches (FDT_IS... mask) */
int include; /* 1 to include matches, 0 to exclude */
const char *string; /* String to match */
struct value_node *next; /* Pointer to next node, or NULL */
};
/* Output formats we support */
enum output_t {
OUT_DTS, /* Device tree source */
OUT_DTB, /* Valid device tree binary */
OUT_BIN, /* Fragment of .dtb, for hashing */
};
/* Holds information which controls our output and options */
struct display_info {
enum output_t output; /* Output format */
int add_aliases; /* Add aliases node to output */
int all; /* Display all properties/nodes */
int colour; /* Display output in ANSI colour */
int region_list; /* Output a region list */
int flags; /* Flags (FDT_REG_...) */
int list_strings; /* List strings in string table */
int show_offset; /* Show offset */
int show_addr; /* Show address */
int header; /* Output an FDT header */
int diff; /* Show +/- diff markers */
int include_root; /* Include the root node and all properties */
int remove_strings; /* Remove unused strings */
int show_dts_version; /* Put '/dts-v1/;' on the first line */
int types_inc; /* Mask of types that we include (FDT_IS...) */
int types_exc; /* Mask of types that we exclude (FDT_IS...) */
int invert; /* Invert polarity of match */
struct value_node *value_head; /* List of values to match */
const char *output_fname; /* Output filename */
FILE *fout; /* File to write dts/dtb output */
};
static void report_error(const char *where, int err)
{
fprintf(stderr, "Error at '%s': %s\n", where, fdt_strerror(err));
}
/* Supported ANSI colours */
enum {
COL_BLACK,
COL_RED,
COL_GREEN,
COL_YELLOW,
COL_BLUE,
COL_MAGENTA,
COL_CYAN,
COL_WHITE,
COL_NONE = -1,
};
/**
* print_ansi_colour() - Print out the ANSI sequence for a colour
*
* @fout: Output file
|