From nobody Sun Feb 13 20:46:14 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 479A2194E2DB; Sun, 13 Feb 2022 20:46:15 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JxfX71QCMz3GPY; Sun, 13 Feb 2022 20:46:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644785175; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Wk7Hi8KNBQntPVIorToVG5ntEkXJC+kRcgCedVdTYos=; b=AmnjMioDJmSCOLeO/o5TrhU1QuR+Ohl0qTqqppfWZvP3Jx3C78nmV8dfHNLVirJHI6Zvi8 Vvt5TeM8VnxGcPeG7YJxdkU9FfU3rPOJZ/06YfbnH5uU+UAZZ6Q72EOiEp47tYaWOgYfhU /VrR3hia73WqknK+mK8xwiceajkypT86OttcRtzIaaTDVaA5BL7KnOBpXgxLErKpoyV6w3 8eSFnP8lr0qA1MJNHW+mwgz1dwkLN7GG4/BQOy0ReIIhiLUuqDYwf7bfxnhrXwawV0bsKz wK8a9GvPfKaXL/HDF7mHpaj8Sw752dY8MvomyXO09WH6FkUNid8qY1wEmM0IfQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 0FC7B21ECB; Sun, 13 Feb 2022 20:46:15 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 21DKkEBx089533; Sun, 13 Feb 2022 20:46:14 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21DKkEBg089532; Sun, 13 Feb 2022 20:46:14 GMT (envelope-from git) Date: Sun, 13 Feb 2022 20:46:14 GMT Message-Id: <202202132046.21DKkEBg089532@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Simon J. Gerraty" Subject: git: ec042f46e9bb - main - Add support for module_verbose List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: sjg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ec042f46e9bbd195e1f7c8151df5d280a2a4d069 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644785175; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Wk7Hi8KNBQntPVIorToVG5ntEkXJC+kRcgCedVdTYos=; b=S6i+3iBO3xHMkB7/qVlqN2BXjPx1cAtLrHEKQz97AICrdGdvw32vZa0aSQVmFUwvLMNnzM c2eMSN78Sl8outSoBiR8mwiLhy5E6sFs0UVHf4iU4/gH1suVBbszgjXvahqW6fIR66JYB6 ROeQ7yyeepekW3RGkk7YbW0T+Tc/fzgxd+L0jNezDnjMBy9uF9y2qFitweyFizhM7IrczF Svs+Hw+SEIrChDVQkwZhtqMaZdCpQLrI/SutSGu63ba6+Cru3/z7gpN4K6P/GGbCMika+6 8Czkz4b5TDUUt8NbBrmBFT6WMwhDaURJgmu7OhQeE7xOhRxvJ2+iSEkKUPsI5w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1644785175; a=rsa-sha256; cv=none; b=v1x6pzZJOGDau1VBQ+E1iFjXB2UnEGt3jrqPZfCoNTMVactjD4EqSgx67IVeF+0aFAw0wR XbdtsqX8C1LTae0NQN6Adx6d9cKyRWC4mzBw2hstkJKnjdU0MfSUtah2hfOF3kz3SUs599 vCLIqQp4mSzMXJmwGSJDNUXKZA5D2dEVXr5f7xXPdu4sEwLzxi4wX5MSFhV5qsKEv+VZyE QCTvpaHEOArmLTMchmfswz4FJ3qwwKoJs1ZpzqPYqfS3ig4bDDiJGiR9MfNtTNLBV8nAjE mOf0eP6pbMWFU0kdzXG2DnffLWu7s25+fv6gtbJniifgpSSmylN+TVn9LjG/ow== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by sjg: URL: https://cgit.FreeBSD.org/src/commit/?id=ec042f46e9bbd195e1f7c8151df5d280a2a4d069 commit ec042f46e9bbd195e1f7c8151df5d280a2a4d069 Author: Simon J. Gerraty AuthorDate: 2022-02-13 20:45:57 +0000 Commit: Simon J. Gerraty CommitDate: 2022-02-13 20:45:57 +0000 Add support for module_verbose Set module_verbose to control the printing of information about loaded modules and kernel: 0 MODULE_VERBOSE_SILENT None 1 MODULE_VERBOSE_SIZE Pathname and size 2 MODULE_VERBOSE_TWIDDLE as for 1 but also twiddle for progress 3 MODULE_VERBOSE_FULL extra detail When the loader is verifying modules we already have a running indication of progress and module_verbose=0 makes sense. Reviewed by: rpokala Differential Revision: https://reviews.freebsd.org/D34245 --- stand/common/bootstrap.h | 8 ++++ stand/common/console.c | 29 ++++++++++- stand/common/load_elf.c | 114 ++++++++++++++++++++++---------------------- stand/common/load_elf_obj.c | 9 ++-- 4 files changed, 98 insertions(+), 62 deletions(-) diff --git a/stand/common/bootstrap.h b/stand/common/bootstrap.h index 42b2c73f5774..9c62a49b0da7 100644 --- a/stand/common/bootstrap.h +++ b/stand/common/bootstrap.h @@ -124,6 +124,14 @@ void cons_probe(void); bool cons_update_mode(bool); void autoload_font(bool); +extern int module_verbose; +enum { + MODULE_VERBOSE_SILENT, /* say nothing */ + MODULE_VERBOSE_SIZE, /* print name and size */ + MODULE_VERBOSE_TWIDDLE, /* show progress */ + MODULE_VERBOSE_FULL, /* all we have */ +}; + /* * Plug-and-play enumerator/configurator interface. */ diff --git a/stand/common/console.c b/stand/common/console.c index ff864276f96c..08d0dc40e3a9 100644 --- a/stand/common/console.c +++ b/stand/common/console.c @@ -41,6 +41,28 @@ static int cons_check(const char *string); static int cons_change(const char *string); static int twiddle_set(struct env_var *ev, int flags, const void *value); +#ifndef MODULE_VERBOSE +# define MODULE_VERBOSE MODULE_VERBOSE_TWIDDLE +#endif +int module_verbose = MODULE_VERBOSE; + +static int +module_verbose_set(struct env_var *ev, int flags, const void *value) +{ + u_long v; + char *eptr; + + v = strtoul(value, &eptr, 0); + if (*(const char *)value == 0 || *eptr != 0) { + printf("invalid module_verbose '%s'\n", (const char *)value); + return (CMD_ERROR); + } + module_verbose = (int)v; + env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL); + + return (CMD_OK); +} + /* * Detect possible console(s) to use. If preferred console(s) have been * specified, mark them as active. Else, mark the first probed console @@ -52,10 +74,15 @@ cons_probe(void) int cons; int active; char *prefconsole; + char module_verbose_buf[8]; TSENTER(); - /* We want a callback to install the new value when this var changes. */ + /* We want a callback to install the new value when these vars change. */ + snprintf(module_verbose_buf, sizeof(module_verbose_buf), "%d", + module_verbose); + env_setenv("module_verbose", EV_VOLATILE, module_verbose_buf, + module_verbose_set, env_nounset); env_setenv("twiddle_divisor", EV_VOLATILE, "16", twiddle_set, env_nounset); diff --git a/stand/common/load_elf.c b/stand/common/load_elf.c index 8cbbe54b49d4..62df96aa2ebc 100644 --- a/stand/common/load_elf.c +++ b/stand/common/load_elf.c @@ -463,13 +463,17 @@ __elfN(loadfile_raw)(char *filename, uint64_t dest, else fp->f_type = strdup("elf multiboot kernel"); -#ifdef ELF_VERBOSE - if (ef.kernel) - printf("%s entry at 0x%jx\n", filename, - (uintmax_t)ehdr->e_entry); -#else - printf("%s ", filename); -#endif + if (module_verbose >= MODULE_VERBOSE_FULL) { + if (ef.kernel) + printf("%s entry at 0x%jx\n", filename, + (uintmax_t)ehdr->e_entry); + } else if (module_verbose > MODULE_VERBOSE_SILENT) + printf("%s ", filename); + + if (module_verbose < MODULE_VERBOSE_TWIDDLE) { + /* A hack for now; we do not want twiddling */ + twiddle_divisor(UINT_MAX); + } fp->f_size = __elfN(loadimage)(fp, &ef, dest); if (fp->f_size == 0 || fp->f_addr == 0) @@ -580,9 +584,10 @@ __elfN(loadimage)(struct preloaded_file *fp, elf_file_t ef, uint64_t off) off += 0x01000000; } ehdr->e_entry += off; -#ifdef ELF_VERBOSE - printf("Converted entry 0x%jx\n", (uintmax_t)ehdr->e_entry); -#endif + if (module_verbose >= MODULE_VERBOSE_FULL) + printf("Converted entry 0x%jx\n", + (uintmax_t)ehdr->e_entry); + #elif defined(__arm__) && !defined(EFI) /* * The elf headers in arm kernels specify virtual addresses in @@ -604,10 +609,9 @@ __elfN(loadimage)(struct preloaded_file *fp, elf_file_t ef, uint64_t off) */ off -= ehdr->e_entry & ~PAGE_MASK; ehdr->e_entry += off; -#ifdef ELF_VERBOSE - printf("ehdr->e_entry 0x%jx, va<->pa off %llx\n", - (uintmax_t)ehdr->e_entry, off); -#endif + if (module_verbose >= MODULE_VERBOSE_FULL) + printf("ehdr->e_entry 0x%jx, va<->pa off %llx\n", + (uintmax_t)ehdr->e_entry, off); #else off = 0; /* other archs use direct mapped kernels */ #endif @@ -632,22 +636,22 @@ __elfN(loadimage)(struct preloaded_file *fp, elf_file_t ef, uint64_t off) if (phdr[i].p_type != PT_LOAD) continue; -#ifdef ELF_VERBOSE - printf("Segment: 0x%lx@0x%lx -> 0x%lx-0x%lx", - (long)phdr[i].p_filesz, (long)phdr[i].p_offset, - (long)(phdr[i].p_vaddr + off), - (long)(phdr[i].p_vaddr + off + phdr[i].p_memsz - 1)); -#else - if ((phdr[i].p_flags & PF_W) == 0) { - printf("text=0x%lx ", (long)phdr[i].p_filesz); - } else { - printf("data=0x%lx", (long)phdr[i].p_filesz); - if (phdr[i].p_filesz < phdr[i].p_memsz) - printf("+0x%lx", (long)(phdr[i].p_memsz - - phdr[i].p_filesz)); - printf(" "); + if (module_verbose >= MODULE_VERBOSE_FULL) { + printf("Segment: 0x%lx@0x%lx -> 0x%lx-0x%lx", + (long)phdr[i].p_filesz, (long)phdr[i].p_offset, + (long)(phdr[i].p_vaddr + off), + (long)(phdr[i].p_vaddr + off + phdr[i].p_memsz - 1)); + } else if (module_verbose > MODULE_VERBOSE_SILENT) { + if ((phdr[i].p_flags & PF_W) == 0) { + printf("text=0x%lx ", (long)phdr[i].p_filesz); + } else { + printf("data=0x%lx", (long)phdr[i].p_filesz); + if (phdr[i].p_filesz < phdr[i].p_memsz) + printf("+0x%lx", (long)(phdr[i].p_memsz - + phdr[i].p_filesz)); + printf(" "); + } } -#endif fpcopy = 0; if (ef->firstlen > phdr[i].p_offset) { fpcopy = ef->firstlen - phdr[i].p_offset; @@ -666,18 +670,16 @@ __elfN(loadimage)(struct preloaded_file *fp, elf_file_t ef, uint64_t off) } /* clear space from oversized segments; eg: bss */ if (phdr[i].p_filesz < phdr[i].p_memsz) { -#ifdef ELF_VERBOSE - printf(" (bss: 0x%lx-0x%lx)", - (long)(phdr[i].p_vaddr + off + phdr[i].p_filesz), - (long)(phdr[i].p_vaddr + off + phdr[i].p_memsz -1)); -#endif - + if (module_verbose >= MODULE_VERBOSE_FULL) { + printf(" (bss: 0x%lx-0x%lx)", + (long)(phdr[i].p_vaddr + off + phdr[i].p_filesz), + (long)(phdr[i].p_vaddr + off + phdr[i].p_memsz -1)); + } kern_bzero(phdr[i].p_vaddr + off + phdr[i].p_filesz, phdr[i].p_memsz - phdr[i].p_filesz); } -#ifdef ELF_VERBOSE - printf("\n"); -#endif + if (module_verbose >= MODULE_VERBOSE_FULL) + printf("\n"); if (archsw.arch_loadseg != NULL) archsw.arch_loadseg(ehdr, phdr + i, off); @@ -767,12 +769,10 @@ __elfN(loadimage)(struct preloaded_file *fp, elf_file_t ef, uint64_t off) goto nosyms; /* Ok, committed to a load. */ -#ifndef ELF_VERBOSE - printf("syms=["); -#endif + if (module_verbose >= MODULE_VERBOSE_FULL) + printf("syms=["); ssym = lastaddr; for (i = symtabindex; i >= 0; i = symstrindex) { -#ifdef ELF_VERBOSE char *secname; switch(shdr[i].sh_type) { @@ -786,23 +786,21 @@ __elfN(loadimage)(struct preloaded_file *fp, elf_file_t ef, uint64_t off) secname = "WHOA!!"; break; } -#endif size = shdr[i].sh_size; archsw.arch_copyin(&size, lastaddr, sizeof(size)); lastaddr += sizeof(size); -#ifdef ELF_VERBOSE - printf("\n%s: 0x%jx@0x%jx -> 0x%jx-0x%jx", secname, - (uintmax_t)shdr[i].sh_size, (uintmax_t)shdr[i].sh_offset, - (uintmax_t)lastaddr, - (uintmax_t)(lastaddr + shdr[i].sh_size)); -#else - if (i == symstrindex) - printf("+"); - printf("0x%lx+0x%lx", (long)sizeof(size), (long)size); -#endif - + if (module_verbose >= MODULE_VERBOSE_FULL) { + printf("\n%s: 0x%jx@0x%jx -> 0x%jx-0x%jx", secname, + (uintmax_t)shdr[i].sh_size, (uintmax_t)shdr[i].sh_offset, + (uintmax_t)lastaddr, + (uintmax_t)(lastaddr + shdr[i].sh_size)); + } else if (module_verbose > MODULE_VERBOSE_SILENT) { + if (i == symstrindex) + printf("+"); + printf("0x%lx+0x%lx", (long)sizeof(size), (long)size); + } if (VECTX_LSEEK(VECTX_HANDLE(ef), (off_t)shdr[i].sh_offset, SEEK_SET) == -1) { printf("\nelf" __XSTRING(__ELF_WORD_SIZE) "_loadimage: could not seek for symbols - skipped!"); @@ -829,15 +827,15 @@ __elfN(loadimage)(struct preloaded_file *fp, elf_file_t ef, uint64_t off) symstrindex = -1; } esym = lastaddr; -#ifndef ELF_VERBOSE - printf("]"); -#endif + if (module_verbose >= MODULE_VERBOSE_FULL) + printf("]"); file_addmetadata(fp, MODINFOMD_SSYM, sizeof(ssym), &ssym); file_addmetadata(fp, MODINFOMD_ESYM, sizeof(esym), &esym); nosyms: - printf("\n"); + if (module_verbose > MODULE_VERBOSE_SILENT) + printf("\n"); ret = lastaddr - firstaddr; fp->f_addr = firstaddr; diff --git a/stand/common/load_elf_obj.c b/stand/common/load_elf_obj.c index f3c84cf31368..ed202e08b780 100644 --- a/stand/common/load_elf_obj.c +++ b/stand/common/load_elf_obj.c @@ -184,7 +184,8 @@ __elfN(obj_loadfile)(char *filename, uint64_t dest, fp->f_name = strdup(filename); fp->f_type = strdup(__elfN(obj_moduletype)); - printf("%s ", filename); + if (module_verbose > MODULE_VERBOSE_SILENT) + printf("%s ", filename); fp->f_size = __elfN(obj_loadimage)(fp, &ef, dest); if (fp->f_size == 0 || fp->f_addr == 0) @@ -378,10 +379,12 @@ __elfN(obj_loadimage)(struct preloaded_file *fp, elf_file_t ef, uint64_t off) ret = lastaddr - firstaddr; fp->f_addr = firstaddr; - printf("size 0x%lx at 0x%lx", (u_long)ret, (u_long)firstaddr); + if (module_verbose > MODULE_VERBOSE_SILENT) + printf("size 0x%lx at 0x%lx", (u_long)ret, (u_long)firstaddr); out: - printf("\n"); + if (module_verbose > MODULE_VERBOSE_SILENT) + printf("\n"); return ret; }