X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=buildtools%2Fpmdinfogen%2Fpmdinfogen.c;h=dc0b6d5ff41e908f6f218c2f3454e0405d5383c1;hb=5d7b673d5fd6663b20c675dd382d9fb43b42af18;hp=e1bf2e4617a16911e03f484f25d331a9cb608f0c;hpb=6a4f87f1e76db2633ea237521fe5af9c657a6cd2;p=dpdk.git diff --git a/buildtools/pmdinfogen/pmdinfogen.c b/buildtools/pmdinfogen/pmdinfogen.c index e1bf2e4617..dc0b6d5ff4 100644 --- a/buildtools/pmdinfogen/pmdinfogen.c +++ b/buildtools/pmdinfogen/pmdinfogen.c @@ -8,7 +8,6 @@ * */ -#define _GNU_SOURCE #include #include #include @@ -26,6 +25,7 @@ #define ADDR_SIZE 32 #endif +static int use_stdin, use_stdout; static const char *sym_name(struct elf_info *elf, Elf_Sym *sym) { @@ -39,11 +39,36 @@ static void *grab_file(const char *filename, unsigned long *size) { struct stat st; void *map = MAP_FAILED; - int fd; + int fd = -1; + + if (!use_stdin) { + fd = open(filename, O_RDONLY); + if (fd < 0) + return NULL; + } else { + /* from stdin, use a temporary file to mmap */ + FILE *infile; + char buffer[1024]; + int n; + + infile = tmpfile(); + if (infile == NULL) { + perror("tmpfile"); + return NULL; + } + fd = dup(fileno(infile)); + fclose(infile); + if (fd < 0) + return NULL; + + n = read(STDIN_FILENO, buffer, sizeof(buffer)); + while (n > 0) { + if (write(fd, buffer, n) != n) + goto failed; + n = read(STDIN_FILENO, buffer, sizeof(buffer)); + } + } - fd = open(filename, O_RDONLY); - if (fd < 0) - return NULL; if (fstat(fd, &st)) goto failed; @@ -158,7 +183,8 @@ static int parse_elf(struct elf_info *info, const char *filename) * There are more than 64k sections, * read count from .sh_size. */ - info->num_sections = TO_NATIVE(endian, 32, sechdrs[0].sh_size); + info->num_sections = + TO_NATIVE(endian, ADDR_SIZE, sechdrs[0].sh_size); } else { info->num_sections = hdr->e_shnum; } @@ -181,7 +207,7 @@ static int parse_elf(struct elf_info *info, const char *filename) sechdrs[i].sh_offset = TO_NATIVE(endian, ADDR_SIZE, sechdrs[i].sh_offset); sechdrs[i].sh_size = - TO_NATIVE(endian, 32, sechdrs[i].sh_size); + TO_NATIVE(endian, ADDR_SIZE, sechdrs[i].sh_size); sechdrs[i].sh_link = TO_NATIVE(endian, 32, sechdrs[i].sh_link); sechdrs[i].sh_info = @@ -226,13 +252,14 @@ static int parse_elf(struct elf_info *info, const char *filename) } if (!info->symtab_start) fprintf(stderr, "%s has no symtab?\n", filename); - - /* Fix endianness in symbols */ - for (sym = info->symtab_start; sym < info->symtab_stop; sym++) { - sym->st_shndx = TO_NATIVE(endian, 16, sym->st_shndx); - sym->st_name = TO_NATIVE(endian, 32, sym->st_name); - sym->st_value = TO_NATIVE(endian, ADDR_SIZE, sym->st_value); - sym->st_size = TO_NATIVE(endian, ADDR_SIZE, sym->st_size); + else { + /* Fix endianness in symbols */ + for (sym = info->symtab_start; sym < info->symtab_stop; sym++) { + sym->st_shndx = TO_NATIVE(endian, 16, sym->st_shndx); + sym->st_name = TO_NATIVE(endian, 32, sym->st_name); + sym->st_value = TO_NATIVE(endian, ADDR_SIZE, sym->st_value); + sym->st_size = TO_NATIVE(endian, ADDR_SIZE, sym->st_size); + } } if (symtab_shndx_idx != ~0U) { @@ -269,6 +296,7 @@ struct opt_tag { static const struct opt_tag opt_tags[] = { {"_param_string_export", "params"}, + {"_kmod_dep_export", "kmod"}, }; static int complete_pmd_entry(struct elf_info *info, struct pmd_driver *drv) @@ -325,6 +353,10 @@ static int locate_pmd_entries(struct elf_info *info) do { new = calloc(sizeof(struct pmd_driver), 1); + if (new == NULL) { + fprintf(stderr, "Failed to calloc memory\n"); + return -1; + } new->name_sym = find_sym_in_symtab(info, "this_pmd_name", last); last = new->name_sym; if (!new->name_sym) @@ -351,10 +383,14 @@ static void output_pmd_info_string(struct elf_info *info, char *outfile) struct rte_pci_id *pci_ids; int idx = 0; - ofd = fopen(outfile, "w+"); - if (!ofd) { - fprintf(stderr, "Unable to open output file\n"); - return; + if (use_stdout) + ofd = stdout; + else { + ofd = fopen(outfile, "w+"); + if (!ofd) { + fprintf(stderr, "Unable to open output file\n"); + return; + } } drv = info->drivers; @@ -386,7 +422,7 @@ static void output_pmd_info_string(struct elf_info *info, char *outfile) else fprintf(ofd, " "); } - fprintf(ofd, "]}\";"); + fprintf(ofd, "]}\";\n"); drv = drv->next; } @@ -395,7 +431,7 @@ static void output_pmd_info_string(struct elf_info *info, char *outfile) int main(int argc, char **argv) { - struct elf_info info; + struct elf_info info = {0}; int rc = 1; if (argc < 3) { @@ -404,9 +440,12 @@ int main(int argc, char **argv) basename(argv[0])); exit(127); } + use_stdin = !strcmp(argv[1], "-"); + use_stdout = !strcmp(argv[2], "-"); parse_elf(&info, argv[1]); - locate_pmd_entries(&info); + if (locate_pmd_entries(&info) < 0) + exit(1); if (info.drivers) { output_pmd_info_string(&info, argv[2]);