main.c (298826) | main.c (300081) |
---|---|
1/*- 2 * Copyright (c) 2008-2010 Rui Paulo 3 * Copyright (c) 2006 Marcel Moolenaar 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 12 unchanged lines hidden (view full) --- 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2008-2010 Rui Paulo 3 * Copyright (c) 2006 Marcel Moolenaar 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 12 unchanged lines hidden (view full) --- 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28#include <sys/cdefs.h> |
29__FBSDID("$FreeBSD: head/sys/boot/efi/loader/main.c 298826 2016-04-30 00:26:38Z pfg $"); | 29__FBSDID("$FreeBSD: head/sys/boot/efi/loader/main.c 300081 2016-05-17 21:25:20Z imp $"); |
30 31#include <sys/param.h> 32#include <sys/reboot.h> 33#include <sys/boot.h> 34#include <stand.h> 35#include <string.h> 36#include <setjmp.h> 37 38#include <efi.h> 39#include <efilib.h> 40 | 30 31#include <sys/param.h> 32#include <sys/reboot.h> 33#include <sys/boot.h> 34#include <stand.h> 35#include <string.h> 36#include <setjmp.h> 37 38#include <efi.h> 39#include <efilib.h> 40 |
41#include <uuid.h> 42 |
|
41#include <bootstrap.h> 42#include <smbios.h> 43 44#ifdef EFI_ZFS_BOOT 45#include <libzfs.h> 46#endif 47 48#include "loader_efi.h" --- 282 unchanged lines hidden (view full) --- 331 printf(" "); 332 print_str16(argv[i]); 333 } 334 printf("\n"); 335 336 printf("Image base: 0x%lx\n", (u_long)img->ImageBase); 337 printf("EFI version: %d.%02d\n", ST->Hdr.Revision >> 16, 338 ST->Hdr.Revision & 0xffff); | 43#include <bootstrap.h> 44#include <smbios.h> 45 46#ifdef EFI_ZFS_BOOT 47#include <libzfs.h> 48#endif 49 50#include "loader_efi.h" --- 282 unchanged lines hidden (view full) --- 333 printf(" "); 334 print_str16(argv[i]); 335 } 336 printf("\n"); 337 338 printf("Image base: 0x%lx\n", (u_long)img->ImageBase); 339 printf("EFI version: %d.%02d\n", ST->Hdr.Revision >> 16, 340 ST->Hdr.Revision & 0xffff); |
339 printf("EFI Firmware: "); 340 /* printf doesn't understand EFI Unicode */ 341 ST->ConOut->OutputString(ST->ConOut, ST->FirmwareVendor); 342 printf(" (rev %d.%02d)\n", ST->FirmwareRevision >> 16, 343 ST->FirmwareRevision & 0xffff); | 341 printf("EFI Firmware: %S (rev %d.%02d)\n", ST->FirmwareVendor, 342 ST->FirmwareRevision >> 16, ST->FirmwareRevision & 0xffff); |
344 345 printf("\n"); 346 printf("%s, Revision %s\n", bootprog_name, bootprog_rev); 347 printf("(%s, %s)\n", bootprog_maker, bootprog_date); 348 349 /* 350 * Disable the watchdog timer. By default the boot manager sets 351 * the timer to 5 minutes before invoking a boot option. If we --- 37 unchanged lines hidden (view full) --- 389 env_setenv("currdev", EV_VOLATILE, efi_fmtdev(&currdev), 390 efi_setcurrdev, env_nounset); 391 env_setenv("loaddev", EV_VOLATILE, efi_fmtdev(&currdev), env_noset, 392 env_nounset); 393 break; 394 } 395 } 396 | 343 344 printf("\n"); 345 printf("%s, Revision %s\n", bootprog_name, bootprog_rev); 346 printf("(%s, %s)\n", bootprog_maker, bootprog_date); 347 348 /* 349 * Disable the watchdog timer. By default the boot manager sets 350 * the timer to 5 minutes before invoking a boot option. If we --- 37 unchanged lines hidden (view full) --- 388 env_setenv("currdev", EV_VOLATILE, efi_fmtdev(&currdev), 389 efi_setcurrdev, env_nounset); 390 env_setenv("loaddev", EV_VOLATILE, efi_fmtdev(&currdev), env_noset, 391 env_nounset); 392 break; 393 } 394 } 395 |
396 snprintf(var, sizeof(var), "%d.%02d", ST->Hdr.Revision >> 16, 397 ST->Hdr.Revision & 0xffff); 398 env_setenv("efi-version", EV_VOLATILE, var, env_noset, env_nounset); |
|
397 setenv("LINES", "24", 1); /* optional */ 398 399 for (k = 0; k < ST->NumberOfTableEntries; k++) { 400 guid = &ST->ConfigurationTable[k].VendorGuid; 401 if (!memcmp(guid, &smbios, sizeof(EFI_GUID))) { 402 smbios_detect(ST->ConfigurationTable[k].VendorTable); 403 break; 404 } 405 } 406 407 interact(NULL); /* doesn't return */ 408 409 return (EFI_SUCCESS); /* keep compiler happy */ 410} 411 | 399 setenv("LINES", "24", 1); /* optional */ 400 401 for (k = 0; k < ST->NumberOfTableEntries; k++) { 402 guid = &ST->ConfigurationTable[k].VendorGuid; 403 if (!memcmp(guid, &smbios, sizeof(EFI_GUID))) { 404 smbios_detect(ST->ConfigurationTable[k].VendorTable); 405 break; 406 } 407 } 408 409 interact(NULL); /* doesn't return */ 410 411 return (EFI_SUCCESS); /* keep compiler happy */ 412} 413 |
414/* XXX move to lib stand ? */ 415static int 416wcscmp(CHAR16 *a, CHAR16 *b) 417{ 418 419 while (*a && *b && *a == *b) { 420 a++; 421 b++; 422 } 423 return *a - *b; 424} 425 426 |
|
412COMMAND_SET(reboot, "reboot", "reboot the system", command_reboot); 413 414static int 415command_reboot(int argc, char *argv[]) 416{ 417 int i; 418 419 for (i = 0; devsw[i] != NULL; ++i) --- 191 unchanged lines hidden (view full) --- 611 612 if (i != 0) 613 printf("Select a mode with the command \"mode <number>\"\n"); 614 615 return (CMD_OK); 616} 617 618 | 427COMMAND_SET(reboot, "reboot", "reboot the system", command_reboot); 428 429static int 430command_reboot(int argc, char *argv[]) 431{ 432 int i; 433 434 for (i = 0; devsw[i] != NULL; ++i) --- 191 unchanged lines hidden (view full) --- 626 627 if (i != 0) 628 printf("Select a mode with the command \"mode <number>\"\n"); 629 630 return (CMD_OK); 631} 632 633 |
634/* deprecated */ |
|
619COMMAND_SET(nvram, "nvram", "get or set NVRAM variables", command_nvram); 620 621static int 622command_nvram(int argc, char *argv[]) 623{ 624 CHAR16 var[128]; 625 CHAR16 *data; 626 EFI_STATUS status; --- 86 unchanged lines hidden (view full) --- 713 command_errmsg = strerror(err); 714 return (CMD_ERROR); 715 } 716 717 return (CMD_OK); 718} 719#endif 720 | 635COMMAND_SET(nvram, "nvram", "get or set NVRAM variables", command_nvram); 636 637static int 638command_nvram(int argc, char *argv[]) 639{ 640 CHAR16 var[128]; 641 CHAR16 *data; 642 EFI_STATUS status; --- 86 unchanged lines hidden (view full) --- 729 command_errmsg = strerror(err); 730 return (CMD_ERROR); 731 } 732 733 return (CMD_OK); 734} 735#endif 736 |
737COMMAND_SET(efishow, "efi-show", "print some or all EFI variables", command_efi_printenv); 738 739static int 740efi_print_var(CHAR16 *varnamearg, EFI_GUID *matchguid, int lflag) 741{ 742 UINTN datasz; 743 EFI_STATUS status; 744 UINT32 attr; 745 CHAR16 *data; 746 char *str; 747 uint32_t uuid_status; 748 749 datasz = 0; 750 status = RS->GetVariable(varnamearg, matchguid, &attr, 751 &datasz, NULL); 752 if (status != EFI_BUFFER_TOO_SMALL) { 753 printf("Can't get the variable: error %#lx\n", status); 754 return (CMD_ERROR); 755 } 756 data = malloc(datasz); 757 status = RS->GetVariable(varnamearg, matchguid, &attr, 758 &datasz, data); 759 if (status != EFI_SUCCESS) { 760 printf("Can't get the variable: error %#lx\n", status); 761 return (CMD_ERROR); 762 } 763 uuid_to_string((uuid_t *)matchguid, &str, &uuid_status); 764 printf("%s %S=%S\n", str, varnamearg, data); 765 free(str); 766 free(data); 767 return (CMD_OK); 768} 769 770static int 771command_efi_printenv(int argc, char *argv[]) 772{ 773 /* 774 * efi-printenv [-a] 775 * print all the env 776 * efi-printenv -u UUID 777 * print all the env vars tagged with UUID 778 * efi-printenv -v var 779 * search all the env vars and print the ones matching var 780 * eif-printenv -u UUID -v var 781 * eif-printenv UUID var 782 * print all the env vars that match UUID and var 783 */ 784 /* XXX We assume EFI_GUID is the same as uuid_t */ 785 int aflag = 0, gflag = 0, lflag = 0, vflag = 0; 786 int ch; 787 unsigned i; 788 EFI_STATUS status; 789 EFI_GUID varguid = { 0,0,0,{0,0,0,0,0,0,0,0} }; 790 EFI_GUID matchguid = { 0,0,0,{0,0,0,0,0,0,0,0} }; 791 uint32_t uuid_status; 792 CHAR16 varname[128]; 793 CHAR16 varnamearg[128]; 794 UINTN varsz; 795 796 while ((ch = getopt(argc, argv, "ag:lv:")) != -1) { 797 switch (ch) { 798 case 'a': 799 aflag = 1; 800 break; 801 case 'g': 802 gflag = 1; 803 uuid_from_string(optarg, (uuid_t *)&matchguid, 804 &uuid_status); 805 if (uuid_status != uuid_s_ok) { 806 printf("uid %s could not be parsed\n", optarg); 807 return (CMD_ERROR); 808 } 809 break; 810 case 'l': 811 lflag = 1; 812 break; 813 case 'v': 814 vflag = 1; 815 if (strlen(optarg) >= nitems(varnamearg)) { 816 printf("Variable %s is longer than %zd characters\n", 817 optarg, nitems(varnamearg)); 818 return (CMD_ERROR); 819 } 820 for (i = 0; i < strlen(optarg); i++) 821 varnamearg[i] = optarg[i]; 822 varnamearg[i] = 0; 823 default: 824 printf("Invalid argument %c\n", ch); 825 return (CMD_ERROR); 826 } 827 } 828 829 if (aflag && (gflag || vflag)) { 830 printf("-a isn't compatible with -v or -u\n"); 831 return (CMD_ERROR); 832 } 833 834 if (aflag && optind < argc) { 835 printf("-a doesn't take any args"); 836 return (CMD_ERROR); 837 } 838 839 if (optind == argc) 840 aflag = 1; 841 842 argc -= optind; 843 argv += optind; 844 845 if (vflag && gflag) 846 return efi_print_var(varnamearg, &matchguid, lflag); 847 848 if (argc == 2) { 849 optarg = argv[0]; 850 if (strlen(optarg) >= nitems(varnamearg)) { 851 printf("Variable %s is longer than %zd characters\n", 852 optarg, nitems(varnamearg)); 853 return (CMD_ERROR); 854 } 855 for (i = 0; i < strlen(optarg); i++) 856 varnamearg[i] = optarg[i]; 857 varnamearg[i] = 0; 858 optarg = argv[1]; 859 uuid_from_string(optarg, (uuid_t *)&matchguid, 860 &uuid_status); 861 if (uuid_status != uuid_s_ok) { 862 printf("uid %s could not be parsed\n", optarg); 863 return (CMD_ERROR); 864 } 865 return efi_print_var(varnamearg, &matchguid, lflag); 866 } 867 868 if (argc != 0) { 869 printf("Too many args\n"); 870 return (CMD_ERROR); 871 } 872 873 /* 874 * Initiate the search -- note the standard takes pain 875 * to specify the initial call must be a poiner to a NULL 876 * character. 877 */ 878 varsz = nitems(varname); 879 varname[0] = 0; 880 status = RS->GetNextVariableName(&varsz, varname, &varguid); 881 while (status != EFI_NOT_FOUND) { 882 status = RS->GetNextVariableName(&varsz, varname, 883 &varguid); 884 if (aflag) { 885 efi_print_var(varname, &varguid, lflag); 886 continue; 887 } 888 if (vflag) { 889 if (wcscmp(varnamearg, varname) == 0) 890 efi_print_var(varname, &varguid, lflag); 891 } 892 if (gflag) { 893 if (memcmp(&varguid, &matchguid, sizeof(varguid)) == 0) 894 efi_print_var(varname, &varguid, lflag); 895 } 896 } 897 898 return (CMD_OK); 899} 900 901COMMAND_SET(efiset, "efi-set", "set EFI variables", command_efi_set); 902 903static int 904command_efi_set(int argc, char *argv[]) 905{ 906 return (CMD_OK); 907} 908 909COMMAND_SET(efiunset, "efi-unset", "delete / unset EFI variables", command_efi_unset); 910 911static int 912command_efi_unset(int argc, char *argv[]) 913{ 914 return (CMD_OK); 915} 916 |
|
721#ifdef LOADER_FDT_SUPPORT 722extern int command_fdt_internal(int argc, char *argv[]); 723 724/* 725 * Since proper fdt command handling function is defined in fdt_loader_cmd.c, 726 * and declaring it as extern is in contradiction with COMMAND_SET() macro 727 * (which uses static pointer), we're defining wrapper function, which 728 * calls the proper fdt handling routine. --- 30 unchanged lines hidden --- | 917#ifdef LOADER_FDT_SUPPORT 918extern int command_fdt_internal(int argc, char *argv[]); 919 920/* 921 * Since proper fdt command handling function is defined in fdt_loader_cmd.c, 922 * and declaring it as extern is in contradiction with COMMAND_SET() macro 923 * (which uses static pointer), we're defining wrapper function, which 924 * calls the proper fdt handling routine. --- 30 unchanged lines hidden --- |