Commit Graph

27 Commits

Author SHA1 Message Date
Caleb Connolly
b8d2248914
add a flag to continue when ufs bsg device is missing
For some usecases it is desired to still update the GPT headers even if
the UFS BSG device is missing. Add a new flag which implements this
behaviour.

It isn't made the default because on some platforms this could result in
an unbootable device, there it's preferable to defer to the user by just
bailing out if the UFS BSG device is unavailable.

Signed-off-by: Caleb Connolly <caleb@connolly.tech>
2023-09-27 18:56:43 +01:00
Caleb Connolly
3390f642e3
meson.build: use gnu11 std instead of c11
This fixes a few compilation issues on different platforms (yay C
standards)

Signed-off-by: Caleb Connolly <caleb@connolly.tech>
2023-09-27 18:43:46 +01:00
Caleb Connolly
74fcde7a8e
header fixes 2023-06-26 14:44:24 +01:00
Caleb Connolly
ea34c3f0b9
drop test stub, fix licenses 2023-06-24 01:38:14 +01:00
Caleb Connolly
e9e86efb96
even even more rework, drop zlib dep
Also fix the mark_boot_successful feature which I broke earlier
2023-06-24 01:04:15 +01:00
Caleb Connolly
bca9aa5dd7
more rework, cleanup, port to pure C
The only C++ was for handling discovering and iterating over the
partitions PER block device, this was implemented in a really
overcomplicated way.

Simplify things, port everything over to c11 and drop the libstdc++
requirement entirely.
2023-06-24 00:06:02 +01:00
Caleb Connolly
04f4ac81ea
rework, fixup, cleanup
Allocate gpt_disk on stack, allocate when needed, rather than multiple
times for every partition.

Huge code cleanup, rerun clang-format, etc

Many changes here inspired by Eric's earlier work.
2023-06-23 21:53:30 +01:00
Caleb Connolly
7f852512b6
write out the backup header too
Now that we actually have the real backup header, we can safely write it
out without having the wrong LBA pointers and other such issues that
would come from writing the primary header to the backup header (ask me
how I know)
2023-06-23 17:23:56 +01:00
Caleb Connolly
7a5d5ee40e
make disk->hdr_bak actually be the GPT backup header
I do not know who thought this should be a "backup" copy of the primary
GPT header...
2023-06-23 17:22:39 +01:00
Caleb Connolly
75e30f8d09
Revert "Use scope-based memory management for malloc, free, open, close, etc."
This commit introduced a lot of changes and seems to have caused a few
issues, including breaking crc32 generation. Revert it for now with the
intention to reimplement some of the improvements.

This reverts commit 9d7600df51.
2023-06-23 13:30:08 +01:00
Eric Curtin
20572c1417 Fix segfault originating in get_suffix function
Some callers try to print the return value from here, printf %s NULL,
ends up being a segfault.
2023-05-29 01:27:55 +00:00
Eric Curtin
9d7600df51 Use scope-based memory management for malloc, free, open, close, etc.
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.
2023-05-29 01:26:29 +00:00
Eric Curtin
843aa92266
Change hdr_offset to signed value, so lseek64 return can be checked
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.
2023-05-15 20:28:54 +01:00
Caleb Connolly
e705c38010
add missing linux/limits.h
Needed for PATH_MAX
2023-05-15 20:26:28 +01:00
Caleb Connolly
1752506e75
gitignore: compile_commands.json 2023-05-15 20:25:59 +01:00
alefnode
df63d7c21c Fix to << uint32_t has not been declared >> 2023-05-04 09:15:29 +02:00
Caleb Connolly
77b48f092a Merge branch 'emmc' into 'main'
Support eMMC-backed A/B

See merge request sdm845-mainline/qbootctl!1
2022-09-21 16:25:40 +00:00
Richard Acayan
17ee1b8e65 detect and handle emmc-backed xbl partitions when switching slots 2022-08-31 17:49:18 -04:00
Richard Acayan
c1f24adfb6 properly remove the partition number and separator 2022-08-31 17:10:31 -04:00
Caleb Connolly
50ef0328af
minor cleanups, improve error handling
gracefully handle UFS_BSG not being enabled in the kernel, rather than
putting the device into a semi-bricked state (oops).
2022-06-10 19:18:13 +01:00
Caleb Connolly
487a96f663
gpt-utils: drop unused function
it also called strlcpy which only exists on musl and bionic, dropping it
lets this build on glibc too.
2022-06-05 22:30:34 +01:00
Caleb Connolly
f885e96bd3
Don't fail if slot already marked successful 2022-06-04 16:03:46 +01:00
Caleb Connolly
6fc95a16ee
add root check 2022-06-04 15:57:54 +01:00
Caleb Connolly
4c49647382
cleanup, stub out tests
not sure how best to write tests, probably a larger test framework on
a board farm to test on real devices will be more sensible.
2022-06-04 15:51:22 +01:00
Caleb Connolly
55612452e0
its ALIIIIIIVE
not yet properly tested, but it seems to mostly work just fine. Slot
switching and marking boot as successful at least just work!
2022-06-04 04:42:40 +01:00
Caleb Connolly
b28a87499c
cleanup, still doesn't seem to work
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.
2021-10-10 02:30:13 +01:00
Caleb Connolly
2f5bf10269
initial commit
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.
2021-10-09 23:16:20 +01:00