Embedded value riffraff: NXP MCU series i.MX RTxxx start those things (3) - Serial ISP mode (blhost)


  Hello everyone, I am a ruffian scale, is a decent engage in technology riffraff. Today riffraff value to introduce is NXP i.MX RTxxx series of MCU Serial ISP mode .

  In the previous article Boot Configuration (ISP Pin, OTP) in riffraff value describes the behavior of the configuration i.MXRTxxx Boot for everyone, which I talked about the first 1.2 Boot There are three patterns of behavior: Serial ISP, Serial Boot, Device Boot, the latter two are executed with the App start-related behavior patterns, and Serial ISP model is relatively independent Flash download function, with Serial ISP, remove the need for dedicated Flash programmer, today riffraff balance will be detailed chat Serial ISP mode.

  Ruffian value already spoken Serial ISP mode is a serial programming mode, in this mode, the BootROM is received from a Host (specified by NXP UART / SPI / I2C / USB-HID port provides PC tool blhost.exe or MCUBootUtility) Application of the data, and the data downloaded into all external support i.MXRTxxx nonvolatile memory, for subsequent preparation starts from the external memory.

First, enter the Serial ISP mode

  On i.MXRTxxx power is always started from the ROM to perform BootROM program, the topmost Boot behavior patterns [3: 0] by the OTP memory in the PRIMARY_BOOT_SRC bit and external chip ISP [2: 0] pin state joint decision. Suppose we are in the development stage, PRIMARY_BOOT_SRC [3: 0] was not programmed, that want to enter the Serial ISP mode is the most direct way to ISP [2: 0] dial to enter the state 3'b110, design i.MXRTxxx when the hardware board ISP [2: 0] pins are to be made via DIP switches to select the input level, the figure is RT600-EVK plate (Rev. E) reference design:

  DIP switch SW5 should be allocated to the 6 SW_DIP-6, i.e., disposed ISP [2: 0] = 3'b110, at this time it directly into the Serial ISP mode.

Two, blhost use

  Enter the Serial ISP mode, host tools and BootROM is ready to be used NXP's command interaction, host tools MCUBootUtility package inside. After the download is good MCUBootUtility pack, \ MCUBootUtility \ Tools \ under win \ blhost2_3 can find blhost.exe for communicating with the BootROM.

2.1 supports communication peripherals pinout

  BootROM supports four communication peripherals, namely, UART / SPI / I2C / USB-HID (wherein UART and USB more commonly used), Spinout follows (applicable Pinout RT600):

2.2 blhost usage

  blhost.exe command-line tools, can be used blhost USB-HID port communicating with interactive commands via the UART / SPI / I2C / and BootROM.
  ? Open blhost.exe, enter the command line - you can see blhost command use help, blhost commands a lot of support:

PS D:\NXP-MCUBootUtility\tools\blhost2_3\win> .\blhost.exe
usage: D:\NXP-MCUBootUtility\tools\blhost2_3\win\blhost.exe
                                                                      [-?|--help]
                                                                      [-p|--port <name>[,<speed>]]
                                                                      [-u|--usb [[[<vid>,]<pid>]]]
                                                                      [-t|--timeout <ms>]
                                                                      -- command <args...>

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

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

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

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

    1                          Bootloader version
    2                          Available peripherals
    3                          Start of program flash, <index> is required
    4                          Size of program flash, <index> is required
    5                          Size of flash sector, <index> is required
    6                          Blocks in flash array, <index> is required
    7                          Available commands
    9                          Last Error
    10                         Verify Writes flag
    11                         Max supported packet size
    14                         Start of RAM, <index> is required
    15                         Size of RAM, <index> is required
    23                         QuadSpi initialization status
    24                         Target version
    25                         External memory attrubutes, <memoryId> is required
    27                         Flash page size, <index> is required
    28                         Interrupt notifier pin
    29                         FFR key store update option
  set-property <tag> <value>
    10                         Verify Writes flag
    28                         Interrupt notifier pin
                               <value>:
                                   bit[31] for enablement, 0: disable, 1: enable
                                   bit[7:0] for GPIO pin index
                                   bit[15:8] for GPIO port index
    29                         FFR key store update option
                               <value>:
                                   0 for Keyprovisioning
                                   1 for write-memory
  flash-erase-region <addr> <byte_count> [memory_id]
                               Erase a region of flash according to [memory_id].
  flash-erase-all [memory_id]  Erase all flash according to [memory_id],
                               excluding protected regions.
  read-memory <addr> <byte_count> [<file>] [memory_id]
                               Read memory according to [memory_id] and write to file
                               or stdout if no file specified
  write-memory <addr> [<file>[,byte_count]| {{<hex-data>}}] [memory_id]
                               Write memory according to [memory_id] from file
                               or string of hex values,
                               e.g. data.bin (writes entire file)
                               e.g. data.bin 8 (writes first 8 bytes from file)
                               e.g. "{{11 22 33 44}}" (w/quotes)
                               e.g. {{11223344}} (no spaces)
  fill-memory <addr> <byte_count> <pattern> [word | short | byte]
                               Fill memory with pattern; size is
                               word (default), short or byte
  receive-sb-file <file>       Receive SB file
  execute <addr> <arg> <stackpointer>
                               Execute at address with arg and stack pointer
  call <addr> <arg>            Call address with arg
  configure-memory <memory_id> <internal_addr>
                               Apply configuration block at internal memory address
                               <internal_addr> to memory with ID <memory_id>
  key-provisioning <operation> [arguments...]
                               <enroll>
                                   Key provisioning enroll. No argument for this operation
                               <set_user_key> <type> <file>[,<size>]
                                   Send the user key specified by <type> to bootloader. <file> is
                                   the binary file containing user key plaintext. If <size> is not
                                   specified, the entire <file> will be sent. Otherwise, only send
                                   the first <size> bytes
                               <set_key> <type> <size>
                                   Generate <size> bytes of the key specified by <type>
                               <write_key_nonvolatile> [memoryID]
                                   Write the key to a nonvolatile memory
                               <read_key_nonvolatile> [memoryID]
                                   Load the key from a nonvolatile memory to bootloader
                               <write_key_store> <file>[,<size>]
                                   Send the key store to bootloader. <file> is the binary file
                                   containing key store. If <size> is not specified, the entire
                                   <file> will be sent. Otherwise, only send the first <size> bytes
                               <read_key_store> <file>
                                   Read the key store from bootloader to host(PC). <file> is the
                                   binary file to store the key store
  flash-image <file> [erase] [memory_id]
                               Write a formated image <file> to memory with ID
                               <memory_id>. Supported file types: SRecord
                               (.srec and .s19) and HEX (.hex). Flash is erased
                               before writing if [erase]=erase. The erase unit
                               size depends on the target and the minimum erase
                               unit size is 1K.
  list-memory                  List all on-chip Flash and RAM regions, and off-chip
                               memories, supported by current device.
                               Only the configured off-chip memory will be list.
  efuse-program-once <addr> <data> [nolock/lock]
                               Program one word of OCOTP Field
                               <addr> is ADDR of OTP word, not the shadowed memory address.
                               <data> is hex digits without prefix '0x'
  efuse-read-once <addr>
                               Read one word of OCOTP Field
                               <addr> is ADDR of OTP word, not the shadowed memory address.
  generate-key-blob <dek_file> <blob_file>
                               Generate the Blob for given Dek Key
                               <dek_file> - input, a binary Dek Key (128 Bits) generated by CST tool.
                               <blob_file> - output, a generated blob (72 Bytes) in binary format.

** Note that not all commands/properties are supported on all platforms.

  当使用串口转USB模块连接i.MXRTxxx的Flexcomm UART0或者使用USB Cable连接上USB1口后可以看到PC设备管理器会识别出相关设备:

  让我们尝试一下使用blhost与BootROM通信,先试一下USB通信:

PS D:\NXP-MCUBootUtility\tools\blhost2_3\win> .\blhost.exe -u 0x1fc9,0x0020 -- get-property 1

Inject command 'get-property'
Response status = 0 (0x0) Success.
Response word 1 = 1258487808 (0x4b030000)
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

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):

// 在SRAM里临时存储Serial EEPROM/NOR配置数据
blhost -p COMx -- fill-memory 0x1C000 0x4 0xC0300000 // Flexcomm SPI3, NOR Flash

// 使用Serial EEPROM/NOR配置数据去配置Flexcomm SPI接口
blhost -p COMx -- configure-memory 0x110 0x1C000

// 擦除Serial EEPROM/NOR并将image下载进Serial EEPROM/NOR
blhost -p COMx -- flash-erase-region 0x0 0x20000 0x110
blhost -p COMx -- write-memory 0x0 bt_image.bin 0x110

  其中bt_image.bin是填充了Image类型数据的Application镜像,关于上述命令的具体意义痞子衡会在后续Serial(1-bit SPI) EEPROM/NOR恢复启动的文章里详尽解释,这里只是给大家一个初步体验。

  至此,恩智浦i.MX RTxxx系列MCU的Serial ISP模式痞子衡便介绍完毕了,掌声在哪里~~~

Guess you like

Origin www.cnblogs.com/henjay724/p/11992494.html