forked from fortebit/fortebit-openiot-bossa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
appletgen
executable file
·67 lines (55 loc) · 1.17 KB
/
appletgen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
if [ $# -ne 3 ]; then
echo "Usage: $0 <name> <src dir> <obj dir>"
exit 1;
fi
ARM=$1
SRCDIR=$2
OBJDIR=$3
APPLET=${ARM/%Arm/Applet}
BINFILE=$OBJDIR/$ARM.bin
OBJFILE=$OBJDIR/$ARM.obj
CPPFILE=$SRCDIR/$ARM.cpp
HFILE=$SRCDIR/$ARM.h
SIZE=$(stat -c%s $BINFILE)
if [ ! -f $BINFILE ]; then
echo "$BINFILE does not exist"
exit -1
fi
if [ ! -f $OBJFILE ]; then
echo "$OBJFILE does not exist"
exit -1
fi
# Generate the header file
DEFINE=_$(echo $1 | tr '[:lower:]' '[:upper:]')_H
cat > $HFILE << EOF
// WARNING!!! DO NOT EDIT - FILE GENERATED BY APPLETGEN
#ifndef $DEFINE
#define $DEFINE
#include <stdint.h>
typedef struct
{
EOF
nm -g $OBJFILE | awk '{print " uint32_t "$3";"}' >> $HFILE
cat >> $HFILE << EOF
uint8_t code[$SIZE];
} $1;
#endif // $DEFINE
EOF
# Generate the C file
cat > $CPPFILE << EOF
// WARNING!!! DO NOT EDIT - FILE GENERATED BY APPLETGEN
#include "$ARM.h"
#include "$APPLET.h"
$ARM $APPLET::applet = {
EOF
nm -g $OBJFILE | awk '{print "// "$3"\n0x"$1","}' >> $CPPFILE
cat >> $CPPFILE << EOF
// code
{
EOF
od -t x1 $BINFILE | awk '{for(n=2;n<=NF;n++){printf("0x"$n", ")}if(NF>1)print""}' >> $CPPFILE
cat >> $CPPFILE << EOF
}
};
EOF