Skip to content

Commit e9c30f9

Browse files
Christophe PriouzeauBernardPuel
authored andcommitted
M33Project: 1.1.0
Change-Id: I790a947c018e4d4c8c50ad06758dc1739d55170b Signed-off-by: Christophe Priouzeau <[email protected]>
1 parent fd1832d commit e9c30f9

File tree

7 files changed

+691
-0
lines changed

7 files changed

+691
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/bin/sh
2+
3+
rproc_class_dir="/sys/class/remoteproc/remoteproc1/"
4+
fmw_dir="/lib/firmware"
5+
project_name=$(basename $(pwd))
6+
# By default the firmware is non secure
7+
fw_type="NonSecure"
8+
9+
usage()
10+
{
11+
# Display Help
12+
echo "start stop the remote processor firmware."
13+
echo
14+
echo "Syntax: ${0} [-t <ns|s|ns_s>] <start|stop>"
15+
echo " -t:"
16+
echo " ns Load a non secure firmware (Default)."
17+
echo " s Load a non secure firmware."
18+
echo " ns_s Load a TF-M + non secure firmwares."
19+
echo
20+
echo " start: Start the firmware."
21+
echo " stop: Stop the firmware."
22+
echo
23+
}
24+
25+
while getopts ":t:" o; do
26+
case "${o}" in
27+
t)
28+
arg_t=${OPTARG}
29+
;;
30+
*)
31+
usage
32+
;;
33+
esac
34+
done
35+
shift $((OPTIND-1))
36+
37+
action=$1
38+
39+
case $action in
40+
start) ;;
41+
42+
stop) ;;
43+
44+
*) echo "`basename ${0}`:usage: start | stop"
45+
printf "\n\033[1;31m Error:\033[0m Invalid Action: \033[1;31m-t $action\033[0m\n\n"
46+
exit 1
47+
;;
48+
esac
49+
50+
rproc_state=`tr -d '\0' < $rproc_class_dir/state`
51+
52+
#################
53+
# Start example #
54+
#################
55+
if [ $action == "start" ]; then
56+
fmw_basename="${project_name}_${fw_type}"
57+
58+
if [ `cat ${rproc_class_dir}/fw_format` = "TEE" ]; then
59+
#The firmware is managed by OP-TEE, it must be signed.
60+
# get the name based depending on firmware present and -t option
61+
fmw_name="`ls lib/firmware/${fmw_basename}_sign.bin`"
62+
if [ -z "${fmw_name}" ]; then
63+
echo "Error: signed firmware ${fmw_basename}_sign.bin cannot be found"
64+
exit 1
65+
fi
66+
fmw_name="`basename ${fmw_name}`"
67+
else
68+
#The firmware is managed by Linux, it must be an ELF.
69+
fmw_name="${fmw_basename}.elf"
70+
if [ -e lib/firmware/${fmw_basename}_stripped.elf ]; then
71+
fmw_name="${fmw_basename}_stripped.elf"
72+
fi
73+
fi
74+
75+
if [ ! -e lib/firmware/${fmw_name} ]; then
76+
echo "Error: signed firmware ${fmw_name} cannot be found"
77+
exit 1
78+
fi
79+
80+
echo "`basename ${0}`: fmw_name=${fmw_name}"
81+
82+
if [ $rproc_state == "running" ]; then
83+
echo "Stopping running fw ..."
84+
echo stop > $rproc_class_dir/state
85+
fi
86+
87+
# Create /lib/firmware directory if not exist
88+
if [ ! -d $fmw_dir ]; then
89+
echo "Create $fmw_dir directory"
90+
mkdir $fmw_dir
91+
fi
92+
93+
# Copy firmware in /lib/firmware
94+
cp lib/firmware/$fmw_name $fmw_dir/
95+
96+
# load and start firmware
97+
echo $fmw_name > $rproc_class_dir/firmware
98+
echo start > $rproc_class_dir/state
99+
fi
100+
101+
################
102+
# Stop example #
103+
################
104+
if [ $action == "stop" ]; then
105+
106+
if [ $rproc_state == "offline" ]; then
107+
echo "Nothing to do, no Cortex-M0 fw is running"
108+
else
109+
echo stop > $rproc_class_dir/state
110+
fi
111+
fi
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#!/bin/sh
2+
3+
rproc_class_dir="/sys/class/remoteproc/remoteproc0/"
4+
fmw_dir="/lib/firmware"
5+
project_name=$(basename $(pwd))
6+
7+
usage()
8+
{
9+
# Display Help
10+
echo "start stop the remote processor firmware."
11+
echo
12+
echo "Syntax: ${0} [-t <ns|s|ns_s>] <start|stop>"
13+
echo " -t:"
14+
echo " ns Load a non secure firmware (Default)."
15+
echo " s Load a non secure firmware."
16+
echo " ns_s Load a TF-M + non secure firmwares."
17+
echo
18+
echo " start: Start the firmware."
19+
echo " stop: Stop the firmware."
20+
echo
21+
}
22+
23+
while getopts ":t:" o; do
24+
case "${o}" in
25+
t)
26+
arg_t=${OPTARG}
27+
;;
28+
*)
29+
usage
30+
;;
31+
esac
32+
done
33+
shift $((OPTIND-1))
34+
35+
if [ -z "${arg_t}" ]; then
36+
# By default the firmware is non secure
37+
fw_type="CM33_NonSecure"
38+
else
39+
case "$arg_t" in
40+
41+
ns)
42+
fw_type="CM33_NonSecure"
43+
;;
44+
45+
s)
46+
fw_type="CM33_Secure"
47+
;;
48+
49+
ns_s)
50+
fw_type="CM33_NonSecure_*"
51+
;;
52+
53+
*)
54+
printf "\n\033[1;31m Error:\033[0m Invalid option: \033[1;31m-t $arg_t\033[0m\n\n"
55+
usage
56+
exit 1
57+
;;
58+
esac
59+
fi
60+
action=$1
61+
62+
case $action in
63+
start) ;;
64+
65+
stop) ;;
66+
67+
*) echo "`basename ${0}`:usage: start | stop"
68+
printf "\n\033[1;31m Error:\033[0m Invalid Action: \033[1;31m-t $action\033[0m\n\n"
69+
exit 1
70+
;;
71+
esac
72+
73+
rproc_state=`tr -d '\0' < $rproc_class_dir/state`
74+
75+
#################
76+
# Start example #
77+
#################
78+
if [ $action == "start" ]; then
79+
fmw_basename="${project_name}_${fw_type}"
80+
81+
if [ `cat ${rproc_class_dir}/fw_format` = "TEE" ]; then
82+
#The firmware is managed by OP-TEE, it must be signed.
83+
# get the name based depending on firmware present and -t option
84+
fmw_name="`ls lib/firmware/${fmw_basename}_sign.bin`"
85+
if [ -z "${fmw_name}" ]; then
86+
echo "Error: signed firmware ${fmw_basename}_sign.bin cannot be found"
87+
exit 1
88+
fi
89+
fmw_name="`basename ${fmw_name}`"
90+
else
91+
#The firmware is managed by Linux, it must be an ELF.
92+
if [ ${fw_type} != "CM33_NonSecure" ]; then
93+
echo "Error: only non secure firmware supported"
94+
exit 1
95+
fi
96+
fmw_name="${fmw_basename}.elf"
97+
if [ -e lib/firmware/${fmw_basename}_stripped.elf ]; then
98+
fmw_name="${fmw_basename}_stripped.elf"
99+
fi
100+
fi
101+
102+
if [ ! -e lib/firmware/${fmw_name} ]; then
103+
echo "Error: signed firmware ${fmw_name} cannot be found"
104+
exit 1
105+
fi
106+
107+
echo "`basename ${0}`: fmw_name=${fmw_name}"
108+
109+
if [ $rproc_state == "running" ]; then
110+
echo "Stopping running fw ..."
111+
echo stop > $rproc_class_dir/state
112+
fi
113+
114+
# Create /lib/firmware directory if not exist
115+
if [ ! -d $fmw_dir ]; then
116+
echo "Create $fmw_dir directory"
117+
mkdir $fmw_dir
118+
fi
119+
120+
# Copy firmware in /lib/firmware
121+
cp lib/firmware/$fmw_name $fmw_dir/
122+
123+
# load and start firmware
124+
echo $fmw_name > $rproc_class_dir/firmware
125+
echo start > $rproc_class_dir/state
126+
fi
127+
128+
################
129+
# Stop example #
130+
################
131+
if [ $action == "stop" ]; then
132+
133+
if [ $rproc_state == "offline" ]; then
134+
echo "Nothing to do, no Cortex-M fw is running"
135+
else
136+
echo stop > $rproc_class_dir/state
137+
fi
138+
fi
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/sh -
2+
3+
# test if we are a stm32mp2
4+
if ! $(grep -q "stm32mp2" /proc/device-tree/compatible) ;
5+
then
6+
exit 0
7+
fi
8+
9+
case $1 in
10+
halt)
11+
# action to do in case of halt
12+
/sbin/st-m33firmware-load-default.sh stop
13+
;;
14+
poweroff)
15+
# action to do in case of poweroff
16+
/sbin/st-m33firmware-load-default.sh stop
17+
;;
18+
reboot)
19+
# action to do in case of reboot
20+
;;
21+
kexec)
22+
# action to do in case of kexec (for crashdump on memory)
23+
;;
24+
esac
25+
exit 0
26+
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/bin/sh -
2+
3+
autodetect_board() {
4+
if [ ! -d /proc/device-tree/ ];
5+
then
6+
echo "Proc Device tree are not available, Could not detect on which board we are" > /dev/kmsg
7+
exit 1
8+
fi
9+
10+
LIST="##BOARDS_LIST##"
11+
board=""
12+
for b in $LIST; do
13+
board_lower=$(echo $b | tr '[:upper:]' '[:lower:]')
14+
comp_board=$(tr -d '\0' < /proc/device-tree/compatible | sed "s|st,|,|g" | cut -d ',' -f2 | head -n 1 |tr '\n' ' ' | sed "s/ //g")
15+
if [ "$comp_board" = "$board_lower" ];
16+
then
17+
echo "Board $board_lower is compatible"
18+
board=$b
19+
break
20+
fi
21+
done
22+
if [ -z "$board" ]; then
23+
echo "Board is not a valid BOARD (stm32mp257f-dk, stm32mp257f-ev1)" > /dev/kmsg
24+
exit 0
25+
fi
26+
}
27+
28+
find_default_project() {
29+
DEFAULT_PROJECT=""
30+
if [ -n "$board" ]; then
31+
if [ -z "$(find @userfs_mount_point@ -name default.$board)" ]; then
32+
echo "The default copro example for ${board} doesn't exist" > /dev/kmsg
33+
exit 1
34+
else
35+
default_path_project=$(find @userfs_mount_point@/ -name default.$board | head -n 1)
36+
DEFAULT_PROJECT=$(dirname $default_path_project)
37+
fi
38+
fi
39+
}
40+
41+
firmware_load_start() {
42+
if [ -n "$DEFAULT_PROJECT" ]; then
43+
cd $DEFAULT_PROJECT
44+
./fw_cortex_m33.sh start
45+
echo "Booting fw image for ${board}" > /dev/kmsg
46+
fi
47+
}
48+
49+
ucsi_stop_workaround() {
50+
if [ -e /sys/bus/i2c/drivers/ucsi-stm32g0-i2c/ ]; then
51+
if [ -e /sys/bus/i2c/drivers/ucsi-stm32g0-i2c/1-0035 ]; then
52+
echo 1-0035 > /sys/bus/i2c/drivers/ucsi-stm32g0-i2c/unbind
53+
fi
54+
fi
55+
}
56+
57+
firmware_load_stop() {
58+
# Stop the firmware
59+
if [ "$(cat /sys/class/remoteproc/remoteproc0/state)" = "running" ]; then
60+
if [ -n "$DEFAULT_PROJECT" ]; then
61+
cd $DEFAULT_PROJECT
62+
ucsi_stop_workaround
63+
./fw_cortex_m33.sh stop
64+
fi
65+
echo "Stopping fw image ${board}" > /dev/kmsg
66+
else
67+
echo "Default copro already stopped" > /dev/kmsg
68+
fi
69+
}
70+
71+
board=""
72+
autodetect_board
73+
find_default_project
74+
75+
case "$1" in
76+
start)
77+
firmware_load_stop
78+
firmware_load_start
79+
;;
80+
stop)
81+
firmware_load_stop
82+
;;
83+
restart)
84+
firmware_load_stop
85+
firmware_load_start
86+
;;
87+
*)
88+
echo "HELP: $0 [start|stop|restart]"
89+
;;
90+
esac
91+
92+
exit 0
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Unit]
2+
Description=ST Load M33 firmware via remoteproc
3+
After=systemd-modules-load.service
4+
5+
[Service]
6+
Type=oneshot
7+
RemainAfterExit=yes
8+
ExecStart=-/sbin/st-m33firmware-load-default.sh start
9+
ExecStop=-/sbin/st-m33firmware-load-default.sh stop
10+
11+
[Install]
12+
WantedBy=sysinit.target

0 commit comments

Comments
 (0)