痞子衡嵌入式:恩智浦i.MX RTxxx系列MCU啟動那些事(3)- Serial ISP模式(blhost)

来源:https://www.cnblogs.com/henjay724/archive/2019/12/05/11992494.html
-Advertisement-
Play Games

i.MXRTxxx Boot有三類行為模式:Serial ISP、Serial Boot、Device Boot,後兩種都是跟App啟動執行相關的行為模式,而Serial ISP模式則是相對獨立的Flash下載功能,有了Serial ISP,便可省去專用Flash編程器,今天痞子衡就來詳細聊一聊Se... ...



  大家好,我是痞子衡,是正經搞技術的痞子。今天痞子衡給大家介紹的是恩智浦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)的參考設計:

  撥碼開關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):

2.2 blhost用法

  blhost.exe是命令行工具,使用blhost可以通過上述UART/SPI/I2C/USB-HID口與BootROM進行通信與命令交互。
  在命令行下打開blhost.exe,輸入-?命令可以看到blhost使用幫助,blhost支持的命令很多:

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里臨時存儲1bit SPI NOR配置數據
blhost -p COMx -- fill-memory 0x1C000 0x4 0xC0300000 // Flexcomm SPI3, NOR Flash

// 使用1bit SPI NOR配置數據去配置Flexcomm SPI介面
blhost -p COMx -- configure-memory 0x110 0x1C000

// 擦除1bit SPI NOR並將image下載進1bit SPI 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) NOR恢復啟動的文章里詳盡解釋,這裡只是給大家一個初步體驗。

  至此,恩智浦i.MX RTxxx系列MCU的Serial ISP模式痞子衡便介紹完畢了,掌聲在哪裡~~~


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • private static void PathCopyFilesWithOriginalFolder() { int sourceFilesNum = 0; try { string sourceDir = @"E:\Source"; string destDir = @"E:\Dest"; st... ...
  • based on https://stackoverflow.com/questions/659013/accessing-a-shared-file-unc-from-a-remote-non-trusted-domain-with-credentials ...
  • .NET Core3.1發佈 我們很高興宣佈.NET Core 3.1的發佈。實際上,這隻是對我們兩個多月前發佈的.NET Core 3.0的一小部分修複和完善。最重要的是.NET Core 3.1是長期支持(LTS)版本,並且將支持三年。和過去一樣,我們希望花一些時間來發佈下一個LTS版本。額外的 ...
  • WGS-84坐標系:全球定位系統使用,GPS、北斗等 GCJ-02坐標系:中國地區使用,由WGS-84偏移而來 BD-09坐標系:百度專用,由GCJ-02偏移而來 (PS:源於項目需求,本來是想讀圖片的經緯度顯示在百度離線地圖上的。後來發現定位偏差太大,仔細一想,原來是圖片和百度使用的坐標系不一樣。 ...
  • 國內優秀的WPF開源控制項庫,Panuon.UI的優化版本。一個漂亮的、使用樣式與附加屬性的WPF UI控制項庫,值得向大家推薦使用與學習。 今天站長(Dotnet9,站長網址:https://dotnet9.com, 微信公眾號:dotnet9_com)推薦另一款開源的WPF控制項庫(PanuonUI. ...
  • 前言 上一篇文章主要介紹了ObjectPool的理論知識,再來介紹一下Microsoft.Extensions.ObjectPool是如何實現的. 核心組件 ObjectPool ObjectPool 是一個泛型抽象介面,他抽象了兩個方法Get和Return Get方法用於從對象池獲取到可用對象,如 ...
  • 註冊表位置: HKEY_CURRENT_USER/ Software/ Microsoft/ Terminal Server client/ servers/ 刪除不需要的IP地址即可。 ...
  • 視頻地址:【黑客基礎】Windows PowerShell 腳本學習 2019.12.05 學習筆記 1、$PSVersionTable :查看PowerShell的版本信息。 2、PowerShell 界面: 開始界面搜索 “PowerShell” ,點擊 “PowerShell.exe” 或者 ...
一周排行
    -Advertisement-
    Play Games
  • C#TMS系統代碼-基礎頁面BaseCity學習 本人純新手,剛進公司跟領導報道,我說我是java全棧,他問我會不會C#,我說大學學過,他說這個TMS系統就給你來管了。外包已經把代碼給我了,這幾天先把增刪改查的代碼背一下,說不定後面就要趕鴨子上架了 Service頁面 //using => impo ...
  • 委托與事件 委托 委托的定義 委托是C#中的一種類型,用於存儲對方法的引用。它允許將方法作為參數傳遞給其他方法,實現回調、事件處理和動態調用等功能。通俗來講,就是委托包含方法的記憶體地址,方法匹配與委托相同的簽名,因此通過使用正確的參數類型來調用方法。 委托的特性 引用方法:委托允許存儲對方法的引用, ...
  • 前言 這幾天閑來沒事看看ABP vNext的文檔和源碼,關於關於依賴註入(屬性註入)這塊兒產生了興趣。 我們都知道。Volo.ABP 依賴註入容器使用了第三方組件Autofac實現的。有三種註入方式,構造函數註入和方法註入和屬性註入。 ABP的屬性註入原則參考如下: 這時候我就開始疑惑了,因為我知道 ...
  • C#TMS系統代碼-業務頁面ShippingNotice學習 學一個業務頁面,ok,領導開完會就被裁掉了,很突然啊,他收拾東西的時候我還以為他要旅游提前請假了,還在尋思為什麼回家連自己買的幾箱飲料都要叫跑腿帶走,怕被偷嗎?還好我在他開會之前拿了兩瓶芬達 感覺感覺前面的BaseCity差不太多,這邊的 ...
  • 概述:在C#中,通過`Expression`類、`AndAlso`和`OrElse`方法可組合兩個`Expression<Func<T, bool>>`,實現多條件動態查詢。通過創建表達式樹,可輕鬆構建複雜的查詢條件。 在C#中,可以使用AndAlso和OrElse方法組合兩個Expression< ...
  • 閑來無聊在我的Biwen.QuickApi中實現一下極簡的事件匯流排,其實代碼還是蠻簡單的,對於初學者可能有些幫助 就貼出來,有什麼不足的地方也歡迎板磚交流~ 首先定義一個事件約定的空介面 public interface IEvent{} 然後定義事件訂閱者介面 public interface I ...
  • 1. 案例 成某三甲醫預約系統, 該項目在2024年初進行上線測試,在正常運行了兩天後,業務系統報錯:The connection pool has been exhausted, either raise MaxPoolSize (currently 800) or Timeout (curren ...
  • 背景 我們有些工具在 Web 版中已經有了很好的實踐,而在 WPF 中重新開發也是一種費時費力的操作,那麼直接集成則是最省事省力的方法了。 思路解釋 為什麼要使用 WPF?莫問為什麼,老 C# 開發的堅持,另外因為 Windows 上已經裝了 Webview2/edge 整體打包比 electron ...
  • EDP是一套集組織架構,許可權框架【功能許可權,操作許可權,數據訪問許可權,WebApi許可權】,自動化日誌,動態Interface,WebApi管理等基礎功能於一體的,基於.net的企業應用開發框架。通過友好的編碼方式實現數據行、列許可權的管控。 ...
  • .Net8.0 Blazor Hybird 桌面端 (WPF/Winform) 實測可以完整運行在 win7sp1/win10/win11. 如果用其他工具打包,還可以運行在mac/linux下, 傳送門BlazorHybrid 發佈為無依賴包方式 安裝 WebView2Runtime 1.57 M ...