X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=buildtools%2Fpmdinfogen%2Fpmdinfogen.c;h=a68d1ea99922319aeaf915a753f6d4ba761820d9;hb=29391fce85133ded6595a635e8b811df23e8c511;hp=96ccbf33bed73290a3821bdfc2399b337f9d7377;hpb=3b29f60f2d584d5086b735e0a6fab518a17eaa1e;p=dpdk.git diff --git a/buildtools/pmdinfogen/pmdinfogen.c b/buildtools/pmdinfogen/pmdinfogen.c index 96ccbf33be..a68d1ea999 100644 --- a/buildtools/pmdinfogen/pmdinfogen.c +++ b/buildtools/pmdinfogen/pmdinfogen.c @@ -1,14 +1,10 @@ -/* Postprocess pmd object files to export hw support +/* SPDX-License-Identifier: GPL-2.0 + * Postprocess pmd object files to export hw support * * Copyright 2016 Neil Horman * Based in part on modpost.c from the linux kernel - * - * This software may be used and distributed according to the terms - * of the GNU General Public License V2, incorporated herein by reference. - * */ -#define _GNU_SOURCE #include #include #include @@ -26,6 +22,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 +36,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 +180,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 +204,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 = @@ -357,10 +380,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; @@ -410,6 +437,8 @@ 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]); if (locate_pmd_entries(&info) < 0)