Announcing efibootmgr-0.2.0
Announcing efibootmgr-0.2.0, a Linux user-space application which interacts with the EFI Boot Manager. It may be downloaded from
http://domsch.com/linux/ia64/efibootmgr-0.2.0.tar.gz.
This requires the efivars module be loaded, and expects them to be at /proc/efi/vars/* which is consistent with the kernel 2.4.4 IA-64 patch. You must be root to run this (as /proc/efi/vars/* are only read/write root).
This is a preliminary release, but seems to work for me. I'd appreciate people's feedback. I suspect it's not quite ready for incorporation into distributions.
By default, with -c, it creates a BootXXXX variable named "Linux", with an EFI Device Path that includes HardDrive()/File(), but not the ACPI stuff. This is per EFI spec, and works as long as disk unique signatures are truely unique.
With -c -e 1, it creates an EDD 1.0 device path like Vendor()/HD()/File() With -c -e 3, it creates an EDD 3.0 device path like ACPI()/PCI()/SCSI()/HD()/File().
With no options, displays current Boot* variable information. -v displays the unparsed device path of each boot option.
usage: efibootmgr [options]
-a | --active set bootnum active
-A | --inactive set bootnum inactive
-b | --bootnum XXXX use BootXXXX (hex)
-B | --delete-bootnum XXXX delete BootXXXX (hex)
-c | --create create new variable bootnum and add to
bootorder
-d | --disk disk (defaults to /dev/sda) containing loader
-e | --edd [1|3|-1] force EDD 1.0 or 3.0 creation variables
(or auto)
-E | --device num EDD 1.0 device number (defaults to 0x80)
-l | --loader name (defaults to \elilo.efi)
-L | --label label Boot manager display label (defaults to
"Linux")
-n | --bootnext XXXX set BootNext to XXXX (hex)
-N | --delete-bootnext delete BootNext
-o | --bootorder XXXX,YYYY,ZZZZ,... explicitly set BootOrder
(hex)
-O | --delete-bootorder delete BootOrder
-p | --part part (defaults to 1) containing loader
-q | --quiet be quiet
-v | --verbose print additional information
-V | --version return version and exit [root@localhost bootmgr]# ./elilo2bootmgr.bin -v
BootNext: 0000
BootOrder: 0000,0004
Boot0000: Linux Vendor(cf31fac5-c24e-11d2-85f3-00a0c93ec93b,80000000)
HD(0,3f,32f8e,0x9674)File(\elilo.efi) Boot0004: Linux ACPI(a0341d0,2)PCI(0,0)SCSI(0,0) HD(0,0,10bc000,0x9ec6)File(\elilo.efi)
Thanks,
Matt
Signature · 5 lines
Matt Domsch Sr. Software Engineer Dell Linux Systems Group Linux OS Development www.dell.com/linux
[email protected] writes:
|> Announcing efibootmgr-0.2.0, a Linux user-space application which interacts |> with the EFI Boot Manager. It may be downloaded from |> http://domsch.com/linux/ia64/efibootmgr-0.2.0.tar.gz.
Appended is a patch that removes the use of kernel headers (which have no place in user level programs), and fixes the use of feature test macros. There are also a few unaligned accesses which I haven't fixed.
Andreas.
Signature · 5 lines
Andreas Schwab "And now for something SuSE Labs completely different." [email protected] SuSE GmbH, Schanzäckerstr. 10, D-90443 Nürnberg Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
efibootmgr/efibootmgr.c +33 -32
@@ -30,6 +30,8 @@*/ +#define _GNU_SOURCE +#include <stdio.h> #include <stdlib.h> #include <string.h>
@@ -39,7 +41,6 @@#include <fcntl.h> #include <dirent.h> #include <unistd.h> -#define _GNU_SOURCE#include <getopt.h> #include "list.h" #include "efi.h"
@@ -53,7 +54,7 @@typedef struct _var_entry {struct dirent *name; -__u16 num; +uint16_t num;efi_variable_t var_data;struct list_head list; }var_entry_t ;
@@ -65,7 +66,7 @@efibootmgr_opt_t opts;static inline void -var_num_from_name (const char *pattern,char *name,__u16 *num) +var_num_from_name (const char *pattern,char *name,uint16_t *num) {sscanf (name, pattern, num); }
@@ -165,7 +166,7 @@ compare(const void *a, const void *b) { int rc = -1; -__u32 n1=*(__u32 *)a, n2=*(__u32 *)b; +uint32_t n1=*(uint32_t *)a, n2=*(uint32_t *)b;if (n1 < n2) rc =-1 ;if (n1 == n2) rc =0 ;if (n2 > n2) rc =1 ;
@@ -181,22 +182,22 @@ find_free_boot_var(struct list_head *boot_list) {int num_vars=0 , i=0 , found; -__u16 *vars, free_number; +uint16_t *vars, free_number;struct list_head *pos;var_entry_t *boot;list_for_each (pos, boot_list) { num_vars++; } - vars =malloc (sizeof (__u16) * num_vars); + vars =malloc (sizeof (uint16_t ) * num_vars);if (!vars)return -1 ; -memset (vars,0 ,sizeof (__u16) * num_vars); +memset (vars,0 ,sizeof (uint16_t ) * num_vars);list_for_each (pos, boot_list) { boot =list_entry (pos, var_entry_t, list); vars[i] = boot->num; i++; } -qsort (vars, i,sizeof (__u16), compare); +qsort (vars, i,sizeof (uint16_t ), compare); found =1 ; num_vars = i;
@@ -277,12 +278,12 @@static efi_status_t -add_to_boot_order (__u16 num) +add_to_boot_order (uint16_t num) {efi_status_t status;efi_variable_t boot_order; -__u64 new_data_size; -__u16 *new_data, *old_data; +uint64_t new_data_size; +uint16_t *new_data, *old_data; status =read_boot_order (&boot_order);
@@ -292,8 +293,8 @@/* We've now got an array (in boot_order.Data) of the boot order. First add our entry, then copy the old array. */ - old_data = (__u16 *)&(boot_order.Data); - new_data_size = boot_order.DataSize +sizeof (__u16); + old_data = (uint16_t *)&(boot_order.Data); + new_data_size = boot_order.DataSize +sizeof (uint16_t ); new_data =malloc (new_data_size); new_data[0 ] = num;
@@ -308,12 +309,12 @@static efi_status_t -remove_from_boot_order (__u16 num) +remove_from_boot_order (uint16_t num) {efi_status_t status;efi_variable_t boot_order; -__u64 new_data_size; -__u16 *new_data, *old_data; +uint64_t new_data_size; +uint16_t *new_data, *old_data;int old_i,new_i;read_boot_order (&boot_order);
@@ -326,12 +327,12 @@boot order. Simply copy the array, skipping the entry we're deleting. */ - old_data = (__u16 *)&(boot_order.Data); + old_data = (uint16_t *)&(boot_order.Data);/* Start with the same size */ new_data_size = boot_order.DataSize; new_data =malloc (new_data_size);for (old_i=0 ,new_i=0 ; - old_i < boot_order.DataSize /sizeof (__u16); + old_i < boot_order.DataSize /sizeof (uint16_t ); old_i++) {if (old_data[old_i] != num) {/* Copy this value */
@@ -341,7 +342,7 @@ }/* Now new_data has what we need */ - new_data_size = new_i *sizeof (__u16); + new_data_size = new_i *sizeof (uint16_t );memset (&(boot_order.Data),0 , boot_order.DataSize);memcpy (&(boot_order.Data), new_data, new_data_size); boot_order.DataSize = new_data_size;
@@ -356,7 +357,7 @@efi_variable_t boot_next;efi_guid_t guid =EFI_GLOBAL_VARIABLE ;char boot_next_name[80 ], text_uuid[40 ]; -__u16 *n = (__u16 *)(boot_next.Data); +uint16_t *n = (uint16_t *)(boot_next.Data);efi_guid_unparse (&guid, text_uuid);
@@ -376,7 +377,7 @@efi_variable_t boot_next;efi_guid_t guid =EFI_GLOBAL_VARIABLE ;char boot_next_name[80 ], text_uuid[40 ]; -__u16 *n = (__u16 *)(boot_next.Data); +uint16_t *n = (uint16_t *)(boot_next.Data);efi_guid_unparse (&guid, text_uuid);
@@ -391,11 +392,11 @@static efi_status_t -set_boot_next (__u16 num) +set_boot_next (uint16_t num) {efi_variable_t var;efi_guid_t guid =EFI_GLOBAL_VARIABLE ; -__u16 *n = (__u16 *)var.Data; +uint16_t *n = (uint16_t *)var.Data;memset (&var,0 ,sizeof (var));
@@ -403,7 +404,7 @@ 1024);memcpy (&var.VendorGuid, &guid,sizeof (guid)); *n = num; - var.DataSize =sizeof (__u16); + var.DataSize =sizeof (uint16_t ); var.Attributes =EFI_VARIABLE_NON_VOLATILE |EFI_VARIABLE_BOOTSERVICE_ACCESS |EFI_VARIABLE_RUNTIME_ACCESS ;
@@ -426,7 +427,7 @@static efi_status_t -delete_boot_var (__u16 num) +delete_boot_var (uint16_t num) {efi_status_t status;efi_variable_t var;
@@ -564,7 +565,7 @@#endif static void -unparse_boot_order (__u16 *order,int length) +unparse_boot_order (uint16_t *order,int length) {int i;printf ("BootOrder: " );
@@ -577,7 +578,7 @@ }static int -parse_boot_order (char *buffer,__u16 *order,int length) +parse_boot_order (char *buffer,uint16_t *order,int length) {int i;int num, rc;
@@ -598,7 +599,7 @@ {efi_variable_t var;efi_guid_t guid =EFI_GLOBAL_VARIABLE ; -__u16 *n = (__u16 *)var.Data; +uint16_t *n = (uint16_t *)var.Data;if (!opts.bootorder)return EFI_SUCCESS ;
@@ -611,7 +612,7 @@ | EFI_VARIABLE_BOOTSERVICE_ACCESS |EFI_VARIABLE_RUNTIME_ACCESS ; - var.DataSize =parse_boot_order (opts.bootorder, n,1024 /sizeof (__u16)) *sizeof (__u16); + var.DataSize =parse_boot_order (opts.bootorder, n,1024 /sizeof (uint16_t )) *sizeof (uint16_t );return write_variable (&var); }
@@ -655,7 +656,7 @@ {efi_status_t status;efi_variable_t boot_order; -__u16 *data; +uint16_t *data; status =read_boot_order (&boot_order);if (status !=EFI_SUCCESS )return ;
@@ -663,9 +664,9 @@/* We've now got an array (in boot_order.Data) of the boot order. First add our entry, then copy the old array. */ - data = (__u16 *)&(boot_order.Data); + data = (uint16_t *)&(boot_order.Data);if (boot_order.DataSize) -unparse_boot_order (data, boot_order.DataSize /sizeof (__u16)); +unparse_boot_order (data, boot_order.DataSize /sizeof (uint16_t )); }
include/crc32.h +2 -2
@@ -22,13 +22,13 @@#ifndef _CRC32_H#define _CRC32_H -#include <linux/types.h> +#include <stdint.h> /* * This computes a 32 bit CRC of the data in the buffer, and returns the CRC. * The polynomial used is 0xedb88320. */ -extern __u32 crc32 (const void *buf,unsigned long len,__u32 seed); +extern uint32_t crc32 (const void *buf,unsigned long len,uint32_t seed);#endif /* _CRC32_H */
include/disk.h +3 -3
@@ -77,10 +77,10 @@ unsigned char *part);int disk_get_partition_info (int fd, -__u32 num, -__u64 *start,__u64 *size, +uint32_t num, +uint64_t *start,uint64_t *size,char *signature, -__u8 *mbr_type,__u8 *signature_type); +uint8_t *mbr_type,uint8_t *signature_type);int disk_get_size (int fd,long *size);
include/efi.h +152 -152
415 lines not on this page · raw message
include/efibootmgr.h +1 -1
@@ -26,7 +26,7 @@char *loader;char *label;char *bootorder; -__u32 part; +uint32_t part;int edd_version;int edd10_devicenum;int bootnum;
include/gpt.h +37 -37
119 lines not on this page · raw message
include/scsi_ioctls.h +3 -2
@@ -21,6 +21,7 @@#ifndef _SCSI_IOCTLS_H#define _SCSI_IOCTLS_H +#include <stdint.h>/* Snagged from linux/include/scsi/scsi.h */
@@ -28,8 +29,8 @@#define SCSI_IOCTL_GET_PCI 0x5387typedef struct scsi_idlun { -__u32 dev_id; -__u32 host_unique_id; +uint32_t dev_id; +uint32_t host_unique_id; }Scsi_Idlun ;
include/unparse_path.h +3 -3
@@ -21,14 +21,14 @@#ifndef _UNPARSE_PATH_H#define _UNPARSE_PATH_H -#include <linux/types.h> +#include <stdint.h> #include "efi.h" #define OFFSET_OF (struct_type, member) \ ((unsigned long) ((char *) &((struct_type*) 0)->member)) -__u64 unparse_path (char *buffer,EFI_DEVICE_PATH *path,__u16 pathsize); -void dump_raw_data (void *data,__u64 length); +uint64_t unparse_path (char *buffer,EFI_DEVICE_PATH *path,uint16_t pathsize); +void dump_raw_data (void *data,uint64_t length);#endif
lib/crc32.c +5 -5
@@ -48,9 +48,9 @@/* */ /* -------------------------------------------------------------------- */ -#include <linux/types.h> +#include <stdint.h> -static __u32 crc32_tab[] = { +static uint32_t crc32_tab[] = {0x00000000L ,0x77073096L ,0xee0e612cL ,0x990951baL ,0x076dc419L ,0x706af48fL ,0xe963a535L ,0x9e6495a3L ,0x0edb8832L ,0x79dcb8a4L ,0xe0d5e91eL ,0x97d2d988L ,0x09b64c2bL ,0x7eb17cbdL ,0xe7b82d07L ,
@@ -107,11 +107,11 @@/* Return a 32-bit CRC of the contents of the buffer. */ -__u32 -crc32 (const void *buf,unsigned long len,__u32 seed) +uint32_t +crc32 (const void *buf,unsigned long len,uint32_t seed) {unsigned long i; - register__u32 crc32val; + registeruint32_t crc32val;const unsigned char *s = buf; crc32val = seed;
lib/disk.c +11 -11
@@ -20,7 +20,7 @@#include <stdio.h> #include <string.h> -#include <linux/types.h> +#include <stdint.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h>
@@ -38,7 +38,7 @@ {struct stat buf;int rc; -__u64 major; +uint64_t major;unsigned char minor;memset (&buf,0 ,sizeof (struct stat )); rc =fstat (fd, &buf);
@@ -283,8 +283,8 @@static int msdos_disk_get_extended_partition_info (int fd,LegacyMBR_t *mbr, -__u32 num, -__u64 *start,__u64 *size) +uint32_t num, +uint64_t *start,uint64_t *size) {/* Until I can handle these... */ fprintf (stderr,"Extended partition info not supported.\n" );
@@ -306,17 +306,17 @@static int msdos_disk_get_partition_info (int fd,LegacyMBR_t *mbr, -__u32 num, -__u64 *start,__u64 *size, +uint32_t num, +uint64_t *start,uint64_t *size,char *signature, -__u8 *mbr_type,__u8 *signature_type) +uint8_t *mbr_type,uint8_t *signature_type) {long disk_size=0 ; *mbr_type =0x01 ; *signature_type =0x01 ; - *(__u32 *)signature = mbr->UniqueMBRSignature; + *(uint32_t *)signature = mbr->UniqueMBRSignature;if (num >4 ) {/* Extended partition */
@@ -356,10 +356,10 @@int disk_get_partition_info (int fd, -__u32 num, -__u64 *start,__u64 *size, +uint32_t num, +uint64_t *start,uint64_t *size,char *signature, -__u8 *mbr_type,__u8 *signature_type) +uint8_t *mbr_type,uint8_t *signature_type) {LegacyMBR_t mbr;off_t offset;
lib/efi.c +25 -26
138 lines not on this page · raw message
lib/gpt.c +15 -15
@@ -26,7 +26,7 @@#include <stdio.h> #include <string.h> #include <stdlib.h> -#include <linux/types.h> +#include <stdint.h> #include <sys/stat.h> #include <sys/ioctl.h> #include <fcntl.h>
@@ -39,7 +39,7 @@#define BLKGETLASTSECT _IO(0x12,108)/* get last sector of block device */ #define BLKGETSIZE _IO(0x12,96)/* return device size */ -static struct blkdev_ioctl_param { +struct blkdev_ioctl_param {unsigned int block;size_t content_length;char * block_contents;
@@ -59,7 +59,7 @@* but seeds the function with ~0, and xor's with ~0 at the end. ************************************************************/ -static inline __u32 +static inline uint32_t efi_crc32 (const void *buf,unsigned long len) {return (crc32 (buf, len, ~0L ) ^ ~0L );
@@ -95,11 +95,11 @@* blocks of 2. :( ************************************************************/ -static __u64 +static uint64_t LastLBA (int filedes) {int rc; -__u64 sectors =0 ; +uint64_t sectors =0 ;struct stat s;memset (&s,0 ,sizeof (s)); rc =fstat (filedes, &s);
@@ -141,7 +141,7 @@static inline int -IsLBAValid (int fd,__u64 lba) +IsLBAValid (int fd,uint64_t lba) {return (lba <=LastLBA (fd)); }
@@ -149,7 +149,7 @@static int -read_lastoddsector (int fd,__u64 lba,void *buffer,size_t count) +read_lastoddsector (int fd,uint64_t lba,void *buffer,size_t count) {int rc;struct blkdev_ioctl_param ioctl_param;
@@ -169,7 +169,7 @@static int -ReadLBA (int fd,__u64 lba,void *buffer,size_t bytes) +ReadLBA (int fd,uint64_t lba,void *buffer,size_t bytes) {off_t offset = lba *512 ;
@@ -242,7 +242,7 @@************************************************************/ static GuidPartitionTableHeader_t *ReadGuidPartitionTableHeader (int fd, -__u64 lba) +uint64_t lba) {GuidPartitionTableHeader_t *gpt; gpt = (GuidPartitionTableHeader_t *)
@@ -275,12 +275,12 @@static int -IsGuidPartitionTableValid (int fd,__u64 lba, +IsGuidPartitionTableValid (int fd,uint64_t lba,GuidPartitionTableHeader_t ** gpt,GuidPartitionEntry_t ** ptes) {int rc =0 ;/* default to not valid */ -__u32 crc, origcrc; +uint32_t crc, origcrc;if (!gpt || !ptes)return rc;
@@ -366,7 +366,7 @@ {int rc =0 ;GuidPartitionEntry_t *pptes =NULL , *aptes =NULL ; -__u64 lastlba; +uint64_t lastlba; lastlba =LastLBA (fd);
@@ -424,10 +424,10 @@int gpt_disk_get_partition_info (int fd, -__u32 num, -__u64 *start,__u64 *size, +uint32_t num, +uint64_t *start,uint64_t *size,char *signature, -__u8 *mbr_type,__u8 *signature_type) +uint8_t *mbr_type,uint8_t *signature_type) {GuidPartitionTableHeader_t * pgpt=NULL , * agpt=NULL , *gpt =NULL ;GuidPartitionEntry_t * ptes=NULL , *p;
lib/scsi_ioctls.c +1 -2
@@ -19,10 +19,9 @@*/ #include <stdio.h> -#include <pci/pci.h> +#include <sys/pci.h> #include <sys/types.h> #include <sys/stat.h> -#include <linux/types.h> #include <fcntl.h> #include <sys/ioctl.h> #include "scsi_ioctls.h"
lib/unparse_path.c +28 -28
155 lines not on this page · raw message
[email protected] writes:
|> Announcing efibootmgr-0.2.0, a Linux user-space application which interacts |> with the EFI Boot Manager. It may be downloaded from |> http://domsch.com/linux/ia64/efibootmgr-0.2.0.tar.gz.
Here is another patch that fixes a crash.
src/lib/efi.c renamed from src/lib/efi.c.~1~ +0 -3
@@ -88,7 +88,6 @@efi_status_t write_variable (efi_variable_t *var) { -char *newname;int fd;size_t writesize;char buffer[PATH_MAX ];
@@ -99,7 +98,6 @@if (fd ==-1 ) {sprintf (buffer,"write_variable():open(%s)" , name);perror (buffer); -free (newname);return EFI_INVALID_PARAMETER ; } writesize =write (fd, var,sizeof (*var));
@@ -108,7 +106,6 @@sprintf (buffer,"write_variable():write(%s)" , name);perror (buffer);dump_raw_data (var,sizeof (*var)); -free (newname);#endif close (fd);return EFI_INVALID_PARAMETER ;
Andreas.
Signature · 5 lines
Andreas Schwab "And now for something SuSE Labs completely different." [email protected] SuSE GmbH, Schanzäckerstr. 10, D-90443 Nürnberg Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5