Improve read-only partition logic

Not all QCOM devices have a pad partition, so instead use a list of
known firmware partition names.
This commit is contained in:
Tom Marshall 2015-06-12 08:59:17 -07:00
parent ed9ef484c6
commit cfbf436bff
3 changed files with 27 additions and 10 deletions

31
gpt.c
View File

@ -22,7 +22,7 @@
#define MAX_LBSIZE 4096 #define MAX_LBSIZE 4096
#if defined(ANDROID) && defined(QCOM) #if defined(ANDROID) && defined(QCOM)
#define IS_PART_RO(gpt,n) ((n) <= (gpt->pad_idx)) #define IS_PART_RO(gpt,n) ((n) <= (gpt->last_fw_idx))
#else #else
#define IS_PART_RO(gpt,n) (0) #define IS_PART_RO(gpt,n) (0)
#endif #endif
@ -133,6 +133,24 @@ static int gpt_header_is_valid(struct gpt_header *header, uint32_t lbsize)
return 0; return 0;
} }
#if defined(ANDROID) && defined(QCOM)
static const char *firmware_prefixes[] = {
"modem", "sbl", "dbi", "DDR", "aboot", "rpm", "boot", NULL
};
static int gpt_part_is_firmware(struct gpt *gpt, uint32_t idx)
{
const char **entry;
for (entry = firmware_prefixes; *entry; ++entry) {
char name[72/2+1];
gpt_part_name(gpt, idx, name);
if (!strncmp(name, *entry, strlen(*entry))) {
return 1;
}
}
return 0;
}
#endif
int gpt_open(struct gpt *gpt, const char *pathname) int gpt_open(struct gpt *gpt, const char *pathname)
{ {
int fd; int fd;
@ -199,12 +217,6 @@ int gpt_open(struct gpt *gpt, const char *pathname)
gpt->header.ptbl_entry_size > gpt->lbsize) { gpt->header.ptbl_entry_size > gpt->lbsize) {
fprintf(stderr, "W: bad primary gpt\n"); fprintf(stderr, "W: bad primary gpt\n");
} }
gpt->pad_idx = gpt_part_find(gpt, "pad");
if (gpt->pad_idx == GPT_PART_INVALID) {
fprintf(stderr, "no pad found\n");
close(fd);
return -1;
}
#else #else
if (gpt->header.current_lba != 1 || if (gpt->header.current_lba != 1 ||
gpt->header.backup_lba >= gpt->lblen || gpt->header.backup_lba >= gpt->lblen ||
@ -250,6 +262,11 @@ int gpt_open(struct gpt *gpt, const char *pathname)
close(fd); close(fd);
return -1; return -1;
} }
#if defined(ANDROID) && defined(QCOM)
if (gpt_part_is_firmware(gpt, n)) {
gpt->last_fw_idx = n;
}
#endif
gpt->last_used_idx = n; gpt->last_used_idx = n;
} }

2
gpt.h
View File

@ -52,7 +52,7 @@ struct gpt
uint32_t lblen; uint32_t lblen;
struct gpt_header header; struct gpt_header header;
#if defined(ANDROID) && defined(QCOM) #if defined(ANDROID) && defined(QCOM)
uint32_t pad_idx; uint32_t last_fw_idx;
#endif #endif
uint32_t last_used_idx; uint32_t last_used_idx;
struct gpt_partition* partitions[GPT_MAX_PARTITIONS]; struct gpt_partition* partitions[GPT_MAX_PARTITIONS];

View File

@ -233,7 +233,7 @@ static int cmd_firmware_save(struct gpt *gpt, unsigned int argc, const char **ar
all = !strcmp(argv[1], "all"); all = !strcmp(argv[1], "all");
} }
startidx = (all ? 0 : gpt->pad_idx+1); startidx = (all ? 0 : gpt->last_fw_idx+1);
for (idx = startidx; idx <= gpt->last_used_idx; ++idx) { for (idx = startidx; idx <= gpt->last_used_idx; ++idx) {
char name[72/2+1]; char name[72/2+1];
char filename[72/2+4+1]; char filename[72/2+4+1];
@ -268,7 +268,7 @@ static int cmd_firmware_load(struct gpt *gpt, unsigned int argc, const char **ar
all = !strcmp(argv[1], "all"); all = !strcmp(argv[1], "all");
} }
startidx = (all ? 0 : gpt->pad_idx+1); startidx = (all ? 0 : gpt->last_fw_idx+1);
for (idx = startidx; idx <= gpt->last_used_idx; ++idx) { for (idx = startidx; idx <= gpt->last_used_idx; ++idx) {
char name[72/2+1]; char name[72/2+1];
char filename[72/2+4+1]; char filename[72/2+4+1];