summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2012-02-19 18:36:57 +0100
committerAmaury Pouly <amaury.pouly@gmail.com>2012-02-19 18:36:57 +0100
commitc483905b9244646e89bc36940da7ea5a65e37392 (patch)
tree4006357666d2a614bce1303df5eeabf4c51d8168
parent2d7a4e9dfaee0fc82561bc19c65647b05ad3e0d5 (diff)
downloadrockbox-c483905b9244646e89bc36940da7ea5a65e37392.tar.gz
rockbox-c483905b9244646e89bc36940da7ea5a65e37392.zip
imxtools: remove most calls to bug/bugp from core library.
It should not exit() anymore on error except on malloc failure. Resource leaks on errors (especially I/O) are quite likely though. Change-Id: I6fcf72fb08fc683468b390d0b8745d31ca982b48
-rw-r--r--utils/imxtools/dbparser.c12
-rw-r--r--utils/imxtools/elftosb.c3
-rw-r--r--utils/imxtools/misc.c28
-rw-r--r--utils/imxtools/misc.h2
-rw-r--r--utils/imxtools/sb.c16
-rw-r--r--utils/imxtools/sbtoelf.c3
6 files changed, 50 insertions, 14 deletions
diff --git a/utils/imxtools/dbparser.c b/utils/imxtools/dbparser.c
index b2027e5ad7..89a63b3767 100644
--- a/utils/imxtools/dbparser.c
+++ b/utils/imxtools/dbparser.c
@@ -460,13 +460,21 @@ struct cmd_file_t *db_parse_file(const char *file)
460 size_t size; 460 size_t size;
461 FILE *f = fopen(file, "r"); 461 FILE *f = fopen(file, "r");
462 if(f == NULL) 462 if(f == NULL)
463 bugp("Cannot open file '%s'", file); 463 {
464 if(g_debug)
465 perror("Cannot open db file");
466 return NULL;
467 }
464 fseek(f, 0, SEEK_END); 468 fseek(f, 0, SEEK_END);
465 size = ftell(f); 469 size = ftell(f);
466 fseek(f, 0, SEEK_SET); 470 fseek(f, 0, SEEK_SET);
467 char *buf = xmalloc(size); 471 char *buf = xmalloc(size);
468 if(fread(buf, size, 1, f) != 1) 472 if(fread(buf, size, 1, f) != 1)
469 bugp("Cannot read file '%s'", file); 473 {
474 if(g_debug)
475 perror("Cannot read db file");
476 return NULL;
477 }
470 fclose(f); 478 fclose(f);
471 479
472 if(g_debug) 480 if(g_debug)
diff --git a/utils/imxtools/elftosb.c b/utils/imxtools/elftosb.c
index 5bd247f27e..43bcf34849 100644
--- a/utils/imxtools/elftosb.c
+++ b/utils/imxtools/elftosb.c
@@ -380,7 +380,8 @@ int main(int argc, char **argv)
380 break; 380 break;
381 case 'k': 381 case 'k':
382 { 382 {
383 add_keys_from_file(optarg); 383 if(!add_keys_from_file(optarg))
384 bug("Cannot keys from %s\n", optarg);
384 break; 385 break;
385 } 386 }
386 case 'z': 387 case 'z':
diff --git a/utils/imxtools/misc.c b/utils/imxtools/misc.c
index abbffbd5ae..a7cc096059 100644
--- a/utils/imxtools/misc.c
+++ b/utils/imxtools/misc.c
@@ -157,18 +157,27 @@ void clear_keys()
157 g_key_array = NULL; 157 g_key_array = NULL;
158} 158}
159 159
160void add_keys_from_file(const char *key_file) 160bool add_keys_from_file(const char *key_file)
161{ 161{
162 int size; 162 int size;
163 FILE *fd = fopen(key_file, "r"); 163 FILE *fd = fopen(key_file, "r");
164 if(fd == NULL) 164 if(fd == NULL)
165 bug("opening key file failed"); 165 {
166 if(g_debug)
167 perror("cannot open key file");
168 return false;
169 }
166 fseek(fd, 0, SEEK_END); 170 fseek(fd, 0, SEEK_END);
167 size = ftell(fd); 171 size = ftell(fd);
168 fseek(fd, 0, SEEK_SET); 172 fseek(fd, 0, SEEK_SET);
169 char *buf = xmalloc(size + 1); 173 char *buf = xmalloc(size + 1);
170 if(fread(buf, 1, size, fd) != (size_t)size) 174 if(fread(buf, 1, size, fd) != (size_t)size)
171 bug("reading key file"); 175 {
176 if(g_debug)
177 perror("Cannot read key file");
178 fclose(fd);
179 return false;
180 }
172 buf[size] = 0; 181 buf[size] = 0;
173 fclose(fd); 182 fclose(fd);
174 183
@@ -180,7 +189,11 @@ void add_keys_from_file(const char *key_file)
180 struct crypto_key_t k; 189 struct crypto_key_t k;
181 /* parse key */ 190 /* parse key */
182 if(!parse_key(&p, &k)) 191 if(!parse_key(&p, &k))
183 bug("invalid key file"); 192 {
193 if(g_debug)
194 printf("invalid key file\n");
195 return false;
196 }
184 if(g_debug) 197 if(g_debug)
185 { 198 {
186 printf("Add key: "); 199 printf("Add key: ");
@@ -189,7 +202,11 @@ void add_keys_from_file(const char *key_file)
189 add_keys(&k, 1); 202 add_keys(&k, 1);
190 /* request at least one space character before next key, or end of file */ 203 /* request at least one space character before next key, or end of file */
191 if(*p != 0 && !isspace(*p)) 204 if(*p != 0 && !isspace(*p))
192 bug("invalid key file"); 205 {
206 if(g_debug)
207 printf("invalid key file\n");
208 return false;
209 }
193 /* skip whitespace */ 210 /* skip whitespace */
194 while(isspace(*p)) 211 while(isspace(*p))
195 p++; 212 p++;
@@ -197,6 +214,7 @@ void add_keys_from_file(const char *key_file)
197 break; 214 break;
198 } 215 }
199 free(buf); 216 free(buf);
217 return true;
200} 218}
201 219
202void print_hex(byte *data, int len, bool newline) 220void print_hex(byte *data, int len, bool newline)
diff --git a/utils/imxtools/misc.h b/utils/imxtools/misc.h
index 7ff9ce545a..4df9bbe957 100644
--- a/utils/imxtools/misc.h
+++ b/utils/imxtools/misc.h
@@ -46,7 +46,7 @@ int convxdigit(char digit, byte *val);
46void print_hex(byte *data, int len, bool newline); 46void print_hex(byte *data, int len, bool newline);
47void add_keys(key_array_t ka, int kac); 47void add_keys(key_array_t ka, int kac);
48bool parse_key(char **str, struct crypto_key_t *key); 48bool parse_key(char **str, struct crypto_key_t *key);
49void add_keys_from_file(const char *key_file); 49bool add_keys_from_file(const char *key_file);
50void print_key(struct crypto_key_t *key, bool newline); 50void print_key(struct crypto_key_t *key, bool newline);
51void clear_keys(); 51void clear_keys();
52 52
diff --git a/utils/imxtools/sb.c b/utils/imxtools/sb.c
index 5e636e99fd..b140df3eb3 100644
--- a/utils/imxtools/sb.c
+++ b/utils/imxtools/sb.c
@@ -122,7 +122,10 @@ static void compute_sb_offsets(struct sb_file_t *sb)
122 sec->sec_size += ROUND_UP(inst->size, BLOCK_SIZE) / BLOCK_SIZE; 122 sec->sec_size += ROUND_UP(inst->size, BLOCK_SIZE) / BLOCK_SIZE;
123 } 123 }
124 else 124 else
125 bug("die on inst %d\n", inst->inst); 125 {
126 if(g_debug)
127 printf("die on inst %d\n", inst->inst);
128 }
126 } 129 }
127 /* we need to make sure next section starts on the right alignment. 130 /* we need to make sure next section starts on the right alignment.
128 * Since each section starts with a boot tag, we thus need to ensure 131 * Since each section starts with a boot tag, we thus need to ensure
@@ -299,7 +302,8 @@ void produce_sb_instruction(struct sb_inst_t *inst,
299 case SB_INST_NOP: 302 case SB_INST_NOP:
300 break; 303 break;
301 default: 304 default:
302 bug("die\n"); 305 if(g_debug)
306 printf("die on invalid inst %d\n", inst->inst);
303 } 307 }
304 cmd->hdr.checksum = instruction_checksum(&cmd->hdr); 308 cmd->hdr.checksum = instruction_checksum(&cmd->hdr);
305} 309}
@@ -438,7 +442,11 @@ enum sb_error_t sb_write_file(struct sb_file_t *sb, const char *filename)
438 write(final_sig, 32); 442 write(final_sig, 32);
439 443
440 if(buf_p - buf != sb_hdr.image_size * BLOCK_SIZE) 444 if(buf_p - buf != sb_hdr.image_size * BLOCK_SIZE)
441 bug("SB image buffer was not entirely filled !"); 445 {
446 if(g_debug)
447 printf("SB image buffer was not entirely filled !");
448 return SB_ERROR;
449 }
442 450
443 FILE *fd = fopen(filename, "wb"); 451 FILE *fd = fopen(filename, "wb");
444 if(fd == NULL) 452 if(fd == NULL)
@@ -833,7 +841,7 @@ struct sb_file_t *sb_read_file(const char *filename, bool raw_mode, void *u,
833 struct crypto_key_t k; 841 struct crypto_key_t k;
834 char *env = getenv("SB_REAL_KEY"); 842 char *env = getenv("SB_REAL_KEY");
835 if(!parse_key(&env, &k) || *env) 843 if(!parse_key(&env, &k) || *env)
836 bug("Invalid SB_REAL_KEY\n"); 844 fatal(SB_ERROR, "Invalid SB_REAL_KEY\n");
837 memcpy(real_key, k.u.key, 16); 845 memcpy(real_key, k.u.key, 16);
838 } 846 }
839 847
diff --git a/utils/imxtools/sbtoelf.c b/utils/imxtools/sbtoelf.c
index fda70b1180..c1d1e9aa34 100644
--- a/utils/imxtools/sbtoelf.c
+++ b/utils/imxtools/sbtoelf.c
@@ -233,7 +233,8 @@ int main(int argc, char **argv)
233 break; 233 break;
234 case 'k': 234 case 'k':
235 { 235 {
236 add_keys_from_file(optarg); 236 if(!add_keys_from_file(optarg))
237 bug("Cannot add keys from %s\n", optarg);
237 break; 238 break;
238 } 239 }
239 case 'z': 240 case 'z':