Skip to content

Commit 551dba5

Browse files
committed
Fix Mav baseband stitching
1 parent 4cf940b commit 551dba5

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/mbn.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,11 @@ void* mbn_stitch(const void* data, size_t data_size, const void* blob, size_t bl
263263

264264
off_t stitch_offset = data_size - blob_size;
265265
if (stitch_offset + blob_size > data_size) {
266-
logger(LL_ERROR, "%s: stitch offset (0x%llx) + size (0x%zx) is larger than the destination (0x%zx)\n", __func__, stitch_offset, blob_size, data_size);
266+
logger(LL_ERROR, "%s: stitch offset (0x%lx) + size (0x%zx) is larger than the destination (0x%zx)\n", __func__, (unsigned long)stitch_offset, blob_size, data_size);
267267
return NULL;
268268
}
269269

270-
void* buf = malloc(data_size);
270+
unsigned char* buf = malloc(data_size);
271271
if (buf == NULL) {
272272
logger(LL_ERROR, "out of memory\n");
273273
return NULL;
@@ -409,7 +409,7 @@ void* mbn_mav25_stitch(const void* data, size_t data_size, const void* blob, siz
409409
}
410410

411411
if (sect_off + sect_size > data_size) {
412-
logger(LL_ERROR, "%s: section (0x%llx+0x%zx) is bigger than the data\n", __func__, sect_off, sect_size);
412+
logger(LL_ERROR, "%s: section (0x%lx+0x%zx) is bigger than the data\n", __func__, (unsigned long)sect_off, sect_size);
413413
return NULL;
414414
}
415415

@@ -442,8 +442,7 @@ void* mbn_mav25_stitch(const void* data, size_t data_size, const void* blob, siz
442442
size_t new_oem_sig_and_cert_chain_size =
443443
src_header->oem_signature_size + src_header->oem_certificate_chain_size;
444444
off_t new_oem_sig_and_cert_chain_off = new_metadata_and_hash_table_size +
445-
header->qti_signature_size +
446-
header->qti_certificate_chain_size;
445+
header->qti_signature_size + header->qti_certificate_chain_size;
447446

448447
if (new_metadata_and_hash_table_size > blob_size) {
449448
logger(LL_ERROR, "%s: new metadata (0x%zx) and hash table (0x%x) are bigger than the source (0x%zx)\n", __func__, new_metadata_size, src_header->hash_table_size, blob_size);
@@ -465,16 +464,16 @@ void* mbn_mav25_stitch(const void* data, size_t data_size, const void* blob, siz
465464
return NULL;
466465
}
467466

468-
void* buf = malloc(data_size);
467+
unsigned char* buf = malloc(data_size);
469468
if (buf == NULL) {
470469
logger(LL_ERROR, "out of memory\n");
471470
return NULL;
472471
}
473472

474473
memcpy(buf, data, data_size);
475-
logger(LL_DEBUG, "%s: stitching mbn at 0x%llx (0x%zx bytes)\n", __func__, sect_off, new_metadata_and_hash_table_size);
474+
logger(LL_DEBUG, "%s: stitching mbn at 0x%lx (0x%zx bytes)\n", __func__, (unsigned long)sect_off, new_metadata_and_hash_table_size);
476475
memcpy(buf + sect_off, blob, new_metadata_and_hash_table_size);
477-
logger(LL_DEBUG, "%s: stitching mbn at 0x%llx (0x%zx bytes)\n", __func__, sect_off + new_oem_sig_and_cert_chain_off, new_oem_sig_and_cert_chain_size);
476+
logger(LL_DEBUG, "%s: stitching mbn at 0x%lx (0x%zx bytes)\n", __func__, (unsigned long)(sect_off + new_oem_sig_and_cert_chain_off), new_oem_sig_and_cert_chain_size);
478477
memcpy(buf + sect_off + new_oem_sig_and_cert_chain_off, blob + new_metadata_and_hash_table_size, new_oem_sig_and_cert_chain_size);
479478

480479
return buf;

src/restore.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,8 +2016,6 @@ static int restore_sign_bbfw(const char* bbfwtmp, plist_t bbtss, const unsigned
20162016
goto leave;
20172017
}
20182018
}
2019-
free(buffer);
2020-
buffer = NULL;
20212019

20222020
blob_size = 0;
20232021
blob = (const unsigned char*)plist_get_data_ptr(node, &blob_size);
@@ -2043,17 +2041,21 @@ static int restore_sign_bbfw(const char* bbfwtmp, plist_t bbtss, const unsigned
20432041
fls = NULL;
20442042
} else if (bb_chip_id == 0x1F30E1) { // Mav25 - Qualcomm Snapdragon X80 5G Modem
20452043
fdata = mbn_mav25_stitch(buffer, zstat.size, blob, (size_t)blob_size);
2044+
fsize = zstat.size;
20462045
if (!fdata) {
20472046
logger(LL_ERROR, "Could not stitch %s\n", signfn);
20482047
goto leave;
20492048
}
20502049
} else {
20512050
fdata = mbn_stitch(buffer, zstat.size, blob, (size_t)blob_size);
2051+
fsize = zstat.size;
20522052
if (!fdata) {
20532053
logger(LL_ERROR, "Could not stitch %s\n", signfn);
20542054
goto leave;
20552055
}
20562056
}
2057+
free(buffer);
2058+
buffer = NULL;
20572059

20582060
zs = zip_source_buffer(za, fdata, fsize, 1);
20592061
if (!zs) {

0 commit comments

Comments
 (0)