diff options
| author | Leah Rowe <leah@libreboot.org> | 2023-01-17 10:23:21 +0000 | 
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2023-01-17 10:23:21 +0000 | 
| commit | 8dea350a625c8d8d9fc0835664b50c1e90ca6fd8 (patch) | |
| tree | 5f42267253f25c7aa16f3c12d1ff9d3552f17cd6 | |
| parent | d0fa08d58d8bc4761c77200f159d571c3fd1231c (diff) | |
util/nvmutil: only write parts that are modified
Old behaviour: always write both gbe sections.
New behaviour: only write back what was changed.
| -rw-r--r-- | util/nvmutil/nvmutil.c | 25 | 
1 files changed, 13 insertions, 12 deletions
| diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 33f23899..4acef2fa 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -439,21 +439,22 @@ writeGbeFile(int *fd, const char *filename)  	int partnum;  	errno = 0; -	if (pwrite((*fd), (uint8_t *) gbe[0], SIZE_4KB, 0) != SIZE_4KB) -		err(errno, "%s", filename); -	if (pwrite((*fd), (uint8_t *) gbe[1], SIZE_4KB, SIZE_4KB) != SIZE_4KB) -		err(errno, "%s", filename); -	if (close((*fd))) -		err(errno, "%s", filename); -	if (errno != 0) -		err(errno, "%s", filename); -  	for (partnum = 0; partnum < 2; partnum++) { -		if (nvmPartModified[partnum]) +		if (nvmPartModified[partnum]) {  			printf("Part %d modified\n", partnum); -		else +		} else {  			fprintf (stderr,  				"Part %d NOT modified\n", partnum); +			continue; +		} +		if (pwrite((*fd), (uint8_t *) gbe[partnum], SIZE_4KB, +		    partnum << 12) != SIZE_4KB) +			err(errno, "%s", filename);  	} -	printf("File `%s` successfully modified\n", filename); +	if (close((*fd))) +		err(errno, "%s", filename); +	if (errno != 0) +		err(errno, "%s", filename); + +	printf("File `%s` successfully re-written.\n", filename);  } | 
