int load_module(FAR struct binary_s *bin) { FAR struct binfmt_s *binfmt; int ret = -ENOENT; #ifdef CONFIG_DEBUG if (bin && bin->filename) #endif { bdbg("Loading %s\n", bin->filename); /* Disabling pre-emption should be sufficient protection while * accessing the list of registered binary format handlers. */ sched_lock(); /* Traverse the list of registered binary format handlers. Stop * when either (1) a handler recognized and loads the format, or * (2) no handler recognizes the format. */ for (binfmt = g_binfmts; binfmt; binfmt = binfmt->next) { /* Use this handler to try to load the format */ ret = binfmt->load(bin); if (ret == OK) { /* Successfully loaded -- break out with ret == 0 */ bvdbg("Successfully loaded module %s\n", bin->filename); dump_module(bin); break; } } sched_unlock(); } /* This is an end-user function. Return failures via errno */ if (ret < 0) { bdbg("Returning errno %d\n", -ret); errno = -ret; return ERROR; } return OK; }
static int load_absmodule(FAR struct binary_s *bin) { FAR struct binfmt_s *binfmt; int ret = -ENOENT; bdbg("Loading %s\n", bin->filename); /* Disabling pre-emption should be sufficient protection while accessing * the list of registered binary format handlers. */ sched_lock(); /* Traverse the list of registered binary format handlers. Stop * when either (1) a handler recognized and loads the format, or * (2) no handler recognizes the format. */ for (binfmt = g_binfmts; binfmt; binfmt = binfmt->next) { /* Use this handler to try to load the format */ ret = binfmt->load(bin); if (ret == OK) { /* Successfully loaded -- break out with ret == 0 */ bvdbg("Successfully loaded module %s\n", bin->filename); dump_module(bin); break; } } sched_unlock(); return ret; }
int main(int argc, char *argv[]) { FILE *fp = NULL; int i; int modules_loaded; int dither = 0; const char *sample_bank_fn = "sample_bank.bin"; struct pimp_sample_bank master_sample_bank; struct serializer s; pimp_sample_bank_init(&master_sample_bank); serializer_init(&s); modules_loaded = 0; for (i = 1; i < argc; ++i) { const char *arg = argv[i]; if (arg[0] == '-') { if (strlen(arg) < 2) print_usage(); switch (arg[1]) { case 'd': case 'D': dither = 1; break; default: print_usage(); } } else { struct pimp_module *mod; const char *ifn = arg; struct pimp_sample_bank sample_bank; pimp_sample_bank_init(&sample_bank); /* load module */ if (isatty(STDOUT_FILENO)) printf("loading %s...\n", ifn); mod = load_module(ifn, &sample_bank); if (NULL != mod) { char ofn[256]; modules_loaded++; /* generate output filename */ strncpy(ofn, ifn, 256); strncat(ofn, ".bin", 256); /* dump sample data */ merge_samples(&master_sample_bank, &sample_bank, mod); /* dump module */ if (isatty(STDOUT_FILENO)) printf("dumping %s...\n", ofn); dump_module(mod, ofn); } } } if (0 == modules_loaded) { fprintf(stderr, "%s: No input files\n", argv[0]); exit(EXIT_FAILURE); } if (isatty(STDOUT_FILENO)) printf("dumping %s\n", sample_bank_fn); fp = fopen(sample_bank_fn, "wb"); if (NULL == fp) { perror(sample_bank_fn); exit(EXIT_FAILURE); } fwrite(master_sample_bank.data, 1, master_sample_bank.size, fp); fclose(fp); fp = NULL; serializer_deinit(&s); return 0; }