From owner-svn-src-stable-11@freebsd.org Fri Feb 21 04:34:58 2020 Return-Path: Delivered-To: svn-src-stable-11@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 03706251375; Fri, 21 Feb 2020 04:34:58 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48NzC55FsGz4C6f; Fri, 21 Feb 2020 04:34:55 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 91EAF54D3; Fri, 21 Feb 2020 04:34:55 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 01L4YtSX068714; Fri, 21 Feb 2020 04:34:55 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 01L4Yt7n068711; Fri, 21 Feb 2020 04:34:55 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <202002210434.01L4Yt7n068711@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Fri, 21 Feb 2020 04:34:55 +0000 (UTC) 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 X-SVN-Group: stable-11 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: in stable: 11/usr.bin/dtc 12/usr.bin/dtc X-SVN-Commit-Revision: 358205 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Feb 2020 04:34:58 -0000 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_ptr;