Implementing Bootloaders on Renesas MCUs

Embed Size (px)

Citation preview

  • Class ID:

    Renesas Electronics America Inc. 2012 Renesas Electronics America Inc. All rights reserved.

    Implementing Bootloaders on Renesas MCUs

  • 2012 Renesas Electronics America Inc. All rights reserved.2

    Renesas Technology & Solution Portfolio

  • 2012 Renesas Electronics America Inc. All rights reserved.3

    Microcontroller and Microprocessor Line-up

    Wide Format LCDs Industrial & Automotive, 130nm 350A/MHz, 1A standby

    44 DMIPS, True Low Power

    Embedded Security, ASSP

    165 DMIPS, FPU, DSC

    1200 DMIPS, Performance1200 DMIPS, Superscalar

    500 DMIPS, Low Power

    165 DMIPS, FPU, DSC

    25 DMIPS, Low Power

    10 DMIPS, Capacitive Touch

    Industrial & Automotive, 150nm 190A/MHz, 0.3A standby

    Industrial, 90nm 200A/MHz, 1.6A deep standby

    Automotive & Industrial, 90nm 600A/MHz, 1.5A standby

    Automotive & Industrial, 65nm 600A/MHz, 1.5A standby Automotive, 40nm

    500A/MHz, 35A deep standby

    Industrial, 40nm 200A/MHz, 0.3A deep standby

    Industrial, 90nm 1mA/MHz, 100A standby

    Industrial & Automotive, 130nm 144A/MHz, 0.2A standby

    2010 2012

    32

    -bit

    8/16

    -bit

    32-Bit High PerformanceDSP, FPU with High Integration

  • 2012 Renesas Electronics America Inc. All rights reserved.4

    In a smart society devices can add features and fix bugs after leaving store shelves. Having a bootloader in your system allows you to sleep better at night.

    Enabling The Smart Society

    Firmware

    v1.2

    ???

    Firmware

    v3.0v4.0v1.3

    Added Multitasking Fixed focusing bug

  • 2012 Renesas Electronics America Inc. All rights reserved.5

    Agenda

    Quick bootloader overview

    The flash loader framework

    Design choices

    RX implementation

    RL78 implementation

    Lab

  • 2012 Renesas Electronics America Inc. All rights reserved.6

    Quick Bootloader Overview

  • 2012 Renesas Electronics America Inc. All rights reserved.7

    Quick Bootloader Overview

    What is a bootloader?

    What can a bootloader do?

    Erase and rewrite user memory

    Validate user memory

    Communicate with the outside world

    Download new application in case of failure

    What should a bootloader be?

    Reset

    Bootloader

    Application

  • 2012 Renesas Electronics America Inc. All rights reserved.8

    Available Boot Options

    Factory bootloader

    Cannot be modified

    User code cannot run

    Can program/erase everything

    User boot area

    Programmed with USB fromfactory

    Uses CPU rewrite code

    User application

    Uses CPU rewrite code

    MCU Address Space

    Factory Bootloader

    RAM

    User Boot Area

    User Application

    Area

    P/E

    P/E

  • 2012 Renesas Electronics America Inc. All rights reserved.9

    The Flash Loader Project

  • 2012 Renesas Electronics America Inc. All rights reserved.10

    What is the Flash Loader Project?

    Flexible system for implementing in-field-reprogramming in your own project

    Communications medium agnostic

    Modify to fit your system

    Retries & error checking built in

    Does not interfere with user application

  • 2012 Renesas Electronics America Inc. All rights reserved.11

    Terms

    DeviceStorage

    v4.2

    Host

    Load Image

  • 2012 Renesas Electronics America Inc. All rights reserved.12

    CheckingDownloading Storing Reprogramming

    Parts of the Flash Loader Project?

    Flexible system that can be split into 2 parts:

    Downloader

    Bootloader

    Host Device Storage

  • 2012 Renesas Electronics America Inc. All rights reserved.13

    1: Using Flash Loader With Your Project

  • 2012 Renesas Electronics America Inc. All rights reserved.14

    Add Flash Loader to your HEW Project

    Add flash loader project files

    Enables future updates

    Flash loader bootloader is separate project

    Users Project

    User Application Flash Loader

    +

  • 2012 Renesas Electronics America Inc. All rights reserved.15

    Configure Flash Loader for Your System

    r_fl_app_header.c r_fl_comm_*type*.c r_fl_downloader.c r_fl_store_manager.c r_fl_memory_*type*.c r_fl_utilities.c

    Host Device Storage

    v4.2

    = Edit for your configuration

  • 2012 Renesas Electronics America Inc. All rights reserved.16

    2: Making a Load Image

  • 2012 Renesas Electronics America Inc. All rights reserved.17 2010 Renesas Electronics America Inc. All rights reserved.

    Making a Load Image

    S-Record (MOT) files are

    inefficient

    S-Record Converter

    Load image information:

    Binary

    Starts with header

    Has N blocksLoad Image

    Header Block 1 Block 2 Block N...

    MOT S-Record

    Converter

    Load

    Image

    60KB 20KB

  • 2012 Renesas Electronics America Inc. All rights reserved.18

    Load Image Header

    2010 Renesas Electronics America Inc. All rights reserved.

    Field Size in Bytes

    Valid mask 1

    Image ID 1

    Version number 1

    Size of load image 4

    Max block data size 4

    Load image CRC 2

    Raw CRC 2

    Address of 1st data block 4

    Successfully stored? 4

  • 2012 Renesas Electronics America Inc. All rights reserved.19

    3: Obtaining the Load Image

  • 2012 Renesas Electronics America Inc. All rights reserved.20

    Transferring the Load Image

    Flash loader is medium agnostic

    Communications protocol is supplied

    Supported commands Information request

    Erase image from storage

    Load image download

    Host Device Storage

  • 2012 Renesas Electronics America Inc. All rights reserved.21

    Storing the Load Image

    As Load blocks come in:

    Check for errors

    Store

    Storage area partitioned for load images

    If error occurs, retry is possible

    Host Device Storage

    Load Block

  • 2012 Renesas Electronics America Inc. All rights reserved.22

    Storage

    What the Storage Area Looks Like

    Load images are in different partitions

    Load Image #1 Address 0x00100000

    Header Block 1 Block 2 Block 3Block 512

    Load Image #2 Address 0x00200000

    Header Block 1 Block 2 Block 3Block 656

    Load Image #3 Address 0x00300000

    EMPTY

  • 2012 Renesas Electronics America Inc. All rights reserved.23

    4: Using the Load Image

  • 2012 Renesas Electronics America Inc. All rights reserved.24

    Reboot & Flash

    Reboot when convenient

    Check for new load image

    If valid, reflash MCU

    Jump to user application and execute

    Host Device Storage

    Load Image

  • 2012 Renesas Electronics America Inc. All rights reserved.25

    Design Choices

  • 2012 Renesas Electronics America Inc. All rights reserved.26

    Bootloader Decisions

    Why not store bootloader in same memory area as user application?

    Bug in control code could erase everything

    Application must be aware of bootloader

    Why not store load images in MCU memory?

    Hard to make bootloader not interfere with user application

    Bug in control code could erase currently running application

    Limit application size or pay more

    Move code to RAM

    May have to use PIC and PID

    Keep safe older revisions

  • 2012 Renesas Electronics America Inc. All rights reserved.27

    RX Implementation

  • 2012 Renesas Electronics America Inc. All rights reserved.28

    Flash Loader Bootloader

    Separate workspace

    Separate memory areas

    Can use same or different communications as FL downloader

    User Boot is special

    User Application

    &

    Flash Loader Downloader

    Flash Loader Bootloader

    MCU User ROM User Boot Area

  • 2012 Renesas Electronics America Inc. All rights reserved.29

    Why is User Boot Special?

    Can execute from either reset vector on start-up

    Cannot accidentally erase

    Should have one and done attitude

    No indirection tables!

    Single-Chip ModeReset Vector

    User Boot ModeReset Vector

  • 2012 Renesas Electronics America Inc. All rights reserved.30

    Storing Load Images

    By default stored in external SPI flash

    RX cannot read from ROM while writing or erasing ROM

    Large stalls in user application or move to RAM

    No chance of losing image

    Cost of SPI flash is usually lower than doubling MCU ROM

    Its so much easier!

  • 2012 Renesas Electronics America Inc. All rights reserved.31

    RL78 Implementation

  • 2012 Renesas Electronics America Inc. All rights reserved.32

    Dual Boot Blocks

    Has 2 independent boot blocks

    Can swap which one is used

    Removes problem of losing everything

    Still recommend external SPI flash

  • 2012 Renesas Electronics America Inc. All rights reserved.33

    Using Boot Swap

    Download new image

    Swap to bootloader block

    Program in image

    Swap to application block

  • 2012 Renesas Electronics America Inc. All rights reserved.34

    Summary

    Quick bootloader overview

    The flash loader framework

    Design choices

    RX implementation

    RL78 implementation

    Lab

  • 2012 Renesas Electronics America Inc. All rights reserved.35

    Questions?

  • 2012 Renesas Electronics America Inc. All rights reserved.36

    In a smart society devices can add features and fix bugs after leaving store shelves. Have a bootloader in your system allows you to sleep better at night.

    Enabling The Smart Society

    Firmware

    v1.2

    ???

    Firmware

    v3.0v4.0v1.3

    Added Multitasking Fixed focusing bug

  • Renesas Electronics America Inc. 2012 Renesas Electronics America Inc. All rights reserved.

    Implementing Bootloaders on Renesas MCUs Renesas Technology & Solution PortfolioMicrocontroller and Microprocessor Line-upEnabling The Smart SocietyAgendaQuick Bootloader OverviewQuick Bootloader OverviewAvailable Boot OptionsThe Flash Loader ProjectWhat is the Flash Loader Project?TermsParts of the Flash Loader Project?1: Using Flash Loader With Your ProjectAdd Flash Loader to your HEW ProjectConfigure Flash Loader for Your System2: Making a Load ImageMaking a Load ImageLoad Image Header3: Obtaining the Load ImageTransferring the Load ImageStoring the Load ImageWhat the Storage Area Looks Like4: Using the Load ImageReboot & FlashDesign ChoicesBootloader DecisionsRX ImplementationFlash Loader BootloaderWhy is User Boot Special?Storing Load ImagesRL78 ImplementationDual Boot BlocksUsing Boot SwapSummarySlide Number 35Enabling The Smart SocietySlide Number 37