-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_rbf.sh
executable file
·74 lines (54 loc) · 1.54 KB
/
load_rbf.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
#!/bin/bash
[ "$EUID" -ne 0 ] && { echo >&2 "run with : sudo $0 $@"; exit 1; }
[ -z $1 ] && { echo >&2 "usage : $0 <rbf_file>"; exit 1; }
export RBF_FILE=$1
export OVL_NAME=load_rbf
[ -f ${RBF_FILE} ] || { echo >&2 "'${RBF_FILE}' is missing!"; exit 1; }
# make sure there is something to program
cat /sys/class/fpga_manager/fpga0/state 2>/dev/null || { echo >&2 "No FPGA manager! Are you running on the DE10?!"; exit 1; }
set -xe
# we need the device tree compiler
if ! hash dtc 2>/dev/null; then
apt update
apt install -y device-tree-compiler
fi
# create device tree overlay config
cat << EOF > ${OVL_NAME}.dtso
/dts-v1/;
/plugin/;
/{
fragment@0 {
target-path = "/soc/base-fpga-region";
__overlay__ {
#address-cells = <1>;
#size-cells = <1>;
firmware-name = "${RBF_FILE}";
};
};
};
EOF
# compile the overlay
dtc -O dtb -o ${OVL_NAME}.dtbo -b 0 -@ ${OVL_NAME}.dtso
# copy the overlay data to /lib/firmware
mkdir -p /lib/firmware
cp ${OVL_NAME}.dtbo /lib/firmware
cp ${RBF_FILE} /lib/firmware
# create config file system
mkdir -p /config
mount -t configfs configfs /config || echo already mounted
# create overlay environment
pushd /config/device-tree/overlays
[ -d ${OVL_NAME} ] && rmdir ${OVL_NAME}
mkdir ${OVL_NAME}
cat ${OVL_NAME}/status
# kick the overlay ; program the FPGA
echo -n "${OVL_NAME}.dtbo" > ${OVL_NAME}/path
cat ${OVL_NAME}/status
# clean up
rmdir ${OVL_NAME}
popd
rm ${OVL_NAME}.dtso ${OVL_NAME}.dtbo
rm /lib/firmware/${OVL_NAME}.dtbo
rm /lib/firmware/${RBF_FILE}
# ok!
echo "DONE!"