diff options
Diffstat (limited to 'lib/efi_loader/efi_variable.c')
| -rw-r--r-- | lib/efi_loader/efi_variable.c | 29 | 
1 files changed, 23 insertions, 6 deletions
| diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c index 28b1aa7505a..e56053194da 100644 --- a/lib/efi_loader/efi_variable.c +++ b/lib/efi_loader/efi_variable.c @@ -125,6 +125,8 @@ static const char *parse_attr(const char *str, u32 *attrp)  		if ((s = prefix(str, "ro"))) {  			attr |= READ_ONLY; +		} else if ((s = prefix(str, "nv"))) { +			attr |= EFI_VARIABLE_NON_VOLATILE;  		} else if ((s = prefix(str, "boot"))) {  			attr |= EFI_VARIABLE_BOOTSERVICE_ACCESS;  		} else if ((s = prefix(str, "run"))) { @@ -427,7 +429,9 @@ efi_status_t EFIAPI efi_set_variable(u16 *variable_name,  	EFI_ENTRY("\"%ls\" %pUl %x %zu %p", variable_name, vendor, attributes,  		  data_size, data); -	if (!variable_name || !vendor) { +	/* TODO: implement APPEND_WRITE */ +	if (!variable_name || !vendor || +	    (attributes & EFI_VARIABLE_APPEND_WRITE)) {  		ret = EFI_INVALID_PARAMETER;  		goto out;  	} @@ -449,15 +453,24 @@ efi_status_t EFIAPI efi_set_variable(u16 *variable_name,  	if (val) {  		parse_attr(val, &attr); +		/* We should not free val */ +		val = NULL;  		if (attr & READ_ONLY) { -			/* We should not free val */ -			val = NULL;  			ret = EFI_WRITE_PROTECTED;  			goto out;  		} + +		/* +		 * attributes won't be changed +		 * TODO: take care of APPEND_WRITE once supported +		 */ +		if (attr != attributes) { +			ret = EFI_INVALID_PARAMETER; +			goto out; +		}  	} -	val = malloc(2 * data_size + strlen("{ro,run,boot}(blob)") + 1); +	val = malloc(2 * data_size + strlen("{ro,run,boot,nv}(blob)") + 1);  	if (!val) {  		ret = EFI_OUT_OF_RESOURCES;  		goto out; @@ -469,12 +482,16 @@ efi_status_t EFIAPI efi_set_variable(u16 *variable_name,  	 * store attributes  	 * TODO: several attributes are not supported  	 */ -	attributes &= (EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS); +	attributes &= (EFI_VARIABLE_NON_VOLATILE | +		       EFI_VARIABLE_BOOTSERVICE_ACCESS | +		       EFI_VARIABLE_RUNTIME_ACCESS);  	s += sprintf(s, "{");  	while (attributes) {  		u32 attr = 1 << (ffs(attributes) - 1); -		if (attr == EFI_VARIABLE_BOOTSERVICE_ACCESS) +		if (attr == EFI_VARIABLE_NON_VOLATILE) +			s += sprintf(s, "nv"); +		else if (attr == EFI_VARIABLE_BOOTSERVICE_ACCESS)  			s += sprintf(s, "boot");  		else if (attr == EFI_VARIABLE_RUNTIME_ACCESS)  			s += sprintf(s, "run"); | 
