@@ -148,13 +148,14 @@ static int program_load_sparse(struct program *program, int fd)
148148 return 0 ;
149149}
150150
151- static int load_program_tag (xmlNode * node , bool is_nand , bool allow_missing , const char * incdir )
151+ static int load_program_tag (xmlNode * node , bool is_nand , bool allow_missing , const char * incdir [], int incdir_count )
152152{
153153 struct program * program ;
154154 char tmp [PATH_MAX ];
155155 int errors = 0 ;
156156 int ret ;
157157 int fd = -1 ;
158+ bool found = false;
158159
159160 program = calloc (1 , sizeof (struct program ));
160161
@@ -184,11 +185,14 @@ static int load_program_tag(xmlNode *node, bool is_nand, bool allow_missing, con
184185 }
185186
186187 if (program -> filename ) {
187- if ( incdir ) {
188- snprintf (tmp , PATH_MAX , "%s/%s" , incdir , program -> filename );
188+ for ( int i = 0 ; i < incdir_count && incdir [ i ]; ++ i ) {
189+ snprintf (tmp , PATH_MAX , "%s/%s" , incdir [ i ] , program -> filename );
189190 if (access (tmp , F_OK ) != -1 ) {
190191 free ((void * )program -> filename );
191192 program -> filename = strdup (tmp );
193+ if (found )
194+ ux_info ("multiple files found for %s, using %s\n" , program -> filename , tmp );
195+ found = true;
192196 }
193197 }
194198
@@ -227,7 +231,7 @@ static int load_program_tag(xmlNode *node, bool is_nand, bool allow_missing, con
227231 return 0 ;
228232}
229233
230- int program_load (const char * program_file , bool is_nand , bool allow_missing , const char * incdir )
234+ int program_load (const char * program_file , bool is_nand , bool allow_missing , const char * incdir [], int incdir_count )
231235{
232236 xmlNode * node ;
233237 xmlNode * root ;
@@ -248,7 +252,7 @@ int program_load(const char *program_file, bool is_nand, bool allow_missing, con
248252 if (!xmlStrcmp (node -> name , (xmlChar * )"erase" ))
249253 errors = load_erase_tag (node , is_nand );
250254 else if (!xmlStrcmp (node -> name , (xmlChar * )"program" ))
251- errors = load_program_tag (node , is_nand , allow_missing , incdir );
255+ errors = load_program_tag (node , is_nand , allow_missing , incdir , incdir_count );
252256 else {
253257 ux_err ("unrecognized tag \"%s\" in program-type file \"%s\"\n" , node -> name , program_file );
254258 errors = - EINVAL ;
0 commit comments