Remove banner printing code from bootloaders, add it to libsa.
This harmonizes efiboot and the various x86 bootloaders to use shared code for printing the banner. By friendly coincidence, it also adds support for specifying 'banner=' in arm efiboot's boot.cfg, as on x86.
This commit is contained in:
parent
77f5ecb001
commit
b7fed38c88
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: boot2.c,v 1.77 2021/06/21 19:52:17 nia Exp $ */
|
||||
/* $NetBSD: boot2.c,v 1.78 2021/09/07 11:41:31 nia Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
|
||||
|
@ -121,7 +121,6 @@ static const char *default_part_name;
|
|||
|
||||
char *sprint_bootsel(const char *);
|
||||
static void bootit(const char *, int);
|
||||
void print_banner(void);
|
||||
void boot2(int, uint64_t);
|
||||
|
||||
void command_help(char *);
|
||||
|
@ -298,35 +297,6 @@ bootit(const char *filename, int howto)
|
|||
printf("boot returned\n");
|
||||
}
|
||||
|
||||
void
|
||||
print_banner(void)
|
||||
{
|
||||
|
||||
clearit();
|
||||
#ifndef SMALL
|
||||
int n;
|
||||
if (bootcfg_info.banner[0]) {
|
||||
for (n = 0; n < BOOTCFG_MAXBANNER && bootcfg_info.banner[n];
|
||||
n++)
|
||||
printf("%s\n", bootcfg_info.banner[n]);
|
||||
} else {
|
||||
#endif /* !SMALL */
|
||||
printf("\n"
|
||||
" \\-__,------,___.\n"
|
||||
" \\ __,---` %s (from NetBSD %s)\n"
|
||||
" \\ `---,_. Revision %s\n"
|
||||
" \\-,_____,.---` Memory: %d/%d k\n"
|
||||
" \\\n"
|
||||
" \\\n"
|
||||
" \\\n",
|
||||
bootprog_name, bootprog_kernrev,
|
||||
bootprog_rev,
|
||||
getbasemem(), getextmem());
|
||||
#ifndef SMALL
|
||||
}
|
||||
#endif /* !SMALL */
|
||||
}
|
||||
|
||||
/*
|
||||
* Called from the initial entry point boot_start in biosboot.S
|
||||
*
|
||||
|
@ -379,10 +349,12 @@ boot2(int biosdev, uint64_t biossector)
|
|||
* If console set in boot.cfg, switch to it.
|
||||
* This will print the banner, so we don't need to explicitly do it
|
||||
*/
|
||||
if (bootcfg_info.consdev)
|
||||
if (bootcfg_info.consdev) {
|
||||
command_consdev(bootcfg_info.consdev);
|
||||
else
|
||||
print_banner();
|
||||
} else {
|
||||
clearit();
|
||||
print_bootcfg_banner(bootprog_name, bootprog_rev);
|
||||
}
|
||||
|
||||
/* Display the menu, if applicable */
|
||||
twiddle_toggle = 0;
|
||||
|
@ -393,7 +365,8 @@ boot2(int biosdev, uint64_t biossector)
|
|||
|
||||
#else
|
||||
twiddle_toggle = 0;
|
||||
print_banner();
|
||||
clearit();
|
||||
print_bootcfg_banner(bootprog_name, bootprog_rev);
|
||||
#endif
|
||||
|
||||
printf("Press return to boot now, any other key for boot menu\n");
|
||||
|
@ -616,7 +589,8 @@ command_consdev(char *arg)
|
|||
}
|
||||
|
||||
initio(cdp->tag);
|
||||
print_banner();
|
||||
clearit();
|
||||
print_bootcfg_banner(bootprog_name, bootprog_rev);
|
||||
return;
|
||||
}
|
||||
error:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: boot.c,v 1.19 2021/06/22 19:53:58 nia Exp $ */
|
||||
/* $NetBSD: boot.c,v 1.20 2021/09/07 11:41:31 nia Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2016 Kimihiro Nonaka <nonaka@netbsd.org>
|
||||
|
@ -277,31 +277,6 @@ bootit(const char *filename, int howto)
|
|||
printf("boot returned\n");
|
||||
}
|
||||
|
||||
void
|
||||
print_banner(void)
|
||||
{
|
||||
int n;
|
||||
|
||||
clearit();
|
||||
if (bootcfg_info.banner[0]) {
|
||||
for (n = 0; n < BOOTCFG_MAXBANNER && bootcfg_info.banner[n];
|
||||
n++)
|
||||
printf("%s\n", bootcfg_info.banner[n]);
|
||||
} else {
|
||||
printf("\n"
|
||||
" \\-__,------,___.\n"
|
||||
" \\ __,---` %s (from NetBSD %s)\n"
|
||||
" \\ `---,_. Revision %s\n"
|
||||
" \\-,_____,.---` Memory: %d/%d k\n"
|
||||
" \\\n"
|
||||
" \\\n"
|
||||
" \\\n",
|
||||
bootprog_name, bootprog_kernrev,
|
||||
bootprog_rev,
|
||||
getbasemem(), getextmem());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
boot(void)
|
||||
{
|
||||
|
@ -344,10 +319,12 @@ boot(void)
|
|||
* If console set in boot.cfg, switch to it.
|
||||
* This will print the banner, so we don't need to explicitly do it
|
||||
*/
|
||||
if (bootcfg_info.consdev)
|
||||
if (bootcfg_info.consdev) {
|
||||
command_consdev(bootcfg_info.consdev);
|
||||
else
|
||||
print_banner();
|
||||
} else {
|
||||
clearit();
|
||||
print_bootcfg_banner(bootprog_name, bootprog_rev);
|
||||
}
|
||||
|
||||
/* Display the menu, if applicable */
|
||||
twiddle_toggle = 0;
|
||||
|
@ -602,7 +579,8 @@ command_consdev(char *arg)
|
|||
}
|
||||
}
|
||||
efi_consinit(cdp->tag, ioport, speed);
|
||||
print_banner();
|
||||
clearit();
|
||||
print_bootcfg_banner(bootprog_name, bootprog_rev);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: efiboot.h,v 1.10 2019/09/13 02:19:45 manu Exp $ */
|
||||
/* $NetBSD: efiboot.h,v 1.11 2021/09/07 11:41:31 nia Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2016 Kimihiro Nonaka <nonaka@netbsd.org>
|
||||
|
@ -41,7 +41,6 @@ extern EFI_GUID GraphicsOutputProtocol;
|
|||
/* boot.c */
|
||||
void boot(void);
|
||||
void clearit(void);
|
||||
void print_banner(void);
|
||||
|
||||
/* efiboot.c */
|
||||
extern EFI_HANDLE IH;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: main.c,v 1.31 2014/06/28 09:16:18 rtr Exp $ */
|
||||
/* $NetBSD: main.c,v 1.32 2021/09/07 11:41:32 nia Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996
|
||||
|
@ -106,20 +106,6 @@ bootit(const char *filename, int howto)
|
|||
return (-1);
|
||||
}
|
||||
|
||||
static void
|
||||
print_banner(void)
|
||||
{
|
||||
int base = getbasemem();
|
||||
int ext = getextmem();
|
||||
|
||||
clearit();
|
||||
printf("\n"
|
||||
">> NetBSD/x86 PXE boot, Revision %s (from NetBSD %s)\n"
|
||||
">> Memory: %d/%d k\n",
|
||||
bootprog_rev, bootprog_kernrev,
|
||||
base, ext);
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
@ -148,10 +134,12 @@ main(void)
|
|||
* If console set in boot.cfg, switch to it.
|
||||
* This will print the banner, so we don't need to explicitly do it
|
||||
*/
|
||||
if (bootcfg_info.consdev)
|
||||
if (bootcfg_info.consdev) {
|
||||
command_consdev(bootcfg_info.consdev);
|
||||
else
|
||||
print_banner();
|
||||
} else {
|
||||
clearit();
|
||||
print_bootcfg_banner(bootprog_name, bootprog_rev);
|
||||
}
|
||||
|
||||
/* Display the menu, if applicable */
|
||||
twiddle_toggle = 0;
|
||||
|
@ -161,7 +149,8 @@ main(void)
|
|||
}
|
||||
#else
|
||||
twiddle_toggle = 0;
|
||||
print_banner();
|
||||
clearit();
|
||||
print_bootcfg_banner(bootprog_name, bootprog_rev);
|
||||
#endif
|
||||
|
||||
printf("Press return to boot now, any other key for boot menu\n");
|
||||
|
@ -254,7 +243,8 @@ command_consdev(char *arg)
|
|||
for (cdp = cons_devs; cdp->name; cdp++) {
|
||||
if (!strcmp(arg, cdp->name)) {
|
||||
initio(cdp->tag);
|
||||
print_banner();
|
||||
clearit();
|
||||
print_bootcfg_banner(bootprog_name, bootprog_rev);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: bootcfg.c,v 1.6 2021/05/30 05:59:23 mlelstv Exp $ */
|
||||
/* $NetBSD: bootcfg.c,v 1.7 2021/09/07 11:41:31 nia Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2008 The NetBSD Foundation, Inc.
|
||||
|
@ -278,3 +278,26 @@ perform_bootcfg(const char *conf, bootcfg_command command, const off_t maxsz)
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
print_bootcfg_banner(const char *bootprog_name, const char *bootprog_rev)
|
||||
{
|
||||
int n = 0;
|
||||
|
||||
if (bootcfg_info.banner[0]) {
|
||||
for (; n < BOOTCFG_MAXBANNER && bootcfg_info.banner[n]; n++)
|
||||
printf("%s\n", bootcfg_info.banner[n]);
|
||||
return;
|
||||
}
|
||||
|
||||
/* If the user has not specified a banner, print a default one. */
|
||||
|
||||
printf("\n");
|
||||
printf(" \\\\-__,------,___.\n");
|
||||
printf(" \\\\ __,---` %s\n", bootprog_name);
|
||||
printf(" \\\\ `---,_. Revision %s\n", bootprog_rev);
|
||||
printf(" \\\\-,_____,.---`\n");
|
||||
printf(" \\\\\n");
|
||||
printf(" \\\\\n");
|
||||
printf(" \\\\\n\n");
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: bootcfg.h,v 1.4 2021/05/30 05:59:23 mlelstv Exp $ */
|
||||
/* $NetBSD: bootcfg.h,v 1.5 2021/09/07 11:41:31 nia Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2008 The NetBSD Foundation, Inc.
|
||||
|
@ -54,5 +54,6 @@ extern struct bootcfg_def bootcfg_info;
|
|||
|
||||
int perform_bootcfg(const char *, bootcfg_command, const off_t);
|
||||
void bootcfg_do_noop(const char *, char *);
|
||||
void print_bootcfg_banner(const char *, const char *);
|
||||
|
||||
#endif /* !_BOOTCFG_H */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: boot.c,v 1.35 2021/07/24 10:22:28 jmcneill Exp $ */
|
||||
/* $NetBSD: boot.c,v 1.36 2021/09/07 11:41:31 nia Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2016 Kimihiro Nonaka <nonaka@netbsd.org>
|
||||
|
@ -451,61 +451,6 @@ set_bootargs(const char *arg)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
get_memory_info(uint64_t *ptotal)
|
||||
{
|
||||
EFI_MEMORY_DESCRIPTOR *md, *memmap;
|
||||
UINTN nentries, mapkey, descsize;
|
||||
UINT32 descver;
|
||||
uint64_t totalpg = 0;
|
||||
int n;
|
||||
|
||||
memmap = LibMemoryMap(&nentries, &mapkey, &descsize, &descver);
|
||||
for (n = 0, md = memmap; n < nentries; n++, md = NextMemoryDescriptor(md, descsize)) {
|
||||
if ((md->Attribute & EFI_MEMORY_WB) == 0) {
|
||||
continue;
|
||||
}
|
||||
totalpg += md->NumberOfPages;
|
||||
}
|
||||
|
||||
*ptotal = totalpg * EFI_PAGE_SIZE;
|
||||
}
|
||||
|
||||
static void
|
||||
format_bytes(uint64_t val, uint64_t *pdiv, const char **punit)
|
||||
{
|
||||
static const char *units[] = { "KB", "MB", "GB" };
|
||||
unsigned n;
|
||||
|
||||
*punit = "bytes";
|
||||
*pdiv = 1;
|
||||
|
||||
for (n = 0; n < __arraycount(units) && val >= 1024 * 10; n++) {
|
||||
*punit = units[n];
|
||||
*pdiv *= 1024;
|
||||
val /= 1024;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
print_banner(void)
|
||||
{
|
||||
const char *total_unit;
|
||||
uint64_t total, total_div;
|
||||
|
||||
get_memory_info(&total);
|
||||
format_bytes(total, &total_div, &total_unit);
|
||||
|
||||
printf(" \\-__,------,___.\n");
|
||||
printf(" \\ __,---` %s\n", bootprog_name);
|
||||
printf(" \\ `---,_. Revision %s\n", bootprog_rev);
|
||||
printf(" \\-,_____,.---` Memory: %" PRIu64 " %s\n",
|
||||
total / total_div, total_unit);
|
||||
printf(" \\\n");
|
||||
printf(" \\\n");
|
||||
printf(" \\\n\n");
|
||||
}
|
||||
|
||||
void
|
||||
boot(void)
|
||||
{
|
||||
|
@ -520,7 +465,7 @@ boot(void)
|
|||
if (bootcfg_info.clear)
|
||||
uefi_call_wrapper(ST->ConOut->ClearScreen, 1, ST->ConOut);
|
||||
|
||||
print_banner();
|
||||
print_bootcfg_banner(bootprog_name, bootprog_rev);
|
||||
|
||||
/* Display menu if configured */
|
||||
if (bootcfg_info.nummenu > 0) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: efiboot.h,v 1.15 2021/06/20 19:10:47 jmcneill Exp $ */
|
||||
/* $NetBSD: efiboot.h,v 1.16 2021/09/07 11:41:31 nia Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2016 Kimihiro Nonaka <nonaka@netbsd.org>
|
||||
|
@ -51,7 +51,6 @@ extern struct fs_ops nfs_fs_ops;
|
|||
/* boot.c */
|
||||
void boot(void);
|
||||
void clearit(void);
|
||||
void print_banner(void);
|
||||
extern const struct boot_command commands[];
|
||||
void command_help(char *);
|
||||
int set_default_device(const char *);
|
||||
|
|
Loading…
Reference in New Issue