[PATCH rtems-tools] bin2c: Add option for alignment

Christian MAUDERER christian.mauderer at embedded-brains.de
Tue Feb 15 14:05:09 UTC 2022


Thanks. I pushed it. I'll update the RTEMS source builder as soon as I 
have tested whether I get the hash right.

Am 14.02.22 um 17:06 schrieb Joel Sherrill:
> I think this looks ok
> 
> On Mon, Feb 14, 2022, 9:44 AM Christian Mauderer 
> <christian.mauderer at embedded-brains.de 
> <mailto:christian.mauderer at embedded-brains.de>> wrote:
> 
>     Sometimes it's useful if structures are aligned. This patch add a
> 
>        -A alignment
> 
>     option. Note that this doesn't check for valid alignments. It accepts
>     any positive number in decimal or hex format. If for example an
>     alignment of 7 is specified, the compiler will complain that it is not a
>     power of 2. But it's not really useful to duplicate this check here.
>     ---
>       misc/bin2c/rtems-bin2c.c | 42 ++++++++++++++++++++++++++++++++++++----
>       1 file changed, 38 insertions(+), 4 deletions(-)
> 
>     diff --git a/misc/bin2c/rtems-bin2c.c b/misc/bin2c/rtems-bin2c.c
>     index 462ecf0..8d0e6a1 100644
>     --- a/misc/bin2c/rtems-bin2c.c
>     +++ b/misc/bin2c/rtems-bin2c.c
>     @@ -42,6 +42,7 @@ int verbose = 0;
>       int zeroterminated = 0;
>       int createC = 1;
>       int createH = 1;
>     +unsigned int align = 0;
> 
>       static void sanitize_file_name(char *p)
>       {
>     @@ -175,11 +176,22 @@ void process(const char *ifname, const char
>     *ofname, const char *forced_name)
>           /* print structure */
>           fprintf(
>             ocfile,
>     -      "%s%sunsigned char %s[] = {\n  ",
>     +      "%s%sunsigned char %s[] ",
>             ((usestatic) ? "static " : ""),
>             ((useconst) ? "const " : ""),
>             buf
>           );
>     +    if (align > 0) {
>     +      fprintf(
>     +        ocfile,
>     +        "__attribute__(( __aligned__(%d) )) ",
>     +        align
>     +      );
>     +    }
>     +    fprintf(
>     +      ocfile,
>     +      "= {\n  "
>     +    );
>           int c, col = 1;
>           while ((c = myfgetc(ifile)) != EOF) {
>             if (col >= 78 - 6) {
>     @@ -238,15 +250,22 @@ void process(const char *ifname, const char
>     *ofname, const char *forced_name)
>           /* print structure */
>           fprintf(
>             ohfile,
>     -      "extern %s%sunsigned char %s[];",
>     +      "extern %s%sunsigned char %s[]",
>             ((usestatic) ? "static " : ""),
>             ((useconst) ? "const " : ""),
>             buf
>           );
>     +    if (align > 0) {
>     +      fprintf(
>     +        ohfile,
>     +        " __attribute__(( __aligned__(%d) ))",
>     +        align
>     +      );
>     +    };
>           /* print sizeof */
>           fprintf(
>             ohfile,
>     -      "\n"
>     +      ";\n"
>             "extern %s%ssize_t %s_size;\n",
>             ((usestatic) ? "static " : ""),
>             ((useconst) ? "const " : ""),
>     @@ -274,7 +293,7 @@ void usage(void)
>       {
>         fprintf(
>            stderr,
>     -     "usage: bin2c [-csvzCH] [-N name] <input_file> <output_file>\n"
>     +     "usage: bin2c [-csvzCH] [-N name] [-A alignment] <input_file>
>     <output_file>\n"
>            "  <input_file> is the binary file to convert\n"
>            "  <output_file> should not have a .c or .h extension\n"
>            "\n"
>     @@ -285,6 +304,7 @@ void usage(void)
>            "  -H - create c-header only\n"
>            "  -C - create c-source file only\n"
>            "  -N - force name of data array\n"
>     +     "  -A - add alignment - parameter can be a hexadecimal or
>     decimal number\n"
>           );
>         exit(1);
>       }
>     @@ -329,6 +349,20 @@ int main(int argc, char **argv)
>             name = argv[1];
>             --argc;
>             ++argv;
>     +    } else if (!strcmp(argv[1], "-A")) {
>     +      --argc;
>     +      ++argv;
>     +      if (argc <= 1) {
>     +        fprintf(stderr, "error: -A needs an alignment\n");
>     +        usage();
>     +      }
>     +      align = strtoul(argv[1], NULL, 0);
>     +      if (align == 0) {
>     +        fprintf(stderr, "error: Couldn't convert argument of -A\n");
>     +        usage();
>     +      }
>     +      --argc;
>     +      ++argv;
>           } else {
>             usage();
>           }
>     -- 
>     2.31.1
> 
>     _______________________________________________
>     devel mailing list
>     devel at rtems.org <mailto:devel at rtems.org>
>     http://lists.rtems.org/mailman/listinfo/devel
>     <http://lists.rtems.org/mailman/listinfo/devel>
> 

-- 
--------------------------------------------
embedded brains GmbH
Herr Christian MAUDERER
Dornierstr. 4
82178 Puchheim
Germany
email: christian.mauderer at embedded-brains.de
phone: +49-89-18 94 741 - 18
fax:   +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/


More information about the devel mailing list