When built and used with Debian 12, write fails like:
block dev write failed: Bad file descriptor
gpt_set_header: Failed to write back GPT header
gpt_disk_commit: Failed to update primary GPT header
update_slot_attribute: Failed to write back entry for xbl_a
SLOT _a: Failed to mark boot successful
due to the fd beeing closed when entering the write function.
Directly use open() and close() and avoid using a C++ object
for that.
Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
If we are using C++, we might as well use scope-based memory management
for these things, cleaner and less error prone. Also removed
unnecessary gotos.
The lines:
if (instance == PRIMARY_GPT)
hdr_offset = block_size;
else {
hdr_offset = lseek64(fd, 0, SEEK_END) - block_size;
}
if (hdr_offset < 0) {
fprintf(stderr, "%s: Failed to get gpt header offset\n",
__func__);
goto error;
}
are error checked. But previously hdr_offset could never be less than
zero because it was unsigned.
getting attributes work, setting them (e.g. with mark_boot_successful)
doesn't seem to work properly.
The IOCTL required to set the boot LUN doesn't work, some kernel driver
is missing for it.
This is a port of the Android bootctrl HAL and Qualcomms GPT based
implementation for musl/glibc based systems running mainline linux
Currently it doesn't work because the gpt hdr which is read doesn't
seem to have valid data.