generated from ZigEmbeddedGroup/hardware-support-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.sh
executable file
·98 lines (81 loc) · 2.63 KB
/
generate.sh
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
rm src/chips -rf
cat >src/chips.zig <<EOF
const std = @import("std");
const micro = @import("../deps/microzig/build.zig");
const Chip = micro.Chip;
const Cpu = micro.Cpu;
const MemoryRegion = micro.MemoryRegion;
// Generated file, do not edit.
fn root_dir() []const u8 {
return std.fs.path.dirname(@src().file) orelse ".";
}
EOF
# skip these chips for now, as they have no counterpart in std.Target.avr.cpu
BLACK_LIST="attiny3224 attiny3226 attiny3227 attiny424 attiny426 attiny427 attiny824 attiny826 attiny827 attiny828"
for ATDF in `ls atdf/*/*.atdf`
do
NAME=$(basename $ATDF | sed 's/\.atdf//')
VAR=$(echo $NAME | tr '[:upper:]' '[:lower:]')
if [[ $BLACK_LIST =~ $VAR ]]; then
echo "Skipping $NAME"
continue
fi
GEN_ZIG="chips/$NAME.zig"
regz $ATDF -o src/$GEN_ZIG
if [ $? -ne 0 ]; then
echo "Failed to generate $GEN_ZIG"
rm -f src/$GEN_ZIG
continue
fi
GEN_JSON="chips/$NAME.json"
regz $ATDF -j -o src/$GEN_JSON
if [ $? -ne 0 ]; then
echo "Failed to generate $GEN_JSON"
rm -f src/$GEN_ZIG src/$GEN_JSON
continue
fi
MEM_DECL=$(cat $ATDF | xq | sed "s/@//g;s/-//g" | jq -r '.avrtoolsdevicefile.devices.device.addressspaces.addressspace[].memorysegment|select(.!=null)|if type == "array" then .[] else . end|select(.name=="SRAM" or .name=="IRAM" or .name=="FLASH" or .name=="PROGMEM" or .name=="INTERNAL_SRAM")|"MemoryRegion{ .offset = \(.start), .length = \(.size), .kind = .\(.type) },"|tostring')
if [ $? -ne 0 ]; then
echo "Failed to generate memory declaration for $NAME"
rm -f src/$GEN_ZIG src/$GEN_JSON
continue
fi
if [[ "$MEM_DECL" != *.ram* ]]; then
echo "RAM memory region is missing for $NAME"
rm -f src/$GEN_ZIG src/$GEN_JSON
continue
fi
if [[ "$MEM_DECL" != *.flash* ]]; then
echo "Flash memory region is missing for $NAME"
rm -f src/$GEN_ZIG src/$GEN_JSON
continue
fi
cat >>src/chips.zig <<EOF
pub const $VAR = Chip{
.name = "$NAME",
.cpu = Cpu{
.name = "$NAME",
.source = .{
.path = std.fmt.comptimePrint("{s}/cpu.zig", .{root_dir()}),
},
.target = std.zig.CrossTarget{
.cpu_arch = .avr,
.cpu_model = .{ .explicit = &std.Target.avr.cpu.$VAR },
.os_tag = .freestanding,
.abi = .eabi,
},
},
.memory_regions = &.{
$MEM_DECL
},
.source = .{
.path = root_dir() ++ "/$GEN_ZIG",
},
.json_register_schema = .{
.path = root_dir() ++ "/$GEN_JSON",
},
};
EOF
done
zig fmt src/chips.zig