4343
4444bool qdl_debug ;
4545
46- static int detect_type (const char * verb )
46+ static int detect_type (const char * verb , const char * incdir )
4747{
4848 xmlNode * root ;
4949 xmlDoc * doc ;
@@ -57,16 +57,22 @@ static int detect_type(const char *verb)
5757 if (!strcmp (verb , "erase" ))
5858 return QDL_CMD_ERASE ;
5959
60- if (access (verb , F_OK )) {
60+ char * filename = strdup (verb );
61+ resolve_path (& filename , incdir );
62+
63+ if (access (filename , F_OK )) {
6164 ux_err ("%s is not a verb and not a XML file\n" , verb );
65+ free (filename );
6266 return - EINVAL ;
6367 }
6468
65- doc = xmlReadFile (verb , NULL , 0 );
69+ doc = xmlReadFile (filename , NULL , 0 );
6670 if (!doc ) {
6771 ux_err ("failed to parse XML file \"%s\"\n" , verb );
72+ free (filename );
6873 return - EINVAL ;
6974 }
75+ free (filename );
7076
7177 root = xmlDocGetRootElement (doc );
7278 if (!xmlStrcmp (root -> name , (xmlChar * )"patches" )) {
@@ -251,6 +257,7 @@ static int decode_programmer_archive(struct sahara_image *blob, struct sahara_im
251257 * decode_sahara_config() - Attempt to decode a Sahara config XML document
252258 * @blob: Loaded image to be decoded as Sahara config
253259 * @images: List of Sahara images, with @images[0] populated
260+ * @incdir: include directory to be searched for the files specified in the Sahara config
254261 *
255262 * The single blob provided in @images[0] might be a XML blob containing
256263 * a sahara_config document with definitions of the various Sahara images that
@@ -261,7 +268,7 @@ static int decode_programmer_archive(struct sahara_image *blob, struct sahara_im
261268 *
262269 * Returns: 0 if no archive was found, 1 if archive was decoded, -1 on error
263270 */
264- static int decode_sahara_config (struct sahara_image * blob , struct sahara_image * images )
271+ static int decode_sahara_config (struct sahara_image * blob , struct sahara_image * images , const char * incdir )
265272{
266273 char image_path_full [PATH_MAX ];
267274 const char * image_path ;
@@ -342,7 +349,7 @@ static int decode_sahara_config(struct sahara_image *blob, struct sahara_image *
342349
343350 free ((void * )image_path );
344351
345- ret = load_sahara_image (image_path_full , & images [image_id ]);
352+ ret = load_sahara_image (image_path_full , & images [image_id ], incdir );
346353 if (ret < 0 )
347354 goto err_free_doc ;
348355 }
@@ -370,6 +377,7 @@ static int decode_sahara_config(struct sahara_image *blob, struct sahara_image *
370377 * decode_programmer() - decodes the programmer specifier
371378 * @s: programmer specifier, from the user
372379 * @images: array of images to populate
380+ * @incdir: include directory to be searched for the files specified in @s
373381 *
374382 * This parses the programmer specifier @s, which can either be a single
375383 * filename, or a comma-separated series of <id>:<filename> entries.
@@ -386,7 +394,7 @@ static int decode_sahara_config(struct sahara_image *blob, struct sahara_image *
386394 *
387395 * Returns: 0 on success, -1 otherwise.
388396 */
389- static int decode_programmer (char * s , struct sahara_image * images )
397+ static int decode_programmer (char * s , struct sahara_image * images , const char * incdir )
390398{
391399 struct sahara_image archive ;
392400 char * filename ;
@@ -411,20 +419,20 @@ static int decode_programmer(char *s, struct sahara_image *images)
411419 }
412420
413421 filename = & tail [1 ];
414- ret = load_sahara_image (filename , & images [id ]);
422+ ret = load_sahara_image (filename , & images [id ], incdir );
415423 if (ret < 0 )
416424 return -1 ;
417425 }
418426 } else {
419- ret = load_sahara_image (s , & archive );
427+ ret = load_sahara_image (s , & archive , incdir );
420428 if (ret < 0 )
421429 return -1 ;
422430
423431 ret = decode_programmer_archive (& archive , images );
424432 if (ret < 0 || ret == 1 )
425433 return ret ;
426434
427- ret = decode_sahara_config (& archive , images );
435+ ret = decode_sahara_config (& archive , images , incdir );
428436 if (ret < 0 || ret == 1 )
429437 return ret ;
430438
@@ -695,18 +703,18 @@ static int qdl_flash(int argc, char **argv)
695703 if (qdl_debug )
696704 print_version ();
697705
698- ret = decode_programmer (argv [optind ++ ], sahara_images );
706+ ret = decode_programmer (argv [optind ++ ], sahara_images , incdir );
699707 if (ret < 0 )
700708 goto out_cleanup ;
701709
702710 do {
703- type = detect_type (argv [optind ]);
711+ type = detect_type (argv [optind ], incdir );
704712 if (type < 0 || type == QDL_FILE_UNKNOWN )
705713 errx (1 , "failed to detect file type of %s\n" , argv [optind ]);
706714
707715 switch (type ) {
708716 case QDL_FILE_PATCH :
709- ret = patch_load (argv [optind ]);
717+ ret = patch_load (argv [optind ], incdir );
710718 if (ret < 0 )
711719 errx (1 , "patch_load %s failed" , argv [optind ]);
712720 break ;
@@ -728,7 +736,7 @@ static int qdl_flash(int argc, char **argv)
728736 if (storage_type != QDL_STORAGE_UFS )
729737 errx (1 , "attempting to load provisioning config when storage isn't \"ufs\"" );
730738
731- ret = ufs_load (argv [optind ], qdl_finalize_provisioning );
739+ ret = ufs_load (argv [optind ], qdl_finalize_provisioning , incdir );
732740 if (ret < 0 )
733741 errx (1 , "ufs_load %s failed" , argv [optind ]);
734742 break ;
0 commit comments