public inbox for linux-ia64@vger.kernel.org
 help / color / mirror / Atom feed
* efibootmgr fixes for EFI 1.10
@ 2005-03-01 23:22 Alex Williamson
  2005-03-01 23:51 ` Andreas Schwab
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Alex Williamson @ 2005-03-01 23:22 UTC (permalink / raw)
  To: linux-ia64


   An EFI firmware engineer brought to my attention that efibootmgr is
not strictly compliant with a clarification that was added to the 1.10
EFI spec.  Section 3.1, page 3-2 now states the BootXXXX entries should
use upper case A-F.  Currently we use lowercase.  The patch below fixes
this problem and tries to be somewhat backwards compatible.  I kind of
doubt many people have more than 10 boot menu entries anyway.  While
poking around, I also added a warning to prevent creating boot entries
with the same number and removed the previous limitation of ignoring
entries greater than 0FFF.

   Please give this a try and let me know if there are any problems.
Thanks,

	Alex

-- 
Alex Williamson                             HP Linux & Open Source Lab

--- efibootmgr-0.5.0/src/lib/efi.c	2005-02-28 16:00:18.782889342 -0700
+++ efibootmgr-0.5.0/src/lib/efi.c	2005-03-01 13:45:11.947945876 -0700
@@ -20,6 +20,7 @@
 
 #define _FILE_OFFSET_BITS 64
 
+#include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -171,9 +172,12 @@
 static int
 select_boot_var_names(const struct dirent *d)
 {
-	int num, rc;
-	rc = sscanf(d->d_name, "Boot0%03x-%*s", &num);
-	return rc;
+	if (!strncmp(d->d_name, "Boot", 4) &&
+	    isxdigit(d->d_name[4]) && isxdigit(d->d_name[5]) &&
+	    isxdigit(d->d_name[6]) && isxdigit(d->d_name[7]) &&
+	    d->d_name[8] = '-')
+		return 1;
+	return 0;
 }
 
 int
@@ -716,7 +720,7 @@
 	memset(buffer,    0, sizeof(buffer));
 
 	/* VariableName needs to be BootXXXX */
-	sprintf(buffer, "Boot%04x", free_number);
+	sprintf(buffer, "Boot%04X", free_number);
 
 	efichar_from_char(var->VariableName, buffer, 1024);
 
--- efibootmgr-0.5.0/src/efibootmgr/efibootmgr.c	2005-02-28 16:00:18.802420592 -0700
+++ efibootmgr-0.5.0/src/efibootmgr/efibootmgr.c	2005-03-01 13:32:05.899127380 -0700
@@ -32,6 +32,7 @@
 
 #define _GNU_SOURCE
 
+#include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -208,6 +209,7 @@
 	list_t *pos;
 	var_entry_t *boot;
 	EFI_LOAD_OPTION *load_option;
+	char name[9];
 
 	list_for_each(pos, boot_list) {
 		boot = list_entry(pos, var_entry_t, list);
@@ -215,8 +217,9 @@
 			boot->var_data.Data;
 		if (!efichar_char_strcmp(opts.label,
 					 load_option->description)) {
-			fprintf(stderr, "** Warning ** : Boot%04x has same label %s\n",
-			       boot->num,
+			snprintf(name, 9, "%s", boot->name->d_name);
+			fprintf(stderr, "** Warning ** : %s has same label %s\n",
+			       name,
 			       opts.label);
 		}
 	}
@@ -228,9 +231,21 @@
 {
 	var_entry_t *boot;
 	int free_number;
+	list_t *pos;
 
-	if (opts.bootnum = -1) free_number = find_free_boot_var(boot_list);
-	else                    free_number = opts.bootnum;
+	if (opts.bootnum = -1)
+		free_number = find_free_boot_var(boot_list);
+	else {
+		list_for_each(pos, boot_list) {
+			boot = list_entry(pos, var_entry_t, list);
+			if (boot->num = opts.bootnum) {
+				fprintf(stderr, "** Warning ** : bootnum %04X "
+				        "already exists\n", opts.bootnum);
+				return NULL;
+			}
+		}
+		free_number = opts.bootnum;
+	}
 
 	if (free_number = -1) return NULL;
 
@@ -398,13 +413,20 @@
 	list_t *pos, *n;
 	var_entry_t *boot;
 
-	snprintf(name, sizeof(name), "Boot%04x", num);
+	snprintf(name, sizeof(name), "Boot%04X", num);
 	memset(&var, 0, sizeof(var));
 	fill_var(&var, name);
 	status = delete_variable(&var);
 
-	if (status) return status;
+	/* For backwards compatibility, try to delete abcdef entries as well */
+	if (status) {
+		snprintf(name, sizeof(name), "Boot%04x", num);
+		memset(&var, 0, sizeof(var));
+		fill_var(&var, name);
+		status = delete_variable(&var);
+	}
 
+	if (status) return status;
 	list_for_each_safe(pos, n, &boot_entry_list) {
 		boot = list_entry(pos, var_entry_t, list);
 		if (boot->num = num) {
@@ -424,11 +446,21 @@
 	list_t *pos;
 	var_entry_t *var;
 	int num=0, rc;
+	char name[9];
 
 	list_for_each(pos, list) {
 		var = list_entry(pos, var_entry_t, list);
 		rc = sscanf(var->name->d_name, pattern, &num);
-		if (rc = 1) var->num = num;
+		if (rc = 1) {
+			var->num = num;
+			snprintf(name, 9, "%s", var->name->d_name);
+			if ((isalpha(name[4]) && islower(name[4])) ||
+			    (isalpha(name[5]) && islower(name[5])) ||
+			    (isalpha(name[6]) && islower(name[6])) ||
+			    (isalpha(name[7]) && islower(name[7])))
+				fprintf(stderr, "** Warning ** : %s is not "
+				        "EFI 1.10 compliant\n", name);
+		}
 	}
 }
 
@@ -528,7 +560,7 @@
 	int i;
 	printf("BootOrder: ");
 	for (i=0; i<length; i++) {
-		printf("%04x", order[i]);
+		printf("%04X", order[i]);
 		if (i < (length-1))
 			printf(",");
 	}
@@ -572,7 +604,7 @@
 {
 	list_t *pos;
 	var_entry_t *boot;
-	char description[80];
+	char description[80], name[9];
 	EFI_LOAD_OPTION *load_option;
 	EFI_DEVICE_PATH *path;
 	char text_path[1024], *p;
@@ -586,7 +618,12 @@
 				load_option->description, sizeof(description));
 		memset(text_path, 0, sizeof(text_path));
 		path = load_option_path(load_option);
-		printf("Boot%04x", boot->num);
+		if (boot->name)
+			snprintf(name, 9, "%s", boot->name->d_name);
+		else
+			snprintf(name, 9, "Boot%04X", boot->num);
+
+		printf("%s", name);
 		if (load_option->attributes & LOAD_OPTION_ACTIVE)
 			printf("* ");
 		else    printf("  ");
@@ -790,7 +827,7 @@
 			opts.delete_boot = 1;
 			break;
 		case 'b':
-			rc = sscanf(optarg, "%x", &num);
+			rc = sscanf(optarg, "%X", &num);
 			if (rc = 1) opts.bootnum = num;
 			break;
 		case 'c':
@@ -920,7 +957,7 @@
 	if (!opts.testfile) {
 		num_boot_names = read_boot_var_names(&boot_names);
 		read_vars(boot_names, num_boot_names, &boot_entry_list);
-		set_var_nums("Boot%04x-%*s", &boot_entry_list);
+		set_var_nums("Boot%04X-%*s", &boot_entry_list);
 
 		if (opts.delete_boot) {
 			if (opts.bootnum = -1)
@@ -972,11 +1009,11 @@
 		if (!opts.quiet) {
 			num = read_boot_u16("BootNext");
 			if (num != -1 ) {
-				printf("BootNext: %04x\n", num);
+				printf("BootNext: %04X\n", num);
 			}
 			num = read_boot_u16("BootCurrent");
 			if (num != -1) {
-				printf("BootCurrent: %04x\n", num);
+				printf("BootCurrent: %04X\n", num);
 			}
 			num = read_boot_u16("Timeout");
 			if (num != -1) {



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: efibootmgr fixes for EFI 1.10
  2005-03-01 23:22 efibootmgr fixes for EFI 1.10 Alex Williamson
@ 2005-03-01 23:51 ` Andreas Schwab
  2005-03-01 23:57 ` Alex Williamson
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Andreas Schwab @ 2005-03-01 23:51 UTC (permalink / raw)
  To: linux-ia64

Alex Williamson <alex.williamson@hp.com> writes:

> @@ -215,8 +217,9 @@
>  			boot->var_data.Data;
>  		if (!efichar_char_strcmp(opts.label,
>  					 load_option->description)) {
> -			fprintf(stderr, "** Warning ** : Boot%04x has same label %s\n",
> -			       boot->num,
> +			snprintf(name, 9, "%s", boot->name->d_name);
> +			fprintf(stderr, "** Warning ** : %s has same label %s\n",
> +			       name,

What's wrong with using boot->name->d_name directly?

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: efibootmgr fixes for EFI 1.10
  2005-03-01 23:22 efibootmgr fixes for EFI 1.10 Alex Williamson
  2005-03-01 23:51 ` Andreas Schwab
@ 2005-03-01 23:57 ` Alex Williamson
  2005-03-02  0:01 ` Andreas Schwab
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Alex Williamson @ 2005-03-01 23:57 UTC (permalink / raw)
  To: linux-ia64

On Wed, 2005-03-02 at 00:51 +0100, Andreas Schwab wrote:
> Alex Williamson <alex.williamson@hp.com> writes:
> 
> > @@ -215,8 +217,9 @@
> >  			boot->var_data.Data;
> >  		if (!efichar_char_strcmp(opts.label,
> >  					 load_option->description)) {
> > -			fprintf(stderr, "** Warning ** : Boot%04x has same label %s\n",
> > -			       boot->num,
> > +			snprintf(name, 9, "%s", boot->name->d_name);
> > +			fprintf(stderr, "** Warning ** : %s has same label %s\n",
> > +			       name,
> 
> What's wrong with using boot->name->d_name directly?

   Then you get something like this printed:

** Warning ** : BootFFFF-8be4df61-93ca-11d2-aa0d-00e098032b8c has same label Linux

Seemed like too much information.  Thanks,

	Alex
-- 
Alex Williamson                             HP Linux & Open Source Lab


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: efibootmgr fixes for EFI 1.10
  2005-03-01 23:22 efibootmgr fixes for EFI 1.10 Alex Williamson
  2005-03-01 23:51 ` Andreas Schwab
  2005-03-01 23:57 ` Alex Williamson
@ 2005-03-02  0:01 ` Andreas Schwab
  2005-03-02  0:03 ` Alex Williamson
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Andreas Schwab @ 2005-03-02  0:01 UTC (permalink / raw)
  To: linux-ia64

Alex Williamson <alex.williamson@hp.com> writes:

>    Then you get something like this printed:
>
> ** Warning ** : BootFFFF-8be4df61-93ca-11d2-aa0d-00e098032b8c has same label Linux
>
> Seemed like too much information.  Thanks,

Then use %.8s.  Likewise for all other occurences of the same theme.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: efibootmgr fixes for EFI 1.10
  2005-03-01 23:22 efibootmgr fixes for EFI 1.10 Alex Williamson
                   ` (2 preceding siblings ...)
  2005-03-02  0:01 ` Andreas Schwab
@ 2005-03-02  0:03 ` Alex Williamson
  2005-03-07 19:29 ` Thibaut VARENE
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Alex Williamson @ 2005-03-02  0:03 UTC (permalink / raw)
  To: linux-ia64

On Wed, 2005-03-02 at 01:01 +0100, Andreas Schwab wrote:
> Alex Williamson <alex.williamson@hp.com> writes:
> 
> >    Then you get something like this printed:
> >
> > ** Warning ** : BootFFFF-8be4df61-93ca-11d2-aa0d-00e098032b8c has same label Linux
> >
> > Seemed like too much information.  Thanks,
> 
> Then use %.8s.  Likewise for all other occurences of the same theme.

  D'oh, thanks.  I'll fix those.

	Alex

-- 
Alex Williamson                             HP Linux & Open Source Lab


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: efibootmgr fixes for EFI 1.10
  2005-03-01 23:22 efibootmgr fixes for EFI 1.10 Alex Williamson
                   ` (3 preceding siblings ...)
  2005-03-02  0:03 ` Alex Williamson
@ 2005-03-07 19:29 ` Thibaut VARENE
  2005-03-07 21:08 ` Alex Williamson
  2005-03-08  0:24 ` Alex Williamson
  6 siblings, 0 replies; 8+ messages in thread
From: Thibaut VARENE @ 2005-03-07 19:29 UTC (permalink / raw)
  To: linux-ia64

On Tue, 01 Mar 2005 17:03:31 -0700
Alex Williamson <alex.williamson@hp.com> wrote:

> On Wed, 2005-03-02 at 01:01 +0100, Andreas Schwab wrote:
> > Alex Williamson <alex.williamson@hp.com> writes:
> > 
> > >    Then you get something like this printed:
> > >
> > > ** Warning ** : BootFFFF-8be4df61-93ca-11d2-aa0d-00e098032b8c has
> > > same label Linux
> > >
> > > Seemed like too much information.  Thanks,
> > 
> > Then use %.8s.  Likewise for all other occurences of the same theme.
> 
>   D'oh, thanks.  I'll fix those.

Hi

I'd be quite interested in having these changes into Ubuntu (and possibly
into Debian as well, assuming Bdale wants them), so I'd like to know
whether you have updated version of that patch you're happy with?

Thx

Thibaut VARENE
The PA/Linux ESIEE Team
http://www.pateam.org/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: efibootmgr fixes for EFI 1.10
  2005-03-01 23:22 efibootmgr fixes for EFI 1.10 Alex Williamson
                   ` (4 preceding siblings ...)
  2005-03-07 19:29 ` Thibaut VARENE
@ 2005-03-07 21:08 ` Alex Williamson
  2005-03-08  0:24 ` Alex Williamson
  6 siblings, 0 replies; 8+ messages in thread
From: Alex Williamson @ 2005-03-07 21:08 UTC (permalink / raw)
  To: linux-ia64

On Mon, 2005-03-07 at 20:29 +0100, Thibaut VARENE wrote:

> I'd be quite interested in having these changes into Ubuntu (and possibly
> into Debian as well, assuming Bdale wants them), so I'd like to know
> whether you have updated version of that patch you're happy with?

   Yep, meant to mail it out last week, but kept forgetting.  Here's the
patch with fixes per Andreas' comments.  I think it's good to go.
Thanks,

	Alex

-- 
Alex Williamson                             HP Linux & Open Source Lab

--- efibootmgr-0.5.0/src/lib/efi.c	2005-02-28 16:00:18.782889342 -0700
+++ efibootmgr-0.5.0/src/lib/efi.c	2005-03-01 13:45:11.947945876 -0700
@@ -20,6 +20,7 @@
 
 #define _FILE_OFFSET_BITS 64
 
+#include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -171,9 +172,12 @@
 static int
 select_boot_var_names(const struct dirent *d)
 {
-	int num, rc;
-	rc = sscanf(d->d_name, "Boot0%03x-%*s", &num);
-	return rc;
+	if (!strncmp(d->d_name, "Boot", 4) &&
+	    isxdigit(d->d_name[4]) && isxdigit(d->d_name[5]) &&
+	    isxdigit(d->d_name[6]) && isxdigit(d->d_name[7]) &&
+	    d->d_name[8] = '-')
+		return 1;
+	return 0;
 }
 
 int
@@ -716,7 +720,7 @@
 	memset(buffer,    0, sizeof(buffer));
 
 	/* VariableName needs to be BootXXXX */
-	sprintf(buffer, "Boot%04x", free_number);
+	sprintf(buffer, "Boot%04X", free_number);
 
 	efichar_from_char(var->VariableName, buffer, 1024);
 
--- efibootmgr-0.5.0/src/efibootmgr/efibootmgr.c	2005-02-28 16:00:18.802420592 -0700
+++ efibootmgr-0.5.0/src/efibootmgr/efibootmgr.c	2005-03-01 17:16:55.496618382 -0700
@@ -32,6 +32,7 @@
 
 #define _GNU_SOURCE
 
+#include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -215,8 +216,8 @@
 			boot->var_data.Data;
 		if (!efichar_char_strcmp(opts.label,
 					 load_option->description)) {
-			fprintf(stderr, "** Warning ** : Boot%04x has same label %s\n",
-			       boot->num,
+			fprintf(stderr, "** Warning ** : %.8s has same label %s\n",
+			       boot->name->d_name,
 			       opts.label);
 		}
 	}
@@ -228,9 +229,21 @@
 {
 	var_entry_t *boot;
 	int free_number;
+	list_t *pos;
 
-	if (opts.bootnum = -1) free_number = find_free_boot_var(boot_list);
-	else                    free_number = opts.bootnum;
+	if (opts.bootnum = -1)
+		free_number = find_free_boot_var(boot_list);
+	else {
+		list_for_each(pos, boot_list) {
+			boot = list_entry(pos, var_entry_t, list);
+			if (boot->num = opts.bootnum) {
+				fprintf(stderr, "** Warning ** : bootnum %04X "
+				        "already exists\n", opts.bootnum);
+				return NULL;
+			}
+		}
+		free_number = opts.bootnum;
+	}
 
 	if (free_number = -1) return NULL;
 
@@ -398,13 +411,20 @@
 	list_t *pos, *n;
 	var_entry_t *boot;
 
-	snprintf(name, sizeof(name), "Boot%04x", num);
+	snprintf(name, sizeof(name), "Boot%04X", num);
 	memset(&var, 0, sizeof(var));
 	fill_var(&var, name);
 	status = delete_variable(&var);
 
-	if (status) return status;
+	/* For backwards compatibility, try to delete abcdef entries as well */
+	if (status) {
+		snprintf(name, sizeof(name), "Boot%04x", num);
+		memset(&var, 0, sizeof(var));
+		fill_var(&var, name);
+		status = delete_variable(&var);
+	}
 
+	if (status) return status;
 	list_for_each_safe(pos, n, &boot_entry_list) {
 		boot = list_entry(pos, var_entry_t, list);
 		if (boot->num = num) {
@@ -424,11 +444,21 @@
 	list_t *pos;
 	var_entry_t *var;
 	int num=0, rc;
+	char *name;
 
 	list_for_each(pos, list) {
 		var = list_entry(pos, var_entry_t, list);
 		rc = sscanf(var->name->d_name, pattern, &num);
-		if (rc = 1) var->num = num;
+		if (rc = 1) {
+			var->num = num;
+			name = var->name->d_name; /* shorter name */
+			if ((isalpha(name[4]) && islower(name[4])) ||
+			    (isalpha(name[5]) && islower(name[5])) ||
+			    (isalpha(name[6]) && islower(name[6])) ||
+			    (isalpha(name[7]) && islower(name[7])))
+				fprintf(stderr, "** Warning ** : %.8s is not "
+				        "EFI 1.10 compliant\n", name);
+		}
 	}
 }
 
@@ -528,7 +558,7 @@
 	int i;
 	printf("BootOrder: ");
 	for (i=0; i<length; i++) {
-		printf("%04x", order[i]);
+		printf("%04X", order[i]);
 		if (i < (length-1))
 			printf(",");
 	}
@@ -586,7 +616,11 @@
 				load_option->description, sizeof(description));
 		memset(text_path, 0, sizeof(text_path));
 		path = load_option_path(load_option);
-		printf("Boot%04x", boot->num);
+		if (boot->name)
+			printf("%.8s", boot->name->d_name);
+		else
+			printf("Boot%04X", boot->num);
+
 		if (load_option->attributes & LOAD_OPTION_ACTIVE)
 			printf("* ");
 		else    printf("  ");
@@ -790,7 +824,7 @@
 			opts.delete_boot = 1;
 			break;
 		case 'b':
-			rc = sscanf(optarg, "%x", &num);
+			rc = sscanf(optarg, "%X", &num);
 			if (rc = 1) opts.bootnum = num;
 			break;
 		case 'c':
@@ -920,7 +954,7 @@
 	if (!opts.testfile) {
 		num_boot_names = read_boot_var_names(&boot_names);
 		read_vars(boot_names, num_boot_names, &boot_entry_list);
-		set_var_nums("Boot%04x-%*s", &boot_entry_list);
+		set_var_nums("Boot%04X-%*s", &boot_entry_list);
 
 		if (opts.delete_boot) {
 			if (opts.bootnum = -1)
@@ -972,11 +1006,11 @@
 		if (!opts.quiet) {
 			num = read_boot_u16("BootNext");
 			if (num != -1 ) {
-				printf("BootNext: %04x\n", num);
+				printf("BootNext: %04X\n", num);
 			}
 			num = read_boot_u16("BootCurrent");
 			if (num != -1) {
-				printf("BootCurrent: %04x\n", num);
+				printf("BootCurrent: %04X\n", num);
 			}
 			num = read_boot_u16("Timeout");
 			if (num != -1) {



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: efibootmgr fixes for EFI 1.10
  2005-03-01 23:22 efibootmgr fixes for EFI 1.10 Alex Williamson
                   ` (5 preceding siblings ...)
  2005-03-07 21:08 ` Alex Williamson
@ 2005-03-08  0:24 ` Alex Williamson
  6 siblings, 0 replies; 8+ messages in thread
From: Alex Williamson @ 2005-03-08  0:24 UTC (permalink / raw)
  To: linux-ia64

[I sent this earlier, but it seems to have gotten lost, sorry for dups]

On Mon, 2005-03-07 at 20:29 +0100, Thibaut VARENE wrote:

> I'd be quite interested in having these changes into Ubuntu (and possibly
> into Debian as well, assuming Bdale wants them), so I'd like to know
> whether you have updated version of that patch you're happy with?

   Yep, meant to mail it out last week, but kept forgetting.  Here's the
patch with fixes per Andreas' comments.  I think it's good to go.
Thanks,

        Alex
-- 
Alex Williamson                             HP Linux & Open Source Lab

--- efibootmgr-0.5.0/src/lib/efi.c	2005-02-28 16:00:18.782889342 -0700
+++ efibootmgr-0.5.0/src/lib/efi.c	2005-03-01 13:45:11.947945876 -0700
@@ -20,6 +20,7 @@
 
 #define _FILE_OFFSET_BITS 64
 
+#include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -171,9 +172,12 @@
 static int
 select_boot_var_names(const struct dirent *d)
 {
-	int num, rc;
-	rc = sscanf(d->d_name, "Boot0%03x-%*s", &num);
-	return rc;
+	if (!strncmp(d->d_name, "Boot", 4) &&
+	    isxdigit(d->d_name[4]) && isxdigit(d->d_name[5]) &&
+	    isxdigit(d->d_name[6]) && isxdigit(d->d_name[7]) &&
+	    d->d_name[8] = '-')
+		return 1;
+	return 0;
 }
 
 int
@@ -716,7 +720,7 @@
 	memset(buffer,    0, sizeof(buffer));
 
 	/* VariableName needs to be BootXXXX */
-	sprintf(buffer, "Boot%04x", free_number);
+	sprintf(buffer, "Boot%04X", free_number);
 
 	efichar_from_char(var->VariableName, buffer, 1024);
 
--- efibootmgr-0.5.0/src/efibootmgr/efibootmgr.c	2005-02-28 16:00:18.802420592 -0700
+++ efibootmgr-0.5.0/src/efibootmgr/efibootmgr.c	2005-03-01 17:16:55.496618382 -0700
@@ -32,6 +32,7 @@
 
 #define _GNU_SOURCE
 
+#include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -215,8 +216,8 @@
 			boot->var_data.Data;
 		if (!efichar_char_strcmp(opts.label,
 					 load_option->description)) {
-			fprintf(stderr, "** Warning ** : Boot%04x has same label %s\n",
-			       boot->num,
+			fprintf(stderr, "** Warning ** : %.8s has same label %s\n",
+			       boot->name->d_name,
 			       opts.label);
 		}
 	}
@@ -228,9 +229,21 @@
 {
 	var_entry_t *boot;
 	int free_number;
+	list_t *pos;
 
-	if (opts.bootnum = -1) free_number = find_free_boot_var(boot_list);
-	else                    free_number = opts.bootnum;
+	if (opts.bootnum = -1)
+		free_number = find_free_boot_var(boot_list);
+	else {
+		list_for_each(pos, boot_list) {
+			boot = list_entry(pos, var_entry_t, list);
+			if (boot->num = opts.bootnum) {
+				fprintf(stderr, "** Warning ** : bootnum %04X "
+				        "already exists\n", opts.bootnum);
+				return NULL;
+			}
+		}
+		free_number = opts.bootnum;
+	}
 
 	if (free_number = -1) return NULL;
 
@@ -398,13 +411,20 @@
 	list_t *pos, *n;
 	var_entry_t *boot;
 
-	snprintf(name, sizeof(name), "Boot%04x", num);
+	snprintf(name, sizeof(name), "Boot%04X", num);
 	memset(&var, 0, sizeof(var));
 	fill_var(&var, name);
 	status = delete_variable(&var);
 
-	if (status) return status;
+	/* For backwards compatibility, try to delete abcdef entries as well */
+	if (status) {
+		snprintf(name, sizeof(name), "Boot%04x", num);
+		memset(&var, 0, sizeof(var));
+		fill_var(&var, name);
+		status = delete_variable(&var);
+	}
 
+	if (status) return status;
 	list_for_each_safe(pos, n, &boot_entry_list) {
 		boot = list_entry(pos, var_entry_t, list);
 		if (boot->num = num) {
@@ -424,11 +444,21 @@
 	list_t *pos;
 	var_entry_t *var;
 	int num=0, rc;
+	char *name;
 
 	list_for_each(pos, list) {
 		var = list_entry(pos, var_entry_t, list);
 		rc = sscanf(var->name->d_name, pattern, &num);
-		if (rc = 1) var->num = num;
+		if (rc = 1) {
+			var->num = num;
+			name = var->name->d_name; /* shorter name */
+			if ((isalpha(name[4]) && islower(name[4])) ||
+			    (isalpha(name[5]) && islower(name[5])) ||
+			    (isalpha(name[6]) && islower(name[6])) ||
+			    (isalpha(name[7]) && islower(name[7])))
+				fprintf(stderr, "** Warning ** : %.8s is not "
+				        "EFI 1.10 compliant\n", name);
+		}
 	}
 }
 
@@ -528,7 +558,7 @@
 	int i;
 	printf("BootOrder: ");
 	for (i=0; i<length; i++) {
-		printf("%04x", order[i]);
+		printf("%04X", order[i]);
 		if (i < (length-1))
 			printf(",");
 	}
@@ -586,7 +616,11 @@
 				load_option->description, sizeof(description));
 		memset(text_path, 0, sizeof(text_path));
 		path = load_option_path(load_option);
-		printf("Boot%04x", boot->num);
+		if (boot->name)
+			printf("%.8s", boot->name->d_name);
+		else
+			printf("Boot%04X", boot->num);
+
 		if (load_option->attributes & LOAD_OPTION_ACTIVE)
 			printf("* ");
 		else    printf("  ");
@@ -790,7 +824,7 @@
 			opts.delete_boot = 1;
 			break;
 		case 'b':
-			rc = sscanf(optarg, "%x", &num);
+			rc = sscanf(optarg, "%X", &num);
 			if (rc = 1) opts.bootnum = num;
 			break;
 		case 'c':
@@ -920,7 +954,7 @@
 	if (!opts.testfile) {
 		num_boot_names = read_boot_var_names(&boot_names);
 		read_vars(boot_names, num_boot_names, &boot_entry_list);
-		set_var_nums("Boot%04x-%*s", &boot_entry_list);
+		set_var_nums("Boot%04X-%*s", &boot_entry_list);
 
 		if (opts.delete_boot) {
 			if (opts.bootnum = -1)
@@ -972,11 +1006,11 @@
 		if (!opts.quiet) {
 			num = read_boot_u16("BootNext");
 			if (num != -1 ) {
-				printf("BootNext: %04x\n", num);
+				printf("BootNext: %04X\n", num);
 			}
 			num = read_boot_u16("BootCurrent");
 			if (num != -1) {
-				printf("BootCurrent: %04x\n", num);
+				printf("BootCurrent: %04X\n", num);
 			}
 			num = read_boot_u16("Timeout");
 			if (num != -1) {



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2005-03-08  0:24 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-03-01 23:22 efibootmgr fixes for EFI 1.10 Alex Williamson
2005-03-01 23:51 ` Andreas Schwab
2005-03-01 23:57 ` Alex Williamson
2005-03-02  0:01 ` Andreas Schwab
2005-03-02  0:03 ` Alex Williamson
2005-03-07 19:29 ` Thibaut VARENE
2005-03-07 21:08 ` Alex Williamson
2005-03-08  0:24 ` Alex Williamson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox