Changeset View
Standalone View
sys/kern/bootmethod.c
- This file was added.
/* | |||||
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD | |||||
* | |||||
* Copyright (c) 2021 Elliott Mitchell | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | |||||
* modification, are permitted provided that the following conditions | |||||
* are met: | |||||
* 1. Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* 2. Redistributions in binary form must reproduce the above copyright | |||||
* notice, this list of conditions and the following disclaimer in the | |||||
* documentation and/or other materials provided with the distribution. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | |||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
* SUCH DAMAGE. | |||||
*/ | |||||
#include <sys/cdefs.h> | |||||
__FBSDID("$FreeBSD$"); | |||||
#include <sys/types.h> /* for u_* for atomic.h, for systm.h */ | |||||
#include <sys/param.h> /* for MAXPATHLEN for kernel.h */ | |||||
#include <sys/kernel.h> | |||||
#include <sys/systm.h> | |||||
#include <sys/sysctl.h> | |||||
enum firmware_types firmware_type = FW_NONE; | |||||
static char bootmethod[16]; | |||||
SYSCTL_STRING(_machdep, OID_AUTO, bootmethod, CTLFLAG_RD, bootmethod, 0, | |||||
kib: If you change bootmethod from array to pointer, you would not need strlcpy() in sysinit. Also… | |||||
Done Inline ActionsBased on what Clang complained about when trying this, I'm pretty sure SYSCTL_STRING() needs a fixed address so a pointer doesn't work. I would have preferred this approach, but if it was setup in a way which makes this impossible. ehem_freebsd_m5p.com: Based on what Clang complained about when trying this, I'm pretty sure SYSCTL_STRING() needs a… | |||||
"System firmware boot method"); | |||||
/* | |||||
* Set the sysctl bootmethod for compatibility | |||||
*/ | |||||
static void set_bootmethod(const void *unused __unused) | |||||
{ | |||||
const char *const types[] = { | |||||
[FW_NONE] = "unknown", | |||||
Done Inline ActionsThis needs to be static kib: This needs to be static | |||||
Done Inline ActionsOkay (marking as done, though Phabricator may not be immediately updated). ehem_freebsd_m5p.com: Okay (marking as done, though Phabricator may not be immediately updated). | |||||
[FW_UEFI] = "UEFI", | |||||
[FW_BIOS] = "BIOS", | |||||
[FW_LINUXABI] = "LinuxABI", | |||||
}; | |||||
const char *val = "other"; | |||||
if (firmware_type < nitems(types) && types[firmware_type] != NULL) | |||||
Not Done Inline ActionsInitialize bootmethod with "other" kib: Initialize bootmethod with "other" | |||||
val = types[firmware_type]; | |||||
strlcpy(bootmethod, val, sizeof(bootmethod)); | |||||
Not Done Inline ActionsThis part is not needed I believe. At most you could MPASS(firmware_type < nitems(types)). kib: This part is not needed I believe. At most you could `MPASS(firmware_type < nitems(types))`. | |||||
Done Inline ActionsOriginally I wasn't expecting the list to be exhaustive and wanted to allow for empty entries. Of the current list though, clearly I've got them all, so perhaps that should be gotten rid of. ehem_freebsd_m5p.com: Originally I wasn't expecting the list to be exhaustive and wanted to allow for empty entries. | |||||
} | |||||
C_SYSINIT(set_bootmethod, SI_SUB_LAST, SI_ORDER_SECOND, set_bootmethod, NULL); | |||||
Not Done Inline ActionsThis simply does not deserve a dedicated file. kib: This simply does not deserve a dedicated file. | |||||
Done Inline ActionsThat doesn't surprise me, but I was unsure of where to place this. Advice on where you think it should be placed would be appreciated. ehem_freebsd_m5p.com: That doesn't surprise me, but I was unsure of where to place this. Advice on where you think… | |||||
Not Done Inline ActionsMost obvious place is kern/subr_param.c kib: Most obvious place is kern/subr_param.c |
If you change bootmethod from array to pointer, you would not need strlcpy() in sysinit. Also you can pre-init it with "other":