查看: 4297|回复: 0

[分享] i.MXRT三位数系列Boot之Serial ISP模式

[复制链接]
  • TA的每日心情
    开心
    2025-7-11 08:53
  • 签到天数: 301 天

    连续签到: 2 天

    [LV.8]以坛为家I

    3868

    主题

    7472

    帖子

    0

    管理员

    Rank: 9Rank: 9Rank: 9

    积分
    39227
    最后登录
    2025-7-18
    发表于 2019-12-30 12:55:26 | 显示全部楼层 |阅读模式
    i.MXRT三位数系列Boot之Serial ISP模式

            今天痞子衡给大家介绍的是恩智浦i.MX RTxxx系列MCU的Serial ISP模式。


      在上一篇文章 Boot配置(ISP Pin, OTP) 里痞子衡为大家介绍了i.MXRTxxx Boot的行为配置,其中第1.2节里讲了Boot有三类行为模式:Serial ISP、Serial Boot、Device Boot,后两种都是跟App启动执行相关的行为模式,而Serial ISP模式则是相对独立的Flash下载功能,有了Serial ISP,便可省去专用Flash编程器,今天痞子衡就来详细聊一聊Serial ISP模式。


      痞子衡在前面已经讲过Serial ISP模式是一种串行编程模式,在这种模式下,BootROM通过指定的UART/SPI/I2C/USB-HID口来接收来自Host(恩智浦提供了上位机工具blhost.exe或者MCUBootUtility)的Application数据,并将数据下载进i.MXRTxxx支持的所有外部非易失性存储器中,为后续从外部存储器启动做准备。


    一、进入Serial ISP模式
      i.MXRTxxx上电永远是从ROM启动去执行BootROM程序,最顶层的Boot行为模式由OTP memory里的PRIMARY_BOOT_SRC[3:0]位和芯片外部ISP[2:0]管脚状态共同决定。假设我们正处于研发阶段,PRIMARY_BOOT_SRC[3:0]并未烧写,那想进入Serial ISP模式最直接的方式便是将ISP[2:0]输入状态拨成3'b110,在设计i.MXRTxxx的硬件板时ISP[2:0] pins应设计成可通过拨码开关选择输入电平,下图是RT600-EVK板(Rev.E)的参考设计:
    24.png
     拨码开关SW5应拨向SW_DIP-6的6,即设置ISP[2:0]=3'b110,此时便直接进入了Serial ISP模式。


    二、blhost的使用
      进入了Serial ISP模式,此时便可以用恩智浦提供的host工具与BootROM进行命令交互,host工具在 MCUBootUtility包 里。下载好MCUBootUtility包之后,在\MCUBootUtility\Tools\blhost2_3\win下可以找到用于与BootROM通信的blhost.exe。


    2.1 支持的通信外设pinout
      BootROM支持四种通信外设,分别是UART/SPI/I2C/USB-HID(其中UART和USB比较常用),pinout如下(Pinout适用RT600):
    25.png
    2.2 blhost用法
      blhost.exe是命令行工具,使用blhost可以通过上述UART/SPI/I2C/USB-HID口与BootROM进行通信与命令交互。
      在命令行下打开blhost.exe,输入-?命令可以看到blhost使用帮助,blhost支持的命令很多:
    1. PS D:\NXP-MCUBootUtility\tools\blhost2_3\win> .\blhost.exe
    2. usage: D:\NXP-MCUBootUtility\tools\blhost2_3\win\blhost.exe
    3.                                                                       [-?|--help]
    4.                                                                       [-p|--port <name>[,<speed>]]
    5.                                                                       [-u|--usb [[[<vid>,]<pid>]]]
    6.                                                                       [-t|--timeout <ms>]
    7.                                                                       -- command <args...>

    8. Options:
    9.   -?/--help                    Show this help
    10.   -p/--port <name>[,<speed>]   Connect to target over UART. Specify COM port
    11.                                and optionally baud rate
    12.                                  (default=57600)
    13.                                  If -ftbi, then port is BusPal port
    14.   --ftdi spi[,<speed>,<polarity>,<phase>,lsb|msb] |
    15.               i2c[,<address>,<speed>]
    16.                                Use SPI or I2C for BusPal<-->Target link
    17.                                All parameters between square brackets are
    18.                                optional, but preceding parameters must be
    19.                                present or marked with a comma.
    20.                                (ex. -b spi,1000,0,1) (ex. --ftdi spi,1000,,lsb)
    21.                                  spi:  speed(KHz),
    22.                                        polarity(0=active_high | 1=active_low),
    23.                                        phase(0=rising_edge | 1=falling_edge),
    24.                                        "lsb" | "msb"
    25.                                        (default=100,1,1,msb)
    26.                                  i2c:  address(7-bit hex), speed(KHz)
    27.                                        (default=0x10,100)
    28.   -u/--usb [[[<vid>,]<pid>] | [<path>]]
    29.                                Connect to target over USB HID device denoted by
    30.                                vid/pid (default=0x15a2,0x0073) or device path
    31.   -t/--timeout <ms>            Set packet timeout in milliseconds
    32.                                  (default=5000)

    33. Memory ID:
    34.   Internal Memory              Device internal memory space
    35.     0                            Internal Memory
    36.                                  (Default selected memory)
    37.     16 (0x10)                    Execute-only region on internal flash
    38.                                  (Only used for flash-erase-all)
    39.   Mapped External Memory       The memories that are remapped to internal space,
    40.                                and must be accessed by internal addresses.
    41.                                (IDs in this group are only used for flash-erase-all and
    42.                                configure-memory, and ignored by write-memory, read-memory,
    43.                                flash-erase-region and flash-image(use default 0))
    44.     1                            QuadSPI Memory
    45.     9                            FlexSPI NOR Memory
    46.   Unmapped External Memory     Memories which cannot be remapped to internal space,
    47.                                and only can be accessed by memories' addresses.
    48.                                (Must be specified for all commands with <memoryId> argument)
    49.     272 (0x110)                  SPI NOR/EEPROM Memory
    50.     288 (0x120)                  uSDHC SD Memory
    51.     289 (0x121)                  uSDHC MMC Memory

    52. ** Note that not all memories are supported on all platforms.

    53. Command:
    54.   reset                        Reset the chip
    55.   get-property <tag> [<memoryId> | <index>]
    56.                                Return bootloader specific property.
    57.                                <memoryId> and <index> are required by some properties.
    58.                                <memoryId> = 0, <index> = 0, if not specified.
    59.                                <memoryId> and <index> are ignored for the other properties.
    60.                                If <index> is over the range supported by the device, bootloader
    61.                                will treat as <index> = 0.

    62.     1                          Bootloader version
    63.     2                          Available peripherals
    64.     3                          Start of program flash, <index> is required
    65.     4                          Size of program flash, <index> is required
    66.     5                          Size of flash sector, <index> is required
    67.     6                          Blocks in flash array, <index> is required
    68.     7                          Available commands
    69.     9                          Last Error
    70.     10                         Verify Writes flag
    71.     11                         Max supported packet size
    72.     14                         Start of RAM, <index> is required
    73.     15                         Size of RAM, <index> is required
    74.     23                         QuadSpi initialization status
    75.     24                         Target version
    76.     25                         External memory attrubutes, <memoryId> is required
    77.     27                         Flash page size, <index> is required
    78.     28                         Interrupt notifier pin
    79.     29                         FFR key store update option
    80.   set-property <tag> <value>
    81.     10                         Verify Writes flag
    82.     28                         Interrupt notifier pin
    83.                                <value>:
    84.                                    bit[31] for enablement, 0: disable, 1: enable
    85.                                    bit[7:0] for GPIO pin index
    86.                                    bit[15:8] for GPIO port index
    87.     29                         FFR key store update option
    88.                                <value>:
    89.                                    0 for Keyprovisioning
    90.                                    1 for write-memory
    91.   flash-erase-region <addr> <byte_count> [memory_id]
    92.                                Erase a region of flash according to [memory_id].
    93.   flash-erase-all [memory_id]  Erase all flash according to [memory_id],
    94.                                excluding protected regions.
    95.   read-memory <addr> <byte_count> [<file>] [memory_id]
    96.                                Read memory according to [memory_id] and write to file
    97.                                or stdout if no file specified
    98.   write-memory <addr> [<file>[,byte_count]| {{<hex-data>}}] [memory_id]
    99.                                Write memory according to [memory_id] from file
    100.                                or string of hex values,
    101.                                e.g. data.bin (writes entire file)
    102.                                e.g. data.bin 8 (writes first 8 bytes from file)
    103.                                e.g. "{{11 22 33 44}}" (w/quotes)
    104.                                e.g. {{11223344}} (no spaces)
    105.   fill-memory <addr> <byte_count> <pattern> [word | short | byte]
    106.                                Fill memory with pattern; size is
    107.                                word (default), short or byte
    108.   receive-sb-file <file>       Receive SB file
    109.   execute <addr> <arg> <stackpointer>
    110.                                Execute at address with arg and stack pointer
    111.   call <addr> <arg>            Call address with arg
    112.   configure-memory <memory_id> <internal_addr>
    113.                                Apply configuration block at internal memory address
    114.                                <internal_addr> to memory with ID <memory_id>
    115.   key-provisioning <operation> [arguments...]
    116.                                <enroll>
    117.                                    Key provisioning enroll. No argument for this operation
    118.                                <set_user_key> <type> <file>[,<size>]
    119.                                    Send the user key specified by <type> to bootloader. <file> is
    120.                                    the binary file containing user key plaintext. If <size> is not
    121.                                    specified, the entire <file> will be sent. Otherwise, only send
    122.                                    the first <size> bytes
    123.                                <set_key> <type> <size>
    124.                                    Generate <size> bytes of the key specified by <type>
    125.                                <write_key_nonvolatile> [memoryID]
    126.                                    Write the key to a nonvolatile memory
    127.                                <read_key_nonvolatile> [memoryID]
    128.                                    Load the key from a nonvolatile memory to bootloader
    129.                                <write_key_store> <file>[,<size>]
    130.                                    Send the key store to bootloader. <file> is the binary file
    131.                                    containing key store. If <size> is not specified, the entire
    132.                                    <file> will be sent. Otherwise, only send the first <size> bytes
    133.                                <read_key_store> <file>
    134.                                    Read the key store from bootloader to host(PC). <file> is the
    135.                                    binary file to store the key store
    136.   flash-image <file> [erase] [memory_id]
    137.                                Write a formated image <file> to memory with ID
    138.                                <memory_id>. Supported file types: SRecord
    139.                                (.srec and .s19) and HEX (.hex). Flash is erased
    140.                                before writing if [erase]=erase. The erase unit
    141.                                size depends on the target and the minimum erase
    142.                                unit size is 1K.
    143.   list-memory                  List all on-chip Flash and RAM regions, and off-chip
    144.                                memories, supported by current device.
    145.                                Only the configured off-chip memory will be list.
    146.   efuse-program-once <addr> <data> [nolock/lock]
    147.                                Program one word of OCOTP Field
    148.                                <addr> is ADDR of OTP word, not the shadowed memory address.
    149.                                <data> is hex digits without prefix '0x'
    150.   efuse-read-once <addr>
    151.                                Read one word of OCOTP Field
    152.                                <addr> is ADDR of OTP word, not the shadowed memory address.
    153.   generate-key-blob <dek_file> <blob_file>
    154.                                Generate the Blob for given Dek Key
    155.                                <dek_file> - input, a binary Dek Key (128 Bits) generated by CST tool.
    156.                                <blob_file> - output, a generated blob (72 Bytes) in binary format.

    157. ** Note that not all commands/properties are supported on all platforms.
    复制代码
     当使用串口转USB模块连接i.MXRTxxx的Flexcomm UART0或者使用USB Cable连接上USB1口后可以看到PC设备管理器会识别出相关设备:
    26.png
     让我们尝试一下使用blhost与BootROM通信,先试一下USB通信:



    PS D:\NXP-MCUBootUtility\tools\blhost2_3\win> .\blhost.exe -u 0x1fc9,0x0020 -- get-property 1
    1. Inject command 'get-property'
    2. Response status = 0 (0x0) Success.
    3. Response word 1 = 1258487808 (0x4b030000)
    4. Current Version = K3.0.0
    复制代码
    再接着试一下UART通信,似乎通信失败了。需要注意的是,当使用USB通信过一次之后,BootROM已经激活USB外设,不会再去检测其他外设(包括UART),如果想使用UART通信,需要将板子reset一次,使BootROM重回外设检测状态。


    PS D:\NXP-MCUBootUtility\tools\blhost2_3\win> .\blhost.exe -p COM25 -- get-property 1
    1. Error: Initial ping failure: No response received for ping command.
    复制代码
    三、下载更新Application示例
      因为BootROM支持启动的外部存储器很多,所以Serial ISP模式下进行Application更新操作要指定具体的外部存储器类型。在上一节blhost的命令帮助里,我们可以看到Memory ID里已经给各种外部储存器分配了ID号,在使用blhost命令时使用不同的ID号即可操作相应外部存储器。
      其实BootROM里已经把外部存储器的下载更新Application操作封装得很简单也很统一,我们其实只需要3步操作即可完成Application的下载。以备份启动的1bit SPI NOR为例(即Flexcomm SPI NOR Memory,Memory ID=0x110):】
    1. // 在SRAM里临时存储1bit SPI NOR配置数据
    2. blhost -p COMx -- fill-memory 0x1C000 0x4 0xC0300000 // Flexcomm SPI3, NOR Flash

    3. // 使用1bit SPI NOR配置数据去配置Flexcomm SPI接口
    4. blhost -p COMx -- configure-memory 0x110 0x1C000

    5. // 擦除1bit SPI NOR并将image下载进1bit SPI NOR
    6. blhost -p COMx -- flash-erase-region 0x0 0x20000 0x110
    7. <font size="3" face="微软雅黑">blhost -p COMx -- write-memory 0x1000 bt_image.bin 0x110</font>
    复制代码
    其中bt_image.bin是填充了Image类型数据的Application镜像,关于上述命令的具体意义痞子衡会在后续Serial(1-bit SPI) NOR恢复启动的文章里详尽解释,这里只是给大家一个初步体验。




    作者:痞子衡

    qiandao qiandao
    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /3 下一条

    Archiver|手机版|小黑屋|恩智浦技术社区

    GMT+8, 2025-7-19 05:02 , Processed in 0.083285 second(s), 20 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.

    快速回复 返回顶部 返回列表