Skip to content

Commit 44e7be0

Browse files
quic-bjorandeandersson
authored andcommitted
sahara: Drop "single image" concept
The Sahara implementation was written without understanding of the special meaning of image id #13. As the implementation grew support for multiple images the special casing of "single image" was introduced, and this spread to the calling bodies. Prior to the introduction of multi-programmer platforms this didn't matter, the logic was fairly simple and usage was straight forward. But when a single programmer image is provided on a multi-programmer target "single_image" is true and hence the image id is ignored on the first read, the one provided file is loaded. The typical outcome is that the following SAHARA_END_OF_IMAGE_CMD fails with a message stating "non-successful end-of-image result". Few users draws the conclusion that this is because they didn't provide the appropriate programmers. But 13 is the image id for the programmer, so it should be fine to drop the special logic. This results in a (somewhat) more helpful error message telling the user that an invalid image is being requested. Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
1 parent f32f5eb commit 44e7be0

File tree

5 files changed

+52
-50
lines changed

5 files changed

+52
-50
lines changed

ks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ int main(int argc, char **argv)
134134
return 1;
135135
}
136136

137-
ret = sahara_run(&qdl, mappings, false, NULL, NULL);
137+
ret = sahara_run(&qdl, mappings, NULL, NULL);
138138
if (ret < 0)
139139
return 1;
140140

qdl.c

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ static uint32_t parse_ascii_hex32(const char *s)
149149

150150
/**
151151
* decode_programmer_archive() - Attempt to decode a programmer CPIO archive
152+
* @blob: Loaded image to be decoded as archive
152153
* @images: List of Sahara images, with @images[0] populated
153154
*
154155
* The single blob provided in @images[0] might be a CPIO archive containing
@@ -159,9 +160,8 @@ static uint32_t parse_ascii_hex32(const char *s)
159160
*
160161
* Returns: 0 if no archive was found, 1 if archive was decoded, -1 on error
161162
*/
162-
static int decode_programmer_archive(struct sahara_image *images)
163+
static int decode_programmer_archive(struct sahara_image *blob, struct sahara_image *images)
163164
{
164-
struct sahara_image *blob = &images[0];
165165
struct cpio_newc_header *hdr;
166166
size_t filesize;
167167
size_t namesize;
@@ -235,6 +235,7 @@ static int decode_programmer_archive(struct sahara_image *images)
235235

236236
/**
237237
* decode_sahara_config() - Attempt to decode a Sahara config XML document
238+
* @blob: Loaded image to be decoded as Sahara config
238239
* @images: List of Sahara images, with @images[0] populated
239240
*
240241
* The single blob provided in @images[0] might be a XML blob containing
@@ -246,9 +247,8 @@ static int decode_programmer_archive(struct sahara_image *images)
246247
*
247248
* Returns: 0 if no archive was found, 1 if archive was decoded, -1 on error
248249
*/
249-
static int decode_sahara_config(struct sahara_image *images)
250+
static int decode_sahara_config(struct sahara_image *blob, struct sahara_image *images)
250251
{
251-
struct sahara_image *blob = &images[0];
252252
char image_path_full[PATH_MAX];
253253
const char *image_path;
254254
unsigned int image_id;
@@ -344,24 +344,25 @@ static int decode_sahara_config(struct sahara_image *images)
344344
* decode_programmer() - decodes the programmer specifier
345345
* @s: programmer specifier, from the user
346346
* @images: array of images to populate
347-
* @single: legacy single image specifier, for which image id should be ignored
348347
*
349348
* This parses the progammer specifier @s, which can either be a single
350349
* filename, or a comma-separated series of <id>:<filename> entries.
351350
*
352-
* In the first case @images[0] is assigned the provided filename and @single is
353-
* set to true. In the second case, each comma-separated entry will be split on
354-
* ':' and the given <filename> will be assigned to the @image entry indicated
355-
* by the given <id>.
351+
* In the first case an attempt will be made to decode the Sahara archive and
352+
* each programmer part will be loaded into their requestd @images entry. If
353+
* the file isn't an archive @images[SAHARA_ID_EHOSTDL_IMG] is assigned. In the
354+
* second case, each comma-separated entry will be split on ':' and the given
355+
* <filename> will be assigned to the @image entry indicated by the given <id>.
356356
*
357357
* Memory is not allocated for the various strings, instead @s will be modified
358358
* by the tokenizer and pointers to the individual parts will be stored in the
359359
* @images array.
360360
*
361361
* Returns: 0 on success, -1 otherwise.
362362
*/
363-
static int decode_programmer(char *s, struct sahara_image *images, bool *single)
363+
static int decode_programmer(char *s, struct sahara_image *images)
364364
{
365+
struct sahara_image archive;
365366
char *filename;
366367
char *save1;
367368
char *pair;
@@ -387,25 +388,21 @@ static int decode_programmer(char *s, struct sahara_image *images, bool *single)
387388
ret = load_sahara_image(filename, &images[id]);
388389
if (ret < 0)
389390
return -1;
390-
391-
*single = false;
392391
}
393392
} else {
394-
ret = load_sahara_image(s, &images[0]);
393+
ret = load_sahara_image(s, &archive);
395394
if (ret < 0)
396395
return -1;
397396

398-
ret = decode_programmer_archive(images);
399-
if (ret < 0)
400-
return -1;
397+
ret = decode_programmer_archive(&archive, images);
398+
if (ret < 0 || ret == 1)
399+
return ret;
401400

402-
if (!ret) {
403-
ret = decode_sahara_config(images);
404-
if (ret < 0)
405-
return -1;
406-
}
401+
ret = decode_sahara_config(&archive, images);
402+
if (ret < 0 || ret == 1)
403+
return -1;
407404

408-
*single = (ret == 0);
405+
images[SAHARA_ID_EHOSTDL_IMG] = archive;
409406
}
410407

411408
return 0;
@@ -468,7 +465,6 @@ int main(int argc, char **argv)
468465
{
469466
enum qdl_storage_type storage_type = QDL_STORAGE_UFS;
470467
struct sahara_image sahara_images[MAPPING_SZ] = {};
471-
bool single_image = true;
472468
char *incdir = NULL;
473469
char *serial = NULL;
474470
const char *vip_generate_dir = NULL;
@@ -593,7 +589,7 @@ int main(int argc, char **argv)
593589
if (qdl_debug)
594590
print_version();
595591

596-
ret = decode_programmer(argv[optind++], sahara_images, &single_image);
592+
ret = decode_programmer(argv[optind++], sahara_images);
597593
if (ret < 0)
598594
exit(1);
599595

@@ -658,7 +654,7 @@ int main(int argc, char **argv)
658654

659655
qdl->storage_type = storage_type;
660656

661-
ret = sahara_run(qdl, sahara_images, single_image, NULL, NULL);
657+
ret = sahara_run(qdl, sahara_images, NULL, NULL);
662658
if (ret < 0)
663659
goto out_cleanup;
664660

qdl.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
#define MAPPING_SZ 64
3838

39+
#define SAHARA_ID_EHOSTDL_IMG 13
40+
3941
enum QDL_DEVICE_TYPE {
4042
QDL_DEVICE_USB,
4143
QDL_DEVICE_SIM,
@@ -101,7 +103,7 @@ int firehose_run(struct qdl_device *qdl);
101103
int firehose_provision(struct qdl_device *qdl);
102104
int firehose_read_buf(struct qdl_device *qdl, struct read_op *read_op, void *out_buf, size_t out_size);
103105
int sahara_run(struct qdl_device *qdl, const struct sahara_image *images,
104-
bool single_image, const char *ramdump_path,
106+
const char *ramdump_path,
105107
const char *ramdump_filter);
106108
int load_sahara_image(const char *filename, struct sahara_image *image);
107109
void print_hex_dump(const char *prefix, const void *buf, size_t len);

ramdump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ int main(int argc, char **argv)
8585
goto out_cleanup;
8686
}
8787

88-
ret = sahara_run(qdl, NULL, true, ramdump_path, filter);
88+
ret = sahara_run(qdl, NULL, ramdump_path, filter);
8989
if (ret < 0) {
9090
ret = 1;
9191
goto out_cleanup;

sahara.c

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ static void sahara_hello(struct qdl_device *qdl, struct sahara_pkt *pkt)
145145
}
146146

147147
static void sahara_read(struct qdl_device *qdl, struct sahara_pkt *pkt,
148-
const struct sahara_image *images,
149-
bool single_image)
148+
const struct sahara_image *images)
150149
{
151150
const struct sahara_image *image;
152151
unsigned int image_idx;
@@ -159,11 +158,7 @@ static void sahara_read(struct qdl_device *qdl, struct sahara_pkt *pkt,
159158
ux_debug("READ image: %d offset: 0x%x length: 0x%x\n",
160159
pkt->read_req.image, pkt->read_req.offset, pkt->read_req.length);
161160

162-
if (single_image)
163-
image_idx = 0;
164-
else
165-
image_idx = pkt->read_req.image;
166-
161+
image_idx = pkt->read_req.image;
167162
if (image_idx >= MAPPING_SZ || !images[image_idx].ptr) {
168163
ux_err("device requested invalid image: %u\n", image_idx);
169164
sahara_send_reset(qdl);
@@ -185,8 +180,7 @@ static void sahara_read(struct qdl_device *qdl, struct sahara_pkt *pkt,
185180
}
186181

187182
static void sahara_read64(struct qdl_device *qdl, struct sahara_pkt *pkt,
188-
const struct sahara_image *images,
189-
bool single_image)
183+
const struct sahara_image *images)
190184
{
191185
const struct sahara_image *image;
192186
unsigned int image_idx;
@@ -199,11 +193,7 @@ static void sahara_read64(struct qdl_device *qdl, struct sahara_pkt *pkt,
199193
ux_debug("READ64 image: %" PRId64 " offset: 0x%" PRIx64 " length: 0x%" PRIx64 "\n",
200194
pkt->read64_req.image, pkt->read64_req.offset, pkt->read64_req.length);
201195

202-
if (single_image)
203-
image_idx = 0;
204-
else
205-
image_idx = pkt->read64_req.image;
206-
196+
image_idx = pkt->read64_req.image;
207197
if (image_idx >= MAPPING_SZ || !images[image_idx].ptr) {
208198
ux_err("device requested invalid image: %u\n", image_idx);
209199
sahara_send_reset(qdl);
@@ -414,12 +404,26 @@ static void sahara_debug64(struct qdl_device *qdl, struct sahara_pkt *pkt,
414404
sahara_send_reset(qdl);
415405
}
416406

417-
static void sahara_debug_list_images(const struct sahara_image *images, bool single_image)
407+
static bool sahara_has_done_pending_quirk(const struct sahara_image *images)
418408
{
409+
unsigned int count = 0;
419410
int i;
420411

421-
if (single_image)
422-
ux_debug("Sahara image id in read requests will be ignored\n");
412+
/*
413+
* E.g MSM8916 EDL reports done = pending, allow this when one a single
414+
* image is provided, and it's used as SAHARA_ID_EHOSTDL_IMG.
415+
*/
416+
for (i = 0; i < MAPPING_SZ; i++) {
417+
if (images[i].ptr)
418+
count++;
419+
}
420+
421+
return count == 1 && images[SAHARA_ID_EHOSTDL_IMG].ptr;
422+
}
423+
424+
static void sahara_debug_list_images(const struct sahara_image *images)
425+
{
426+
int i;
423427

424428
ux_debug("Sahara images:\n");
425429
for (i = 0; i < MAPPING_SZ; i++) {
@@ -429,7 +433,7 @@ static void sahara_debug_list_images(const struct sahara_image *images, bool sin
429433
}
430434

431435
int sahara_run(struct qdl_device *qdl, const struct sahara_image *images,
432-
bool single_image, const char *ramdump_path,
436+
const char *ramdump_path,
433437
const char *ramdump_filter)
434438
{
435439
struct sahara_pkt *pkt;
@@ -439,7 +443,7 @@ int sahara_run(struct qdl_device *qdl, const struct sahara_image *images,
439443
int n;
440444

441445
if (images)
442-
sahara_debug_list_images(images, single_image);
446+
sahara_debug_list_images(images);
443447

444448
/*
445449
* Don't need to do anything in simulation mode with Sahara,
@@ -466,7 +470,7 @@ int sahara_run(struct qdl_device *qdl, const struct sahara_image *images,
466470
sahara_hello(qdl, pkt);
467471
break;
468472
case SAHARA_READ_DATA_CMD:
469-
sahara_read(qdl, pkt, images, single_image);
473+
sahara_read(qdl, pkt, images);
470474
break;
471475
case SAHARA_END_OF_IMAGE_CMD:
472476
sahara_eoi(qdl, pkt);
@@ -475,14 +479,14 @@ int sahara_run(struct qdl_device *qdl, const struct sahara_image *images,
475479
done = sahara_done(qdl, pkt);
476480

477481
/* E.g MSM8916 EDL reports done = 0 here */
478-
if (single_image)
482+
if (sahara_has_done_pending_quirk(images))
479483
done = true;
480484
break;
481485
case SAHARA_MEM_DEBUG64_CMD:
482486
sahara_debug64(qdl, pkt, ramdump_path, ramdump_filter);
483487
break;
484488
case SAHARA_READ_DATA64_CMD:
485-
sahara_read64(qdl, pkt, images, single_image);
489+
sahara_read64(qdl, pkt, images);
486490
break;
487491
case SAHARA_RESET_RESP_CMD:
488492
assert(pkt->length == SAHARA_RESET_LENGTH);

0 commit comments

Comments
 (0)