1#! /bin/sh
2# Convert binary to binary-text.
3# Command line:
4#     convert-binary-to-text.sh xxx.cl.bin xxx.clx.bin
5#
6# Usage of binary-text file (if needed):
7# 1. generate binary file, related script: libxcam/tests/test-binary-kernel
8#    $ test-binary-kernel --src-kernel kernel_demo.cl --bin-kernel kernel_demo.cl.bin --kernel-name kernel_demo
9#
10# 2. generate binary-text file, related script: libxcam/tools/convert-binary-to-text.sh
11#    $ convert-binary-to-text.sh kernel_demo.cl.bin kernel_demo.clx.bin
12#
13# 3. include binary-text file when create image handler, please refer to demo handler:
14#    SmartPtr<CLImageHandler> create_cl_binary_demo_image_handler (SmartPtr<CLContext> &context)
15
16
17BINARY_FILE=$1
18TEXT_FILE=$2
19
20if [ $# -ne 2 ]; then
21    echo "Usage: $0 <binary_file> <text_file>"
22    exit 1
23fi
24
25od -A n -t x1 -v $BINARY_FILE | \
26    gawk '
27    BEGIN { print "{" }
28    {
29        printf "   "
30        for (i = 1; i < NF; i++)
31            { printf " 0x" $i "," }
32        print " 0x" $i ","
33    }
34    END { print "};" }
35    ' > $TEXT_FILE.tmp
36
37ret=$?
38if [ $ret != 0 ]; then
39    echo "Convert $BINARY_FILE to $TEXT_FILE faild"
40    rm -f $TEXT_FILE.tmp
41    exit 1
42fi
43
44mv $TEXT_FILE.tmp $TEXT_FILE
45
46echo "Convert $BINARY_FILE to $TEXT_FILE done"
47