Changeset View
Standalone View
sys/boot/efi/boot1/boot1.c
Context not available. | |||||
* All rights reserved. | * All rights reserved. | ||||
* Copyright (c) 2014 Nathan Whitehorn | * Copyright (c) 2014 Nathan Whitehorn | ||||
* All rights reserved. | * All rights reserved. | ||||
* Copyright (c) 2015 Eric McCorkle | |||||
* All rights reverved. | |||||
* | * | ||||
* Redistribution and use in source and binary forms are freely | * Redistribution and use in source and binary forms are freely | ||||
* permitted provided that the above copyright notice and this | * permitted provided that the above copyright notice and this | ||||
Context not available. | |||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/dirent.h> | |||||
#include <machine/elf.h> | #include <machine/elf.h> | ||||
#include <machine/stdarg.h> | #include <machine/stdarg.h> | ||||
Context not available. | |||||
#include <efi.h> | #include <efi.h> | ||||
#include <eficonsctl.h> | #include <eficonsctl.h> | ||||
#include "boot_module.h" | |||||
#define _PATH_LOADER "/boot/loader.efi" | #define _PATH_LOADER "/boot/loader.efi" | ||||
#define _PATH_KERNEL "/boot/kernel/kernel" | #define _PATH_KERNEL "/boot/kernel/kernel" | ||||
Context not available. | |||||
u_int sp_size; | u_int sp_size; | ||||
}; | }; | ||||
static const boot_module_t* const boot_modules[] = | |||||
{ | |||||
#ifdef ZFS_EFI_BOOT | |||||
&zfs_module, | |||||
#endif | |||||
#ifdef UFS_EFI_BOOT | |||||
&ufs_module | |||||
#endif | |||||
}; | |||||
#define NUM_BOOT_MODULES (sizeof(boot_modules) / sizeof(boot_module_t*)) | |||||
static const char digits[] = "0123456789abcdef"; | static const char digits[] = "0123456789abcdef"; | ||||
static void panic(const char *fmt, ...) __dead2; | |||||
static int printf(const char *fmt, ...); | |||||
static int putchar(char c, void *arg); | |||||
static int vprintf(const char *fmt, va_list ap); | |||||
static int vsnprintf(char *str, size_t sz, const char *fmt, va_list ap); | |||||
static int __printf(const char *fmt, putc_func_t *putc, void *arg, va_list ap); | static int __printf(const char *fmt, putc_func_t *putc, void *arg, va_list ap); | ||||
static int __putc(char c, void *arg); | static int __putc(char c, void *arg); | ||||
static int __puts(const char *s, putc_func_t *putc, void *arg); | static int __puts(const char *s, putc_func_t *putc, void *arg); | ||||
Context not available. | |||||
static int domount(EFI_DEVICE_PATH *device, EFI_BLOCK_IO *blkio, int quiet); | static int domount(EFI_DEVICE_PATH *device, EFI_BLOCK_IO *blkio, int quiet); | ||||
static void load(const char *fname); | static void load(const char *fname); | ||||
static void try_load(const boot_module_t* mod, const dev_info_t devs[], | |||||
size_t ndevs); | |||||
static EFI_SYSTEM_TABLE *systab; | static EFI_SYSTEM_TABLE *systab; | ||||
static EFI_HANDLE *image; | static EFI_HANDLE *image; | ||||
delphij: There are many style(9) violations in the following section, please consider fixing them before… | |||||
static void | void* | ||||
Malloc(size_t len, const char *file, int line) | |||||
{ | |||||
void* out; | |||||
if (systab->BootServices->AllocatePool(EfiLoaderData, | |||||
len, &out) != | |||||
EFI_SUCCESS) { | |||||
printf("Can't allocate memory pool\n"); | |||||
return NULL; | |||||
} | |||||
return out; | |||||
andrewUnsubmitted Not Done Inline ActionsReturn values should be enclosed in parentheses, i.e. return (out); (and similar for other return statements). andrew: Return values should be enclosed in parentheses, i.e. `return (out);` (and similar for other… | |||||
} | |||||
char* | |||||
strcpy(char *dst, const char *src) { | |||||
int i; | |||||
for(i = 0; src[i]; i++) | |||||
dst[i] = src[i]; | |||||
return dst; | |||||
Done Inline ActionsCan we just use the libc version of strchr instead of introducing yet another new strchr implementation? delphij: Can we just use the libc version of strchr instead of introducing yet another new strchr… | |||||
Not Done Inline ActionsThe issue here is that this is EFI ABI code. Therefore, it has to be compiled with a different set of compiler flags. I don't think linking against libc will actually work because of that. eric_metricspace.net: The issue here is that this is EFI ABI code. Therefore, it has to be compiled with a different… | |||||
delphijUnsubmitted Not Done Inline ActionsNo, I mean perhaps we can either add ${SRCTOP}/lib/libc/string/strcpy.c or #include it? delphij: No, I mean perhaps we can either add ${SRCTOP}/lib/libc/string/strcpy.c or #include it? | |||||
} | |||||
char* | |||||
strchr(const char *s, int c) { | |||||
int i; | |||||
for(i = 0; s[i]; i++) | |||||
if (s[i] == c) | |||||
return (char*)(s + i); | |||||
Done Inline ActionsSame here. delphij: Same here. | |||||
return NULL; | |||||
} | |||||
int | |||||
strncmp(const char *a, const char *b, size_t len) | |||||
{ | |||||
int i; | |||||
for (i = 0; i < len; i++) | |||||
if(a[i] == '\0' && b[i] == '\0') { | |||||
return 0; | |||||
} else if(a[i] < b[i]) { | |||||
return -1; | |||||
} else if(a[i] > b[i]) { | |||||
return 1; | |||||
} | |||||
Done Inline ActionsCan we make this a strlen()? delphij: Can we make this a strlen()? | |||||
return 0; | |||||
} | |||||
size_t | |||||
strlen(const char *s) { | |||||
size_t len = 0; | |||||
for(; *s != '\0'; s++, len++); | |||||
Done Inline ActionsThis looks like it is not doing what it is supposed to do. If it passed a string that does where the first byte is not 0 it would loop forever... alvisen_gmail.com: This looks like it is not doing what it is supposed to do. If it passed a string that does… | |||||
return len; | |||||
Done Inline ActionsSince there is an alias for this (memcmp), I would suggest just use memcmp and remove this one. delphij: Since there is an alias for this (memcmp), I would suggest just use memcmp and remove this one. | |||||
eric_metricspace.netAuthorUnsubmitted Not Done Inline ActionsThe existence of bcmp is required by either the ZFS or UFS code. In general, the functions here are required by the filesystem code, and because of the aforementioned ABI issue, we can't just link against stdlib eric_metricspace.net: The existence of bcmp is required by either the ZFS or UFS code. In general, the functions… | |||||
} | |||||
char* | |||||
strdup(const char *s) { | |||||
const int len = strlen(s); | |||||
char* const out = malloc(len); | |||||
int i; | |||||
for(i = 0; i < len; i++) | |||||
out[i] = s[i]; | |||||
return out; | |||||
} | |||||
int | |||||
bcmp(const void *a, const void *b, size_t len) | |||||
{ | |||||
const char *sa = a; | |||||
const char *sb = b; | |||||
int i; | |||||
for (i = 0; i < len; i++) | |||||
if(sa[i] != sb[i]) | |||||
return 1; | |||||
return 0; | |||||
} | |||||
int | |||||
memcmp(const void *a, const void *b, size_t len) | |||||
{ | |||||
return bcmp(a, b, len); | |||||
} | |||||
void | |||||
bcopy(const void *src, void *dst, size_t len) | bcopy(const void *src, void *dst, size_t len) | ||||
{ | { | ||||
const char *s = src; | const char *s = src; | ||||
Context not available. | |||||
*d++ = *s++; | *d++ = *s++; | ||||
} | } | ||||
static void | void* | ||||
andrewUnsubmitted Not Done Inline ActionsMissing a space, i.e. this should be void *. andrew: Missing a space, i.e. this should be `void *`. | |||||
memcpy(void *dst, const void *src, size_t len) | memcpy(void *dst, const void *src, size_t len) | ||||
{ | { | ||||
bcopy(src, dst, len); | bcopy(src, dst, len); | ||||
return dst; | |||||
} | } | ||||
static void | void* | ||||
bzero(void *b, size_t len) | memset(void *b, int val, size_t len) | ||||
{ | { | ||||
char *p = b; | char *p = b; | ||||
while (len-- != 0) | while (len-- != 0) | ||||
*p++ = 0; | *p++ = val; | ||||
return b; | |||||
} | } | ||||
static int | int | ||||
strcmp(const char *s1, const char *s2) | strcmp(const char *s1, const char *s2) | ||||
{ | { | ||||
for (; *s1 == *s2 && *s1; s1++, s2++) | for (; *s1 == *s2 && *s1; s1++, s2++) | ||||
Context not available. | |||||
return ((u_char)*s1 - (u_char)*s2); | return ((u_char)*s1 - (u_char)*s2); | ||||
} | } | ||||
int | |||||
Done Inline ActionsI'd suggest some comment here describing that try_load would not return if load is succeeded. delphij: I'd suggest some comment here describing that try_load would not return if load is succeeded. | |||||
putchr(char c, void *arg) | |||||
{ | |||||
CHAR16 buf[2]; | |||||
if (c == '\n') { | |||||
buf[0] = '\r'; | |||||
buf[1] = 0; | |||||
systab->ConOut->OutputString(systab->ConOut, buf); | |||||
} | |||||
buf[0] = c; | |||||
buf[1] = 0; | |||||
Done Inline ActionsPlease use buffer == NULL. Modern compilers already have the ability to detect this kind of mistakes and doing so doesn't buy us much. delphij: Please use buffer == NULL. Modern compilers already have the ability to detect this kind of… | |||||
systab->ConOut->OutputString(systab->ConOut, buf); | |||||
return (1); | |||||
} | |||||
static EFI_GUID BlockIoProtocolGUID = BLOCK_IO_PROTOCOL; | static EFI_GUID BlockIoProtocolGUID = BLOCK_IO_PROTOCOL; | ||||
static EFI_GUID DevicePathGUID = DEVICE_PATH_PROTOCOL; | static EFI_GUID DevicePathGUID = DEVICE_PATH_PROTOCOL; | ||||
Done Inline ActionsWe'll want to clean these up -- either delete them if there's no value any longer, or make a DPRINTF macro or such. emaste: We'll want to clean these up -- either delete them if there's no value any longer, or make a… | |||||
static EFI_GUID LoadedImageGUID = LOADED_IMAGE_PROTOCOL; | static EFI_GUID LoadedImageGUID = LOADED_IMAGE_PROTOCOL; | ||||
static EFI_GUID ConsoleControlGUID = EFI_CONSOLE_CONTROL_PROTOCOL_GUID; | static EFI_GUID ConsoleControlGUID = EFI_CONSOLE_CONTROL_PROTOCOL_GUID; | ||||
static EFI_BLOCK_IO *bootdev; | #define MAX_DEVS 128 | ||||
static EFI_DEVICE_PATH *bootdevpath; | |||||
static EFI_HANDLE *bootdevhandle; | |||||
EFI_STATUS efi_main(EFI_HANDLE Ximage, EFI_SYSTEM_TABLE* Xsystab) | /* | ||||
* This function only returns if it fails to load the kernel. If it | |||||
* succeeds, it simply boots the kernel. | |||||
*/ | |||||
void | |||||
try_load(const boot_module_t* mod, const dev_info_t devs[], size_t ndevs) | |||||
{ | { | ||||
EFI_HANDLE handles[128]; | int idx; | ||||
size_t bufsize; | |||||
void* const buffer = mod->load(devs, ndevs, _PATH_LOADER, | |||||
&idx, &bufsize); | |||||
EFI_HANDLE loaderhandle; | |||||
EFI_LOADED_IMAGE *loaded_image; | |||||
if (buffer == NULL) { | |||||
printf("Could not load file\n"); | |||||
return; | |||||
} | |||||
if (systab->BootServices->LoadImage(TRUE, image, devs[idx].devpath, | |||||
buffer, bufsize, &loaderhandle) != | |||||
andrewUnsubmitted Not Done Inline ActionsThe second line should be indented 1 tab and 4 spaces. The EFI_SUCCESS) can then be moved to the same line. andrew: The second line should be indented 1 tab and 4 spaces. The `EFI_SUCCESS)` can then be moved to… | |||||
EFI_SUCCESS) | |||||
return; | |||||
if (systab->BootServices->HandleProtocol(loaderhandle, | |||||
&LoadedImageGUID, | |||||
(VOID**)&loaded_image) != | |||||
EFI_SUCCESS) | |||||
andrewUnsubmitted Not Done Inline ActionsDitto andrew: Ditto | |||||
return; | |||||
loaded_image->DeviceHandle = devs[idx].devhandle; | |||||
if (systab->BootServices->StartImage(loaderhandle, NULL, NULL) != | |||||
EFI_SUCCESS) | |||||
return; | |||||
} | |||||
void | |||||
efi_main(EFI_HANDLE Ximage, EFI_SYSTEM_TABLE *Xsystab) | |||||
{ | |||||
EFI_HANDLE handles[MAX_DEVS]; | |||||
dev_info_t module_devs[NUM_BOOT_MODULES][MAX_DEVS]; | |||||
size_t dev_offsets[NUM_BOOT_MODULES]; | |||||
EFI_BLOCK_IO *blkio; | EFI_BLOCK_IO *blkio; | ||||
UINTN i, nparts = sizeof(handles), cols, rows, max_dim, best_mode; | UINTN nparts = sizeof(handles); | ||||
Done Inline Actionsstyle(9) does not want variable declarations in for loops emaste: style(9) does not want variable declarations in for loops | |||||
EFI_STATUS status; | EFI_STATUS status; | ||||
EFI_DEVICE_PATH *devpath; | EFI_DEVICE_PATH *devpath; | ||||
Done Inline ActionsPlease change this to memset(). delphij: Please change this to memset(). | |||||
EFI_BOOT_SERVICES *BS; | EFI_BOOT_SERVICES *BS; | ||||
EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl = NULL; | EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl = NULL; | ||||
SIMPLE_TEXT_OUTPUT_INTERFACE *conout = NULL; | SIMPLE_TEXT_OUTPUT_INTERFACE *conout = NULL; | ||||
Done Inline Actionsstyle(9) wants /* */ comments emaste: style(9) wants `/* */` comments | |||||
char *path = _PATH_LOADER; | UINTN i; | ||||
UINTN j; | |||||
UINTN max_dim; | |||||
UINTN best_mode; | |||||
UINTN cols; | |||||
UINTN rows; | |||||
/* Basic initialization*/ | |||||
systab = Xsystab; | systab = Xsystab; | ||||
image = Ximage; | image = Ximage; | ||||
memset(dev_offsets, 0, NUM_BOOT_MODULES * sizeof(size_t)); | |||||
/* Set up the console, so printf works. */ | |||||
BS = systab->BootServices; | BS = systab->BootServices; | ||||
status = BS->LocateProtocol(&ConsoleControlGUID, NULL, | status = BS->LocateProtocol(&ConsoleControlGUID, NULL, | ||||
(VOID **)&ConsoleControl); | (VOID **)&ConsoleControl); | ||||
Done Inline ActionsThe printf should be conditionalized on UFS/ZFS being enabled, or more likely just leave it -- especially if there's per-module printfs below. emaste: The printf should be conditionalized on UFS/ZFS being enabled, or more likely just leave it… | |||||
Context not available. | |||||
Done Inline ActionsHere and at several other places the opening brace is placed on a new line. This violates FreeBSD style and is inconsistent with the nearby code. avg: Here and at several other places the opening brace is placed on a new line. This violates… | |||||
printf("\n" | printf("\n" | ||||
">> FreeBSD EFI boot block\n"); | ">> FreeBSD EFI boot block\n"); | ||||
printf(" Loader path: %s\n", path); | printf(" Loader path: %s\n\n", _PATH_LOADER); | ||||
printf(" Initializing modules:"); | |||||
for(i = 0; i < NUM_BOOT_MODULES; i++) { | |||||
if (NULL != boot_modules[i]) { | |||||
printf(" %s", boot_modules[i]->name); | |||||
boot_modules[i]->init(image, systab, BS); | |||||
} | |||||
} | |||||
putchr('\n', NULL); | |||||
/* Get all the device handles */ | |||||
status = systab->BootServices->LocateHandle(ByProtocol, | status = systab->BootServices->LocateHandle(ByProtocol, | ||||
&BlockIoProtocolGUID, NULL, &nparts, handles); | &BlockIoProtocolGUID, NULL, &nparts, handles); | ||||
nparts /= sizeof(handles[0]); | nparts /= sizeof(handles[0]); | ||||
/* Scan all partitions, probing with all modules. */ | |||||
for (i = 0; i < nparts; i++) { | for (i = 0; i < nparts; i++) { | ||||
dev_info_t devinfo; | |||||
/* Figure out if we're dealing with an actual partition. */ | |||||
status = systab->BootServices->HandleProtocol(handles[i], | status = systab->BootServices->HandleProtocol(handles[i], | ||||
&DevicePathGUID, (void **)&devpath); | &DevicePathGUID, (void **)&devpath); | ||||
if (EFI_ERROR(status)) | if (EFI_ERROR(status)) | ||||
Context not available. | |||||
if (!blkio->Media->LogicalPartition) | if (!blkio->Media->LogicalPartition) | ||||
continue; | continue; | ||||
/* Setup devinfo */ | |||||
devinfo.dev = blkio; | |||||
devinfo.devpath = devpath; | |||||
devinfo.devhandle = handles[i]; | |||||
devinfo.devdata = NULL; | |||||
if (domount(devpath, blkio, 1) >= 0) | /* Run through each module, see if it can load this partition */ | ||||
break; | for (j = 0; j < NUM_BOOT_MODULES; j++ ) { | ||||
if (NULL != boot_modules[j] && | |||||
boot_modules[j]->probe(&devinfo)) { | |||||
/* If it can, save it to the device list for | |||||
* that module. | |||||
*/ | |||||
module_devs[j][dev_offsets[j]++] = devinfo; | |||||
} | |||||
} | |||||
} | } | ||||
if (i == nparts) | /* | ||||
panic("No bootable partition found"); | * Select a partition to boot. We do this by trying each | ||||
* module in order. | |||||
*/ | |||||
for (i = 0; i < NUM_BOOT_MODULES; i++) | |||||
if (NULL != boot_modules[i]) | |||||
try_load(boot_modules[i], module_devs[i], | |||||
dev_offsets[i]); | |||||
bootdevhandle = handles[i]; | /* If we get here, we're out of luck... */ | ||||
load(path); | panic("No bootable partitions found!"); | ||||
panic("Load failed"); | |||||
return EFI_SUCCESS; | |||||
} | } | ||||
static int | void | ||||
dskread(void *buf, u_int64_t lba, int nblk) | |||||
{ | |||||
EFI_STATUS status; | |||||
int size; | |||||
lba = lba / (bootdev->Media->BlockSize / DEV_BSIZE); | |||||
size = nblk * DEV_BSIZE; | |||||
status = bootdev->ReadBlocks(bootdev, bootdev->Media->MediaId, lba, | |||||
size, buf); | |||||
if (EFI_ERROR(status)) | |||||
return (-1); | |||||
return (0); | |||||
} | |||||
#include "ufsread.c" | |||||
static ssize_t | |||||
fsstat(ufs_ino_t inode) | |||||
{ | |||||
#ifndef UFS2_ONLY | |||||
static struct ufs1_dinode dp1; | |||||
ufs1_daddr_t addr1; | |||||
#endif | |||||
#ifndef UFS1_ONLY | |||||
static struct ufs2_dinode dp2; | |||||
#endif | |||||
static struct fs fs; | |||||
static ufs_ino_t inomap; | |||||
char *blkbuf; | |||||
void *indbuf; | |||||
size_t n, nb, size, off, vboff; | |||||
ufs_lbn_t lbn; | |||||
ufs2_daddr_t addr2, vbaddr; | |||||
static ufs2_daddr_t blkmap, indmap; | |||||
u_int u; | |||||
blkbuf = dmadat->blkbuf; | |||||
indbuf = dmadat->indbuf; | |||||
if (!dsk_meta) { | |||||
inomap = 0; | |||||
for (n = 0; sblock_try[n] != -1; n++) { | |||||
if (dskread(dmadat->sbbuf, sblock_try[n] / DEV_BSIZE, | |||||
SBLOCKSIZE / DEV_BSIZE)) | |||||
return -1; | |||||
memcpy(&fs, dmadat->sbbuf, sizeof(struct fs)); | |||||
if (( | |||||
#if defined(UFS1_ONLY) | |||||
fs.fs_magic == FS_UFS1_MAGIC | |||||
#elif defined(UFS2_ONLY) | |||||
(fs.fs_magic == FS_UFS2_MAGIC && | |||||
fs.fs_sblockloc == sblock_try[n]) | |||||
#else | |||||
fs.fs_magic == FS_UFS1_MAGIC || | |||||
(fs.fs_magic == FS_UFS2_MAGIC && | |||||
fs.fs_sblockloc == sblock_try[n]) | |||||
#endif | |||||
) && | |||||
fs.fs_bsize <= MAXBSIZE && | |||||
fs.fs_bsize >= sizeof(struct fs)) | |||||
break; | |||||
} | |||||
if (sblock_try[n] == -1) { | |||||
printf("Not ufs\n"); | |||||
return -1; | |||||
} | |||||
dsk_meta++; | |||||
} else | |||||
memcpy(&fs, dmadat->sbbuf, sizeof(struct fs)); | |||||
if (!inode) | |||||
return 0; | |||||
if (inomap != inode) { | |||||
n = IPERVBLK(&fs); | |||||
if (dskread(blkbuf, INO_TO_VBA(&fs, n, inode), DBPERVBLK)) | |||||
return -1; | |||||
n = INO_TO_VBO(n, inode); | |||||
#if defined(UFS1_ONLY) | |||||
memcpy(&dp1, (struct ufs1_dinode *)blkbuf + n, | |||||
sizeof(struct ufs1_dinode)); | |||||
#elif defined(UFS2_ONLY) | |||||
memcpy(&dp2, (struct ufs2_dinode *)blkbuf + n, | |||||
sizeof(struct ufs2_dinode)); | |||||
#else | |||||
if (fs.fs_magic == FS_UFS1_MAGIC) | |||||
memcpy(&dp1, (struct ufs1_dinode *)blkbuf + n, | |||||
sizeof(struct ufs1_dinode)); | |||||
else | |||||
memcpy(&dp2, (struct ufs2_dinode *)blkbuf + n, | |||||
sizeof(struct ufs2_dinode)); | |||||
#endif | |||||
inomap = inode; | |||||
fs_off = 0; | |||||
blkmap = indmap = 0; | |||||
} | |||||
size = DIP(di_size); | |||||
n = size - fs_off; | |||||
return (n); | |||||
} | |||||
static struct dmadat __dmadat; | |||||
static int | |||||
domount(EFI_DEVICE_PATH *device, EFI_BLOCK_IO *blkio, int quiet) | |||||
{ | |||||
dmadat = &__dmadat; | |||||
bootdev = blkio; | |||||
bootdevpath = device; | |||||
if (fsread(0, NULL, 0)) { | |||||
if (!quiet) | |||||
printf("domount: can't read superblock\n"); | |||||
return (-1); | |||||
} | |||||
if (!quiet) | |||||
printf("Succesfully mounted UFS filesystem\n"); | |||||
return (0); | |||||
} | |||||
static void | |||||
load(const char *fname) | |||||
{ | |||||
ufs_ino_t ino; | |||||
EFI_STATUS status; | |||||
EFI_HANDLE loaderhandle; | |||||
EFI_LOADED_IMAGE *loaded_image; | |||||
void *buffer; | |||||
size_t bufsize; | |||||
if ((ino = lookup(fname)) == 0) { | |||||
printf("File %s not found\n", fname); | |||||
return; | |||||
} | |||||
bufsize = fsstat(ino); | |||||
status = systab->BootServices->AllocatePool(EfiLoaderData, | |||||
bufsize, &buffer); | |||||
fsread(ino, buffer, bufsize); | |||||
/* XXX: For secure boot, we need our own loader here */ | |||||
status = systab->BootServices->LoadImage(TRUE, image, bootdevpath, | |||||
buffer, bufsize, &loaderhandle); | |||||
if (EFI_ERROR(status)) | |||||
printf("LoadImage failed with error %lx\n", status); | |||||
status = systab->BootServices->HandleProtocol(loaderhandle, | |||||
&LoadedImageGUID, (VOID**)&loaded_image); | |||||
if (EFI_ERROR(status)) | |||||
printf("HandleProtocol failed with error %lx\n", status); | |||||
loaded_image->DeviceHandle = bootdevhandle; | |||||
status = systab->BootServices->StartImage(loaderhandle, NULL, NULL); | |||||
if (EFI_ERROR(status)) | |||||
printf("StartImage failed with error %lx\n", status); | |||||
} | |||||
static void | |||||
panic(const char *fmt, ...) | panic(const char *fmt, ...) | ||||
{ | { | ||||
char buf[128]; | char buf[128]; | ||||
Context not available. | |||||
while (1) {} | while (1) {} | ||||
} | } | ||||
static int | int | ||||
printf(const char *fmt, ...) | printf(const char *fmt, ...) | ||||
{ | { | ||||
va_list ap; | va_list ap; | ||||
Context not available. | |||||
return 0; | return 0; | ||||
va_start(ap, fmt); | va_start(ap, fmt); | ||||
ret = vprintf(fmt, ap); | ret = __printf(fmt, putchr, 0, ap); | ||||
va_end(ap); | va_end(ap); | ||||
return (ret); | return (ret); | ||||
} | } | ||||
static int | void vprintf(const char *fmt, va_list ap) | ||||
putchar(char c, void *arg) | |||||
{ | { | ||||
CHAR16 buf[2]; | __printf(fmt, putchr, 0, ap); | ||||
if (c == '\n') { | |||||
buf[0] = '\r'; | |||||
buf[1] = 0; | |||||
systab->ConOut->OutputString(systab->ConOut, buf); | |||||
} | |||||
buf[0] = c; | |||||
buf[1] = 0; | |||||
systab->ConOut->OutputString(systab->ConOut, buf); | |||||
return (1); | |||||
} | } | ||||
static int | int vsnprintf(char *str, size_t sz, const char *fmt, va_list ap) | ||||
vprintf(const char *fmt, va_list ap) | |||||
{ | { | ||||
int ret; | |||||
ret = __printf(fmt, putchar, 0, ap); | |||||
return (ret); | |||||
} | |||||
static int | |||||
vsnprintf(char *str, size_t sz, const char *fmt, va_list ap) | |||||
{ | |||||
struct sp_data sp; | struct sp_data sp; | ||||
int ret; | int ret; | ||||
Context not available. |
There are many style(9) violations in the following section, please consider fixing them before committing.