]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/rm-lld.git/blob - util/cify.sh
if alignment
[keystone-rtos/rm-lld.git] / util / cify.sh
1 #!/bin/sh
2
3 # Copyright (c) 2013, Texas Instruments Incorporated
4 # All rights reserved.
5
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9
10 # *  Redistributions of source code must retain the above copyright
11 #    notice, this list of conditions and the following disclaimer.
12
13 # *  Redistributions in binary form must reproduce the above copyright
14 #    notice, this list of conditions and the following disclaimer in the
15 #    documentation and/or other materials provided with the distribution.
16
17 # *  Neither the name of Texas Instruments Incorporated nor the names of
18 #    its contributors may be used to endorse or promote products derived
19 #    from this software without specific prior written permission.
20
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31 # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
34 # Converts a .dtb file to a C const byte array that can be compiled into
35 # programs utilizing RM that don't have direct access to a file system
36 #
37 NUM_ARGS=5
39 if [ $# -ne $NUM_ARGS ] ; then
40   echo "Usage:"
41   echo "        cify <input .dtb file> <output .c file> <const byte array name>"
42   echo "             <data section name> <cache alignment>"
43   echo " "
44   echo "Example:"
45   echo "        cify test.dtb test.c testArray testArraySect 128"
46   echo "            Creates a C source file containing const char testArray[]"
47   echo "            with the binary data from test.dtb"
48   echo " "
49   echo "            #pragma DATA_SECTION (testArray, \".testArraySect\");"
50   echo "            #pragma DATA_ALIGN (testArray, 128)"
51   echo "            const char testArray[] = {"
52   echo "            ..."
53   echo "            ...padded to the next 128 byte interval"
54   echo "            };"
55   exit 1
56 else
57   echo "#pragma DATA_SECTION ($3, \".$4\");" > $2
58   echo "#pragma DATA_ALIGN ($3, $5)" >> $2
59   echo "const char $3[] = {" >> $2
60   od -tx1 $1 -w1 -v -An | awk '{printf "0x%s,\n",$1}' >> $2
61   bytes=`od  -tx1 $1 -w1 -v -An | wc -l`
62   remainder=$(($bytes%$5))
63   while [ $remainder -lt $5 ]
64   do
65     echo "0x00," >> $2
66     remainder=$(($remainder+1))
67   done
68   echo "};" >> $2
69 fi