mirror of
https://github.com/linux-msm/qbootctl
synced 2024-11-23 14:43:29 +08:00
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).
This commit is contained in:
parent
487a96f663
commit
50ef0328af
@ -39,3 +39,8 @@ qbootctl [-c|-m|-s|-u|-b|-n|-x] [SLOT]
|
||||
## Debugging
|
||||
|
||||
Set `DEBUG` to 1 in `utils.h` to enable debug logging.
|
||||
|
||||
## Documentation
|
||||
|
||||
A more details explanation and a list of devices where qbootctl has been
|
||||
validated can be found [on the postmarketOS wiki](https://wiki.postmarketos.org/wiki/Android_AB_Slots):
|
||||
|
@ -33,6 +33,7 @@
|
||||
|
||||
#include "utils.h"
|
||||
#include "gpt-utils.h"
|
||||
#include "ufs-bsg.h"
|
||||
|
||||
#include "bootctrl.h"
|
||||
|
||||
@ -607,6 +608,10 @@ int set_active_boot_slot(unsigned slot)
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (ufs_bsg_dev_open() < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
//The partition list just contains prefixes(without the _a/_b) of the
|
||||
//partitions that support A/B. In order to get the layout we need the
|
||||
//actual names. To do this we append the slot suffix to every member
|
||||
|
@ -300,8 +300,6 @@ int gpt_utils_set_xbl_boot_partition(enum boot_chain chain)
|
||||
LOGD("%s: setting %s lun as boot lun\n", __func__, boot_dev);
|
||||
|
||||
if (set_boot_lun(boot_lun_id)) {
|
||||
fprintf(stderr, "%s: Failed to set xblbak as boot partition\n",
|
||||
__func__);
|
||||
goto error;
|
||||
}
|
||||
return 0;
|
||||
|
53
ufs-bsg.cpp
53
ufs-bsg.cpp
@ -45,52 +45,30 @@
|
||||
#include "utils.h"
|
||||
#include "ufs-bsg.h"
|
||||
|
||||
// FIXME: replace this with something that actually works
|
||||
// static int get_ufs_bsg_dev(void)
|
||||
// {
|
||||
// DIR *dir;
|
||||
// struct dirent *ent;
|
||||
// int ret = -ENODEV;
|
||||
/* UFS BSG device node */
|
||||
static char ufs_bsg_dev[FNAME_SZ] = "/dev/bsg/ufs-bsg0";
|
||||
|
||||
// if ((dir = opendir ("/dev")) != NULL) {
|
||||
// /* read all the files and directories within directory */
|
||||
// while ((ent = readdir(dir)) != NULL) {
|
||||
// if (!strcmp(ent->d_name, "bsg") ||
|
||||
// !strcmp(ent->d_name, "ufs-bsg0")) {
|
||||
// snprintf(ufs_bsg_dev, FNAME_SZ, "/dev/%s", ent->d_name);
|
||||
// ret = 0;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if (ret)
|
||||
// fprintf(stderr, "could not find the ufs-bsg dev\n");
|
||||
// closedir (dir);
|
||||
// } else {
|
||||
// /* could not open directory */
|
||||
// fprintf(stderr, "could not open /dev (error no: %d)\n", errno);
|
||||
// ret = -EINVAL;
|
||||
// }
|
||||
static int fd_ufs_bsg = 0;
|
||||
|
||||
// return ret;
|
||||
// }
|
||||
|
||||
int ufs_bsg_dev_open(void)
|
||||
int ufs_bsg_dev_open()
|
||||
{
|
||||
int ret;
|
||||
if (!fd_ufs_bsg) {
|
||||
if (fd_ufs_bsg)
|
||||
return 0;
|
||||
|
||||
fd_ufs_bsg = open(ufs_bsg_dev, O_RDWR);
|
||||
ret = errno;
|
||||
if (fd_ufs_bsg < 0) {
|
||||
fprintf(stderr, "Unable to open %s (error no: %d)",
|
||||
ufs_bsg_dev, errno);
|
||||
fprintf(stderr, "Unable to open '%s': %s\n", ufs_bsg_dev,
|
||||
strerror(errno));
|
||||
fprintf(stderr,
|
||||
"Is CONFIG_SCSI_UFS_BSG is enabled in your kernel?\n");
|
||||
fd_ufs_bsg = 0;
|
||||
return ret;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ufs_bsg_dev_close(void)
|
||||
void ufs_bsg_dev_close()
|
||||
{
|
||||
if (fd_ufs_bsg) {
|
||||
close(fd_ufs_bsg);
|
||||
@ -188,9 +166,6 @@ int32_t set_boot_lun(__u8 lun_id)
|
||||
int32_t ret;
|
||||
__u32 boot_lun_id = lun_id;
|
||||
|
||||
// ret = get_ufs_bsg_dev();
|
||||
// if (ret)
|
||||
// return ret;
|
||||
LOGD("Using UFS bsg device: %s\n", ufs_bsg_dev);
|
||||
|
||||
ret = ufs_bsg_dev_open();
|
||||
|
@ -36,11 +36,6 @@
|
||||
|
||||
#define DWORD(b3, b2, b1, b0) htobe32((b3 << 24) | (b2 << 16) | (b1 << 8) | b0)
|
||||
|
||||
/* UFS BSG device node */
|
||||
char ufs_bsg_dev[FNAME_SZ] = "/dev/bsg/ufs-bsg0";
|
||||
|
||||
int fd_ufs_bsg;
|
||||
|
||||
/* UPIU Transaction Codes */
|
||||
enum {
|
||||
UTP_UPIU_NOP_OUT = 0x00,
|
||||
@ -91,4 +86,6 @@ enum query_attr_idn {
|
||||
QUERY_ATTR_IDN_ACTIVE_ICC_LVL = 0x03,
|
||||
};
|
||||
|
||||
int ufs_bsg_dev_open();
|
||||
|
||||
#endif /* __RECOVERY_UFS_BSG_H__ */
|
||||
|
Loading…
Reference in New Issue
Block a user