diff options
author | ian <ian@FreeBSD.org> | 2016-01-19 21:39:21 +0000 |
---|---|---|
committer | ian <ian@FreeBSD.org> | 2016-01-19 21:39:21 +0000 |
commit | 3c5bf8f9aed8d68d435bf11215f3153209d0ef17 (patch) | |
tree | a72a2dc9cb1079b084d66bbd207e93dfb250c55b /sys/boot/efi/loader | |
parent | 8d32f2253188606396e0d9f449f7bd903aa1d659 (diff) | |
download | FreeBSD-src-3c5bf8f9aed8d68d435bf11215f3153209d0ef17.zip FreeBSD-src-3c5bf8f9aed8d68d435bf11215f3153209d0ef17.tar.gz |
MFC r292584:
Set env vars from values on the efi loader command line.
Examine each cmdline arg and if it contains an '=' convert it to ascii and
pass it to putenv(). This allows var=value settings to come in on the
command line.
This will allow overriding dhcp server-provided data in loader(8), as
discussed in PR 202098
PR: 202098
Relnotes: Yes (this goes together with r294343)
Diffstat (limited to 'sys/boot/efi/loader')
-rw-r--r-- | sys/boot/efi/loader/main.c | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/sys/boot/efi/loader/main.c b/sys/boot/efi/loader/main.c index f334488..b61c32c 100644 --- a/sys/boot/efi/loader/main.c +++ b/sys/boot/efi/loader/main.c @@ -63,10 +63,10 @@ EFI_GUID debugimg = DEBUG_IMAGE_INFO_TABLE_GUID; EFI_STATUS main(int argc, CHAR16 *argv[]) { - char vendor[128]; + char var[128]; EFI_LOADED_IMAGE *img; EFI_GUID *guid; - int i; + int i, j, vargood; /* * XXX Chicken-and-egg problem; we want to have console output @@ -76,6 +76,29 @@ main(int argc, CHAR16 *argv[]) */ cons_probe(); + /* + * Loop through the args, and for each one that contains an '=' that is + * not the first character, add it to the environment. This allows + * loader and kernel env vars to be passed on the command line. Convert + * args from UCS-2 to ASCII (16 to 8 bit) as they are copied. + */ + for (i = 1; i < argc; i++) { + vargood = 0; + for (j = 0; argv[i][j] != 0; j++) { + if (j == sizeof(var)) { + vargood = 0; + break; + } + if (j > 0 && argv[i][j] == '=') + vargood = 1; + var[j] = (char)argv[i][j]; + } + if (vargood) { + var[j] = 0; + putenv(var); + } + } + if (efi_copy_init()) { printf("failed to allocate staging area\n"); return (EFI_BUFFER_TOO_SMALL); |