Date: Fri, 21 Feb 2020 04:34:55 +0000 (UTC) From: Kyle Evans <kevans@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r358205 - in stable: 11/usr.bin/dtc 12/usr.bin/dtc Message-ID: <202002210434.01L4Yt7n068711@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kevans Date: Fri Feb 21 04:34:54 2020 New Revision: 358205 URL: https://svnweb.freebsd.org/changeset/base/358205 Log: MFC r357923-r357924: dtc fixes for /memreserve/ and -I/-O defaults r357923: 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). r357924: dtc: re-apply r353961, r354115 I missed in final review of r357923's diff that these ones hadn't yet been sent upstream and inadvertently reverted them. =-( Re-apply now. Modified: stable/11/usr.bin/dtc/dtc.cc stable/11/usr.bin/dtc/fdt.cc stable/11/usr.bin/dtc/fdt.hh Directory Properties: stable/11/ (props changed) Changes in other areas also in this revision: Modified: stable/12/usr.bin/dtc/dtc.cc stable/12/usr.bin/dtc/fdt.cc stable/12/usr.bin/dtc/fdt.hh Directory Properties: stable/12/ (props changed) Modified: stable/11/usr.bin/dtc/dtc.cc ============================================================================== --- stable/11/usr.bin/dtc/dtc.cc Fri Feb 21 04:33:14 2020 (r358204) +++ stable/11/usr.bin/dtc/dtc.cc Fri Feb 21 04:34:54 2020 (r358205) @@ -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: stable/11/usr.bin/dtc/fdt.cc ============================================================================== --- stable/11/usr.bin/dtc/fdt.cc Fri Feb 21 04:33:14 2020 (r358204) +++ stable/11/usr.bin/dtc/fdt.cc Fri Feb 21 04:34:54 2020 (r358205) @@ -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: stable/11/usr.bin/dtc/fdt.hh ============================================================================== --- stable/11/usr.bin/dtc/fdt.hh Fri Feb 21 04:33:14 2020 (r358204) +++ stable/11/usr.bin/dtc/fdt.hh Fri Feb 21 04:34:54 2020 (r358205) @@ -58,6 +58,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;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202002210434.01L4Yt7n068711>