1#!/usr/bin/env bash
2#******************************************************************************
3#  * @attention
4#  *
5#  * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
6#  * All rights reserved.</center></h2>
7#  *
8#  * This software component is licensed by ST under BSD 3-Clause license,
9#  * the "License"; You may not use this file except in compliance with the
10#  * License. You may obtain a copy of the License at:
11#  *                        opensource.org/licenses/BSD-3-Clause
12#  *
13#  ******************************************************************************
14
15echo "regression script started"
16sn_option=""
17if [ $# -eq 1 ]; then
18sn_option="sn=$1"
19fi
20PATH="/C/Program Files/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin/":$PATH
21stm32programmercli="STM32_Programmer_CLI"
22# remove write protection
23secbootadd0=0x180030
24connect="-c port=SWD "$sn_option" mode=UR --hardRst"
25connect_no_reset="-c port=SWD "$sn_option" mode=HotPlug"
26rdp_0="-ob RDP=0xAA TZEN=1"
27remove_bank1_protect="-ob SECWM1_PSTRT=127 SECWM1_PEND=0 WRP1A_PSTRT=127 WRP1A_PEND=0 WRP1B_PSTRT=127 WRP1B_PEND=0"
28remove_bank2_protect="-ob SECWM2_PSTRT=127 SECWM2_PEND=0 WRP2A_PSTRT=127 WRP2A_PEND=0 WRP2B_PSTRT=127 WRP2B_PEND=0"
29erase_all="-e all"
30remove_hdp_protection="-ob HDP1_PEND=0 HDP1EN=0 HDP2_PEND=0 HDP2EN=0"
31default_ob1="-ob SRAM2_RST=0 SECBOOTADD0="$secbootadd0" DBANK=1 SWAP_BANK=0 SECWM1_PSTRT=0 SECWM1_PEND=127"
32default_ob2="-ob SECWM2_PSTRT=0 SECWM2_PEND=127"
33echo "Regression to RDP 0 and  tzen=1"
34$stm32programmercli $connect_no_reset $rdp_0
35echo "Remove bank1 protection and erase all"
36$stm32programmercli $connect $remove_bank1_protect $erase_all
37echo "Remove bank2 protection and erase all"
38$stm32programmercli $connect $remove_bank2_protect $erase_all
39echo "Remove hdp protection"
40$stm32programmercli $connect_no_reset $remove_hdp_protection
41echo "Set default OB 1 (dual bank, swap bank, sram2 reset, secure entry point, bank 1 full secure)"
42$stm32programmercli $connect_no_reset $default_ob1
43echo "Set default OB 2 (bank 2 full secure)"
44$stm32programmercli $connect_no_reset $default_ob2
45echo "regression script Done"
46