svn commit: r357923 - head/usr.bin/dtc

Kyle Evans kevans at FreeBSD.org
Fri Feb 14 18:46:35 UTC 2020


Author: kevans
Date: Fri Feb 14 18:46:34 2020
New Revision: 357923
URL: https://svnweb.freebsd.org/changeset/base/357923

Log:
  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

Modified:
  head/usr.bin/dtc/dtb.cc
  head/usr.bin/dtc/dtc.cc
  head/usr.bin/dtc/fdt.cc
  head/usr.bin/dtc/fdt.hh

Modified: head/usr.bin/dtc/dtb.cc
==============================================================================
--- head/usr.bin/dtc/dtb.cc	Fri Feb 14 17:05:35 2020	(r357922)
+++ head/usr.bin/dtc/dtb.cc	Fri Feb 14 18:46:34 2020	(r357923)
@@ -36,7 +36,6 @@
 #include <sys/types.h>
 #include <inttypes.h>
 #include <stdio.h>
-#include <stdlib.h>
 #include <unistd.h>
 #include <errno.h>
 

Modified: head/usr.bin/dtc/dtc.cc
==============================================================================
--- head/usr.bin/dtc/dtc.cc	Fri Feb 14 17:05:35 2020	(r357922)
+++ head/usr.bin/dtc/dtc.cc	Fri Feb 14 18:46:34 2020	(r357923)
@@ -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
 			{
@@ -297,6 +307,14 @@ main(int argc, char **argv)
 			fprintf(stderr, "Unknown option %c\n", ch);
 			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)
 	{

Modified: head/usr.bin/dtc/fdt.cc
==============================================================================
--- head/usr.bin/dtc/fdt.cc	Fri Feb 14 17:05:35 2020	(r357922)
+++ head/usr.bin/dtc/fdt.cc	Fri Feb 14 18:46:34 2020	(r357923)
@@ -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);
 	}
@@ -1793,6 +1797,10 @@ device_tree::parse_dtb(const string &fn, FILE *)
 			fprintf(stderr, "Failed to read memory reservation table\n");
 			valid = false;
 			return;
+		}
+		if (start != 0 || length != 0)
+		{
+			reservations.push_back(reservation(start, length));
 		}
 	} while (!((start == 0) && (length == 0)));
 	input_buffer struct_table =

Modified: head/usr.bin/dtc/fdt.hh
==============================================================================
--- head/usr.bin/dtc/fdt.hh	Fri Feb 14 17:05:35 2020	(r357922)
+++ head/usr.bin/dtc/fdt.hh	Fri Feb 14 18:46:34 2020	(r357923)
@@ -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;


More information about the svn-src-head mailing list