From owner-svn-src-all@freebsd.org Thu Jan 16 03:11:27 2020 Return-Path: Delivered-To: svn-src-all@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 5DD61226F40; Thu, 16 Jan 2020 03:11:27 +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 47yq3M1vnWz4MQh; Thu, 16 Jan 2020 03:11:27 +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 3B0ED18DEC; Thu, 16 Jan 2020 03:11:27 +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 00G3BRNx077862; Thu, 16 Jan 2020 03:11:27 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 00G3BQwI077860; Thu, 16 Jan 2020 03:11:26 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <202001160311.00G3BQwI077860@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Thu, 16 Jan 2020 03:11:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r356771 - in stable: 11/stand/fdt 11/stand/uboot/fdt 12/stand/fdt 12/stand/uboot/fdt X-SVN-Group: stable-12 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: in stable: 11/stand/fdt 11/stand/uboot/fdt 12/stand/fdt 12/stand/uboot/fdt X-SVN-Commit-Revision: 356771 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Jan 2020 03:11:27 -0000 Author: kevans Date: Thu Jan 16 03:11:25 2020 New Revision: 356771 URL: https://svnweb.freebsd.org/changeset/base/356771 Log: MFC r356538: stand/fdt: Scale blob size better as overlays apply Currently, our overlay blob will grow to include the size of the complete overlay blob we're applying. This doesn't scale very well with a lot of overlays- they tend to include a lot of overhead, and they will generally only add a fraction of their total size to the blob they're being applied to. To combat this, pack the blob as we apply new overlays and keep track of how many overlays we've applied. Only ubldr has any fixups to be applied after overlays, so we only need to re-pad the blob in ubldr. Presumably the allocation won't fail since we just did a lot worse in trying to apply overlays and succeeded. I have no intention of removing the padding in make_dtb.sh. There might be an argument to be had over whether it should be configurable, since ubldr *is* the only loader that actually has fixups to be applied and we can do this at runtime, but I'm not too concerned about this. This diff has been sitting in Phabricator for a year and a half, but I've decided to flush it as it does make sure that we're scaling the blob appropriately and leave room at the end for fixups in case of some freak circumstance where applying overlays leaves us with a blob of insufficient size. Modified: stable/12/stand/fdt/fdt_loader_cmd.c stable/12/stand/fdt/fdt_platform.h stable/12/stand/uboot/fdt/uboot_fdt.c Directory Properties: stable/12/ (props changed) Changes in other areas also in this revision: Modified: stable/11/stand/fdt/fdt_loader_cmd.c stable/11/stand/fdt/fdt_platform.h stable/11/stand/uboot/fdt/uboot_fdt.c Directory Properties: stable/11/ (props changed) Modified: stable/12/stand/fdt/fdt_loader_cmd.c ============================================================================== --- stable/12/stand/fdt/fdt_loader_cmd.c Thu Jan 16 01:13:32 2020 (r356770) +++ stable/12/stand/fdt/fdt_loader_cmd.c Thu Jan 16 03:11:25 2020 (r356771) @@ -427,7 +427,10 @@ fdt_check_overlay_compatible(void *base_fdt, void *ove return (1); } -void +/* + * Returns the number of overlays successfully applied + */ +int fdt_apply_overlays() { struct preloaded_file *fp; @@ -436,13 +439,13 @@ fdt_apply_overlays() void *current_fdtp; void *next_fdtp; void *overlay; - int rv; + int overlays_applied, rv; if ((fdtp == NULL) || (fdtp_size == 0)) - return; + return (0); if (fdt_overlays_applied) - return; + return (0); max_overlay_size = 0; for (fp = file_findfile(NULL, "dtbo"); fp != NULL; fp = fp->f_next) { @@ -452,15 +455,16 @@ fdt_apply_overlays() /* Nothing to apply */ if (max_overlay_size == 0) - return; + return (0); overlay = malloc(max_overlay_size); if (overlay == NULL) { printf("failed to allocate memory for DTB blob with overlays\n"); - return; + return (0); } current_fdtp = fdtp; current_fdtp_size = fdtp_size; + overlays_applied = 0; for (fp = file_findfile(NULL, "dtbo"); fp != NULL; fp = fp->f_next) { COPYOUT(fp->f_addr, overlay, fp->f_size); /* Check compatible first to avoid unnecessary allocation */ @@ -493,7 +497,9 @@ fdt_apply_overlays() if (current_fdtp != fdtp) free(current_fdtp); current_fdtp = next_fdtp; - current_fdtp_size = next_fdtp_size; + fdt_pack(current_fdtp); + current_fdtp_size = fdt_totalsize(current_fdtp); + overlays_applied++; } else { /* * Assume here that the base we tried to apply on is @@ -513,6 +519,26 @@ fdt_apply_overlays() } free(overlay); fdt_overlays_applied = 1; + return (overlays_applied); +} + +int +fdt_pad_dtb(size_t padding) +{ + void *padded_fdtp; + size_t padded_fdtp_size; + + padded_fdtp_size = fdtp_size + padding; + padded_fdtp = malloc(padded_fdtp_size); + if (padded_fdtp == NULL) + return (1); + if (fdt_open_into(fdtp, padded_fdtp, padded_fdtp_size) != 0) { + free(padded_fdtp); + return (1); + } + fdtp = padded_fdtp; + fdtp_size = padded_fdtp_size; + return (0); } int Modified: stable/12/stand/fdt/fdt_platform.h ============================================================================== --- stable/12/stand/fdt/fdt_platform.h Thu Jan 16 01:13:32 2020 (r356770) +++ stable/12/stand/fdt/fdt_platform.h Thu Jan 16 03:11:25 2020 (r356771) @@ -43,7 +43,8 @@ void fdt_fixup_cpubusfreqs(unsigned long, unsigned lon void fdt_fixup_ethernet(const char *, char *, int); void fdt_fixup_memory(struct fdt_mem_region *, size_t); void fdt_fixup_stdout(const char *); -void fdt_apply_overlays(void); +int fdt_apply_overlays(void); +int fdt_pad_dtb(size_t); int fdt_load_dtb_addr(struct fdt_header *); int fdt_load_dtb_file(const char *); void fdt_load_dtb_overlays(const char *); Modified: stable/12/stand/uboot/fdt/uboot_fdt.c ============================================================================== --- stable/12/stand/uboot/fdt/uboot_fdt.c Thu Jan 16 01:13:32 2020 (r356770) +++ stable/12/stand/uboot/fdt/uboot_fdt.c Thu Jan 16 03:11:25 2020 (r356771) @@ -63,6 +63,8 @@ fdt_platform_load_from_ubenv(const char *var) return (1); } +#define FDT_DTB_PADSZ 1024 + int fdt_platform_load_dtb(void) { @@ -127,7 +129,8 @@ fdt_platform_fixups(void) ethstr = NULL; /* Apply overlays before anything else */ - fdt_apply_overlays(); + if (fdt_apply_overlays() > 0) + fdt_pad_dtb(FDT_DTB_PADSZ); /* Acquire sys_info */ si = ub_get_sys_info();