summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mauderer <christian.mauderer@embedded-brains.de>2022-02-14 16:14:32 +0100
committerChristian Mauderer <christian.mauderer@embedded-brains.de>2022-02-14 16:35:31 +0100
commit3c0e4f74f16e840958c0b1a824cb1dfeba8491fa (patch)
tree221e9d3663648c7931b167c0c331d8e47869c813
parentrtems-bsps.ini: Correct spelling of aarch64 (diff)
downloadrtems-tools-3c0e4f74f16e840958c0b1a824cb1dfeba8491fa.tar.bz2
bin2c: Add option for alignment
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.
-rw-r--r--misc/bin2c/rtems-bin2c.c42
1 files 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();
}