본문 바로가기

05_Toolkit/AWS_IoT

Ex1. ② STM SECURE BOOT


Ex1. ② STM SECURE BOOT

( 태그 : AWS_IoT_FreeRTOS, AWS_IoT )


Root of Trust 서비스를 시작 하며 저장되어 실행되는 코드는 변경이 불가능 합니다.

Platform 무결성을 검증 합니다. Clock 설정, Register 구성, 메모리 보호 등에 대해 검증 합니다.


1. ‘Secure Boot’ Project


1-1. Secure Boot Feature

  • Secure Boot는 System Reset될 때 실행되는 변경되지 않는 코드 입니다.
  • STM32의 protection을 점검하여 runtime 보호를 활성화 합니다.
  • 애플리케이션 코드의 신뢰성과 무결성을 확인하여 유효하지 않은지 확인하고 악성 코드 실행을 차단 합니다.
  • 보호되고 격리 된 환경에서 실행되는 PKCS #11 API (KEY ID 기반 API)를 통해 사용자 애플리케이션에 암호화 서비스를 제공합니다.
  • 인증 확인, 데이터 복호화 및 데이터 무결성 확인에 사용되는 사용자 애플리케이션 Key는 보호되고 격리 된 환경에 저장됩니다.

1-2. Pre-Build & Post-Build

  • Prebuild 단게에서는 Postbuild를 위해 elf 파일을 제거 합니다.

    • STSAFE-A110과의 pairing key를 생성합니다.
    • Pre-Build script : STM32CubeExpansion_Cloud_AWS_V2.0.0/Projects/B-L4S5I-IOT01A/Applications/BootLoader_STSAFE/2_Image_SECoreBin/STM32CubeIDE/prebuild.sh
  • Postbuild 단게에서는 BootLoader와 Application을 묶어 단일 Image를 생성 합니다.

    • FW Image와 Application에 대한 Header와 encryption된 binary를 생성합니다.
    • Post-Build script : STM32CubeExpansion_Cloud_AWS_V2.0.0/Projects/B-L4S5I-IOT01A/Applications/BootLoader_STSAFE/2_Image_SECoreBin/STM32CubeIDE/postbuild.sh

1-3. Image preparation

  • Windows OS에서는 사전 빌드된 Image Preparation tool을 사용합니다.

    • STM32CubeExapnasion_Cloud_AWS_V2.0.0/Middleware/ST/STM32_Secure_Engine/Utiltities/KeysAndimages/win/ prepareimage.exe
  • MAC이나 Linux OS에서는 Python script로 준비된 Image Preparation 코드를 사용합니다.

    • STM32CubeExapnasion_Cloud_AWS_V2.0.0/Middleware/ST/STM32_Secure_Engine/Utiltities/KeysAndimages/prepareimage.py
  • Secure Boot 동작은 다음과 같이 진행됩니다.


2. Build ‘Secure Boot’ Project

  • B-L4S5I-IOT01_2_Image_SECoreBin’ project를 선택한 후 Build Project를 실행합니다. 이전 Build 산출물을 제거하고 싶으면 Clean Project를 먼저 진행한 후 Build Project를 실행합니다.


  • Build 산출물은 SECoreBin.bin 파일 입니다.
arm-none-eabi-objcopy  -O binary  SECoreBin.elf  "SECoreBin.bin"
Finished building: **SECoreBin.bin**
  • SECoreBin.bin 파일이 저장되는 위치는 ‘STM32CubeExpansion_Cloud_AWS_V2.0.0/Projects/B-L4S5I-IOT01A/Applications/BootLoader_STSAFE/2_Image_SECoreBin/STM32CubeIDE/B-L4S5I-IOT01_2_Image_SECoreBin/Debug/’ 입니다.


3. ‘Secure FW Update’ Project

  • 두 개의 Image area에서 유효한 Image를 확인하여 실행 합니다.
  • FW Upgrade시 Image의 유효한 Key 검증을 진행하게 됩니다.


4. Build ‘Secure FW Update’ Project

  • B-L4S5I-IOT01_2_Image_SBSFU’ project를 선택한 후 Build Project를 실행합니다. 이전 Build 산출물을 제거하고 싶으면 Clean Project를 먼저 진행한 후 Build Project를 실행합니다.


  • Build 산출물은 SBSFU.bin 파일 입니다.
arm-none-eabi-objcopy  -O binary  SBSFU.elf  "SBSFU.bin"
Finished building: **SBSFU.bin**
  • SBSFU.bin 파일이 저장되는 위치는 ‘STM32CubeExpansion_Cloud_AWS_V2.0.0/Projects/B-L4S5I-IOT01A/Applications/BootLoader_STSAFE/2_Image_SBSFU/STM32CubeIDE/B-L4S5I-IOT01_2_Image_SBSFU/Debug/’ 입니다.


5. Programming SBSFU.bin

  • CSTM32CubeProgrammer 우축 상단의 Connect 버튼을 눌러 디바이스를 연결 합니다.
  • Erasing & programming Tab을 선택합니다.
  • Browse 버튼을 눌러 Build한 ‘STM32CubeExpansion_Cloud_AWS_V2.0.0/Projects/B-L4S5I-IOT01A/Applications/BootLoader_STSAFE/2_Image_SBSFU/STM32CubeIDE/B-L4S5I-IOT01_2_Image_SBSFU/Debug/SBSFU.bin’ 파일을 선택합니다.


  • Programming 시작 주소는 기본값인 0x08000000 입니다. 변경하지 않고 유지합니다.
  • Programming option은 Verfiy programming을 선택합니다.
  • Start Programming 버튼을 클릭하여 bin 파일을 writing 합니다.
  • Programming이 완료되면 MCU 보드의 리셋 버튼으로 재 부팅 합니다.
  • Terminal 프로그램을 통해 로그를 확인할 수 있습니다.
= [SBOOT] System Security Check successfully passed. Starting...
= [FWIMG] Slot #0 @: 8105000 / Slot #1 @: 8036000 / Swap @: 81d5000

======================================================================
=              (C) COPYRIGHT 2017 STMicroelectronics                 =
=                                                                    =
=              Secure Boot and Secure Firmware Update                =
======================================================================

= [SBOOT] SECURE ENGINE INITIALIZATION SUCCESSFUL
= [SBOOT] STATE: CHECK STATUS ON RESET
          INFO: A Reboot has been triggered by a Hardware reset!
          Consecutive Boot on error counter = 0
          INFO: Last execution detected error was:No error. Success.
= [SBOOT] STATE: CHECK NEW FIRMWARE TO DOWNLOAD
= [SBOOT] STATE: CHECK KMS BLOB TO INSTALL
= [SBOOT] STATE: CHECK USER FW STATUS
= [SBOOT] LOADING CERTS FROM SECURE ENGINEOK
Check for header at 0x080db000
Check for header at 0x080d0000
Check for header at 0x080c5000
Check for header at 0x080ba000
Check for header at 0x080af000
Check for header at 0x080a4000
Check for header at 0x08099000
Check for header at 0x0808e000
Check for header at 0x08083000
Check for header at 0x08078000
Check for header at 0x0806d000
Check for header at 0x08062000
Check for header at 0x08057000
Check for header at 0x0804c000
Check for header at 0x08041000
Check for header at 0x08036000
Header not found
          No valid FW found in the active slot nor new encrypted FW found in the UserApp download area
          Waiting for the local download to start...
= [SBOOT] STATE: DOWNLOAD NEW USER FIRMWARE
          File> Transfer> YMODEM> Send ....

Build Error Fix

Images_SECoreBin Build Error - MAC OS

/bin/sh: ../../prebuild.sh: Permission denied

  • STM32CubeExpansion_Cloud_AWS_V2.0.0/Projects/B-L4S5I-IOT01A/Applications/BootLoader_STSAFE/2_Images_SECoreBin/STM32CubeIDE/prebuild.sh 파일에 실행 권한을 설정 합니다.
chmod +x prebuild.sh

ImportError: No module named Cryptodome.Cipher

  • prebuild.sh에서 실행하는 prepareimage.py는 requirements.txt에 정의된 pycryptodome, pycryptodomex, ecdsa, pyelftools, numpy, lief를 사용하는데 이중 pycryptodomex library가 정상적으로 import 되지 않는 문제입니다.
  • 다음과 같이 python을 venv에서 실행되도록 환경을 구성 합니다.
  • 수정 파일 : STM32CubeExpansion_Cloud_AWS_V2.0.0/Projects/B-L4S5I-IOT01A/Applications/BootLoader_STSAFE/2_Image_SECoreBin/STM32CubeIDE/prebuild.sh

  • 변경 전

# test if window executeable useable
prepareimage=$basedir/win/prepareimage/prepareimage.exe
uname  | grep -i -e windows -e mingw > /dev/null 2>&1

if [ $? = 0 ] && [  -e "$prepareimage" ]; then
  echo "prepareimage with windows executeable" >> $1/output.txt
  echo "prepareimage with windows executeable"
  cmd=""
else
  # line for python
  echo "prepareimage with python script" >> $1/output.txt
  echo "prepareimage with python script"
  prepareimage=$basedir/prepareimage.py
  cmd=python
fi
  • 변경 후
# test if window executeable useable
prepareimage=$basedir/win/prepareimage/prepareimage.exe
uname  | grep -i -e windows -e mingw > /dev/null 2>&1

if [ $? = 0 ] && [  -e "$prepareimage" ]; then
  echo "prepareimage with windows executeable" >> $1/output.txt
  echo "prepareimage with windows executeable"
  cmd=""
else
  # add venv
  echo "run python3 on venv"
  python3 -m venv venv
  source venv/bin/activate
  pip3 install -r $basedir/requirements.txt
  # line for python
  echo "prepareimage with python script" >> $1/output.txt
  echo "prepareimage with python script"
  prepareimage=$basedir/prepareimage.py
  cmd=python3
fi




Credits


Korean version   

Jongwoo Lee (rainny@)

Sejun Kim (sejun@)

Albert Lee (sehyul@)


Original Contents Author

Vanitha Ramaswami (rvanitha@)


© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved.                                           

메이커스페이스 G·캠프에서 만든 콘텐츠가 아니며, 서울하드웨어해커톤에서 강의가 진행될 예정입니다.   

https://master.d2s409snhlt74e.amplifyapp.com/                                                                         

'05_Toolkit > AWS_IoT' 카테고리의 다른 글

Ex1. ④ AWS IOT CORE 연결  (0) 2020.11.26
Ex1. ③ AWS IOT APPLICATION  (0) 2020.11.26
Ex1. ① STSAFE PROVISIOING  (0) 2020.11.26
Ex1. PREPARATION ON BOTH DEVICE AND AWS PLATFORM  (0) 2020.11.26
Ex0. ⑥ ADDITIONAL SW TOOL  (0) 2020.11.26

 
90, Digital-ro 9-gil, Geumcheon-gu, Seoul, Republic of Korea
https://seoulhackathon.tistory.com/   
mail: 12000@12000.co Tel : +82-2-2135-5280
Copyright 2021 by Seoul Businsss Agency. All Rights Reserved. (Powered by Tistory)
Hackathon | Recent Articles +more
  •  
  •  
  •  
  •  
  •  
  •  
  •  
Hackathon | News +more
  •  
  •  
  •  
  •  
  •  
  •  
  •  
Hackathon | Schedule +more
  •  
  •  
  •  
  •  
  •  
  •  
  •  
Hackathon | Workshops    more
Hackathon | Toolkit    more
Hackathon | Video Tutorial    more
Hackathon | Hackathon +more
  •  
  •  
  •  
  •  
  •  
  •  
  •  
Hackathon | Others +more
  •  
  •  
  •  
  •  
  •  
  •  
  •  
Previous Hackathon    more

programs run by :

90, Digital-ro 9-gil, Geumcheon-gu, Seoul, Republic of Korea https://seoulhackathon.tistory.com
mail: 12000@12000.co Tel : +82-2-2135-5280