summaryrefslogtreecommitdiff
path: root/usr.bin/dtc
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2020-02-14 18:46:34 +0000
committerKyle Evans <kevans@FreeBSD.org>2020-02-14 18:46:34 +0000
commitaac4229aac3b59dedd160793faf21e18cf85bdfc (patch)
treefe2bd9d2a7e7371c035e27d8e49f350726d6bce9 /usr.bin/dtc
parent4c3ccd967e6b9a6c157bd38410bdccd098bdb9e1 (diff)
downloadsrc-test-aac4229aac3b59dedd160793faf21e18cf85bdfc.tar.gz
src-test-aac4229aac3b59dedd160793faf21e18cf85bdfc.zip
Pull in latest fixes from dtc, up to 0060471
This includes a small battery of /memreserve/ fixes to make sure dtc is properly writing these regions into the output file and reading them back out. As of this update, dtc will now also assume common defaults for -I/-O if only one is specified; namely, dts for one implies dtb for the other and vice versa (Requested by: jhibbits, preserves GPL dtc behavior too). MFC after: 1 week
Notes
Notes: svn path=/head/; revision=357923
Diffstat (limited to 'usr.bin/dtc')
-rw-r--r--usr.bin/dtc/dtb.cc1
-rw-r--r--usr.bin/dtc/dtc.cc22
-rw-r--r--usr.bin/dtc/fdt.cc20
-rw-r--r--usr.bin/dtc/fdt.hh8
4 files changed, 42 insertions, 9 deletions
diff --git a/usr.bin/dtc/dtb.cc b/usr.bin/dtc/dtb.cc
index 6346d63cc0afe..d7aecba028003 100644
--- a/usr.bin/dtc/dtb.cc
+++ b/usr.bin/dtc/dtb.cc
@@ -36,7 +36,6 @@
#include <sys/types.h>
#include <inttypes.h>
#include <stdio.h>
-#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
diff --git a/usr.bin/dtc/dtc.cc b/usr.bin/dtc/dtc.cc
index b9423f4868159..0cda698011efa 100644
--- a/usr.bin/dtc/dtc.cc
+++ b/usr.bin/dtc/dtc.cc
@@ -94,6 +94,8 @@ void version(const char* progname)
} // Anonymous namespace
using fdt::device_tree;
+using fdt::tree_write_fn_ptr;
+using fdt::tree_read_fn_ptr;
int
main(int argc, char **argv)
@@ -104,8 +106,8 @@ main(int argc, char **argv)
const char *in_file = "-";
FILE *depfile = 0;
bool debug_mode = false;
- auto write_fn = &device_tree::write_binary;
- auto read_fn = &device_tree::parse_dts;
+ tree_write_fn_ptr write_fn = nullptr;
+ tree_read_fn_ptr read_fn = nullptr;
uint32_t boot_cpu = 0;
bool boot_cpu_specified = false;
bool keep_going = false;
@@ -135,6 +137,10 @@ main(int argc, char **argv)
if (arg == "dtb")
{
read_fn = &device_tree::parse_dtb;
+ if (write_fn == nullptr)
+ {
+ write_fn = &device_tree::write_dts;
+ }
}
else if (arg == "dts")
{
@@ -161,6 +167,10 @@ main(int argc, char **argv)
else if (arg == "dts")
{
write_fn = &device_tree::write_dts;
+ if (read_fn == nullptr)
+ {
+ read_fn = &device_tree::parse_dtb;
+ }
}
else
{
@@ -298,6 +308,14 @@ main(int argc, char **argv)
return EXIT_FAILURE;
}
}
+ if (read_fn == nullptr)
+ {
+ read_fn = &device_tree::parse_dts;
+ }
+ if (write_fn == nullptr)
+ {
+ write_fn = &device_tree::write_binary;
+ }
if (optind < argc)
{
in_file = argv[optind];
diff --git a/usr.bin/dtc/fdt.cc b/usr.bin/dtc/fdt.cc
index 606493e3521be..494604e191df7 100644
--- a/usr.bin/dtc/fdt.cc
+++ b/usr.bin/dtc/fdt.cc
@@ -1563,11 +1563,11 @@ device_tree::parse_file(text_input_buffer &input,
{
input.next_token();
// Read the header
- while (input.consume("/dts-v1/;"))
+ if (input.consume("/dts-v1/;"))
{
read_header = true;
- input.next_token();
}
+ input.next_token();
if (input.consume("/plugin/;"))
{
is_plugin = true;
@@ -1589,9 +1589,12 @@ device_tree::parse_file(text_input_buffer &input,
{
input.parse_error("Expected size on /memreserve/ node.");
}
+ else
+ {
+ reservations.push_back(reservation(start, len));
+ }
input.next_token();
input.consume(';');
- reservations.push_back(reservation(start, len));
input.next_token();
}
while (valid && !input.finished())
@@ -1661,7 +1664,7 @@ device_tree::write(int fd)
reservation_writer.write_comment(string("Reservation start"));
reservation_writer.write_data(i.first);
reservation_writer.write_comment(string("Reservation length"));
- reservation_writer.write_data(i.first);
+ reservation_writer.write_data(i.second);
}
// Write n spare reserve map entries, plus the trailing 0.
for (uint32_t i=0 ; i<=spare_reserve_map_entries ; i++)
@@ -1747,10 +1750,11 @@ device_tree::write_dts(int fd)
if (!reservations.empty())
{
const char msg[] = "/memreserve/";
- fwrite(msg, sizeof(msg), 1, file);
+ // Exclude the null byte when we're writing it out to the file.
+ fwrite(msg, sizeof(msg) - 1, 1, file);
for (auto &i : reservations)
{
- fprintf(file, " %" PRIx64 " %" PRIx64, i.first, i.second);
+ fprintf(file, " 0x%" PRIx64 " 0x%" PRIx64, i.first, i.second);
}
fputs(";\n\n", file);
}
@@ -1794,6 +1798,10 @@ device_tree::parse_dtb(const string &fn, FILE *)
valid = false;
return;
}
+ if (start != 0 || length != 0)
+ {
+ reservations.push_back(reservation(start, length));
+ }
} while (!((start == 0) && (length == 0)));
input_buffer struct_table =
input.buffer_from_offset(h.off_dt_struct, h.size_dt_struct);
diff --git a/usr.bin/dtc/fdt.hh b/usr.bin/dtc/fdt.hh
index 86c0dcede5e4f..6c737cc83e3ee 100644
--- a/usr.bin/dtc/fdt.hh
+++ b/usr.bin/dtc/fdt.hh
@@ -59,6 +59,14 @@ class property;
class node;
class device_tree;
/**
+ * Type for device tree write functions.
+ */
+typedef void (device_tree::* tree_write_fn_ptr)(int);
+/**
+ * Type for device tree read functions.
+ */
+typedef void (device_tree::* tree_read_fn_ptr)(const std::string &, FILE *);
+/**
* Type for (owned) pointers to properties.
*/
typedef std::shared_ptr<property> property_ptr;