# NXP Bootloader Example
- Interface: `CAN`
- Vendor Device: `PEAK`
- Test Board: [S32K344/324/314大开发板EVB评估板](https://item.taobao.com/item.htm?abbucket=19&id=740622398903&ns=1&pisk=foBIpV2TH20CwzFUG0Ew5MELoK95FawqR0tRmgHE2pppy1scPerutp56PNQ6Jvr3tQL5-pdlTU8ePLslllz43-ShxLvTury2-9WlzK0KvX3yXVKWtPrZ7-ShxUmIyo5T34GtHzkKwUQJBCKDALnpvBE6BnxXevd-pf39SFLJeUL-6VK2qYhpya39X3x223LK9ce9q3vJyap-wku64WtRAlu6g--gKeSp5xsGCHLstMTseY611BTA3FM-eOtdjWT25xNyksYegEbTQv95X3_6g6ajdasRm_d1F2EFkgQhCpvbakAf6152O1aKFFWeVIpJ10HRfdTGlTpYHVtG6M5RKwiSeHXF3QTD1uHkadB2MsQIqoj9p3QkiTzmKeIRmtf2hJgDA1IXCg-o3ENK9bi6iYt6ulZsZbX7XcDfljopZBKMv-r_fVGk9hxtlTrsOXRpjhP8flgLf&priceTId=213e363a17316432955378124eef04&skuId=5466402150063&spm=a21n57.1.item.3.3173523c0cLCx7&utparam=%7B%22aplus_abtest%22%3A%22b157c0e4b60c27af3bd36a542bb06f7a%22%7D&xxc=taobaoSearch), or NXP S32K344EVB.

- Ecu Code: [NXP Bootloader](https://community.nxp.com/t5/S32K-Knowledge-Base/Unified-bootloader-Demo/ta-p/1423099)
## Description
This example demonstrates how to use the EcuBus-Pro to upgrade Application firmware through UDS CAN protocol. This example use PEAK as USB-CAN adapter.
## CAN Configuration
- CAN
- Baudrate: 500Kbps
- TX ID: 0x784
- RX ID: 0x7f0
## Connection
| PEAK | S32K344大开发板EVB评估板 |
| ---- | ------------------------ |
| CANH | CAN0 H23-1 |
| CANL | CAN0 H23-2 |
## Usage
1. Download the [NXP Bootloader](https://community.nxp.com/t5/S32K-Knowledge-Base/Unified-bootloader-Demo/ta-p/1423099).
1. The download demo is based on old EcuBus tool, which is deprecated. The new EcuBus-Pro tool has more features and better performance.
2. If you use the `NXP S32K344EVB`, you can directly download the firmware. If you use the `S32K344大开发板EVB评估板`, you need to modify the LPUART pins and LED pins.
3. Connect the PEAK USB-CAN adapter to the computer, and connect the PEAK USB-CAN adapter to the S32K344 board.
4. Run the Sequence-Tester_1.
---
## Diagnostic Steps

This example implements firmware upgrade through UDS diagnostic protocol. The main steps are as follows:
1. Session Control and Communication Control
- DiagnosticSessionControl (0x10) switch to programming session (0x03)
- CommunicationControl (0x28) disable normal communication (controlType=0x03)
- DiagnosticSessionControl (0x10) switch to extended session (0x02)
2. Security Access
- SecurityAccess (0x27, subfunction=0x01) request seed
- SecurityAccess (0x27, subfunction=0x02) send key
- Key calculation uses AES-128-CBC algorithm, key is [0-15], IV is all zeros
3. Write Identifier
- WriteDataByIdentifier (0x2E, DID=0xF15A) write specific identifier
4. Download Program
For each firmware file:
1. RequestDownload (0x34) request download, specify memory address and size
2. RoutineControl (0x31, routineId=0x0202) verify CRC
3. TransferData (0x36) transfer data in blocks
4. RequestTransferExit (0x37) end transfer
5. Firmware Verification and Reset
- RoutineControl (0x31, routineId=0xFF00) verify firmware
- RoutineControl (0x31, routineId=0xFF01) verification complete
- ECUReset (0x11) reset ECU
## Firmware Files
The example includes two firmware files:
1. S32K344_FlsDrvRTD100.bin
- Download Address: 0x20000010
- Driver firmware
2. S32K344_CAN_App_RTD200.bin
- Download Address: 0x00440200
- Application firmware
## Notes
1. Ensure firmware files are placed in the project's bin directory
2. Do not disconnect or power off during download
3. If download fails, you can retry the entire process
4. Each firmware file needs CRC verification
---
**[Demo Video](https://www.bilibili.com/video/BV1KcmfYNEkQ)**
## Script Implementation Details
The bootloader.ts script implements the diagnostic sequence. Here's a detailed explanation of each part:
### Initialization and Imports
```typescript
import crypto from 'crypto'
import { CRC, DiagRequest, DiagResponse } from 'ECB'
import path from 'path'
import fs from 'fs/promises'
```
- Imports required modules for cryptography, CRC calculation, and file operations
- `ECB` provides UDS diagnostic communication utilities
### Configuration
```typescript
const crc = new CRC('self', 16, 0x3d65, 0, 0xffff, true, true)
let maxChunkSize: number | undefined = undefined
let content: undefined | Buffer = undefined
```
- Configures CRC-16 calculator for firmware verification
- Variables to store transfer block size and firmware content
### Firmware Files Configuration
```typescript
const fileList = [
{
addr: 0x20000010,
file: path.join(process.env.PROJECT_ROOT, 'bin', 'S32K344_FlsDrvRTD100.bin')
},
{
addr: 0x00440200,
file: path.join(process.env.PROJECT_ROOT, 'bin', 'S32K344_CAN_App_RTD200.bin')
}
]
```
- Defines firmware files to be downloaded with their target addresses
### Initialization Handler
```typescript
Util.Init(async () => {
const req = DiagRequest.from('Tester_1.RoutineControl491')
req.diagSetParameter('routineControlType', 1)
await req.changeService()
const resp = DiagResponse.from('Tester_1.RoutineControl491')
resp.diagSetParameter('routineControlType', 1)
await resp.changeService()
})
```
- Modifies RoutineControl491 service to use type 1 (start routine)
- Updates both request and response parameters
### Security Access Handler
```typescript
Util.On('Tester_1.SecurityAccess390.recv', async (v) => {
const data = v.diagGetParameterRaw('securitySeed')
const cipher = crypto.createCipheriv(
'aes-128-cbc',
Buffer.from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]),
Buffer.alloc(16, 0)
)
let encrypted = cipher.update(data)
cipher.final()
const req = DiagRequest.from('Tester_1.SecurityAccess391')
req.diagSetParameterSize('data', 128)
req.diagSetParameterRaw('data', encrypted)
await req.changeService()
})
```
- Handles security access seed-key exchange
- Uses AES-128-CBC to calculate key from received seed
- Sends calculated key back to ECU
### Download Process Handlers
```typescript
Util.Register('Tester_1.JobFunction0', async () => {
// Prepare next firmware file for download
const item = fileList.shift()
if (item) {
// Request download and verify CRC
// Returns array of requests to be sent
}
return []
})
Util.Register('Tester_1.JobFunction1', () => {
// Handle actual data transfer
// Splits firmware into chunks and sends them
// Ends with transfer exit request
// Returns array of requests to be sent
})
```
- JobFunction0: Prepares download by:
1. Getting next firmware file
2. Setting up download request with correct address
3. Calculating and verifying CRC
- JobFunction1: Handles data transfer by:
1. Splitting firmware into appropriate chunk sizes
2. Creating TransferData requests for each chunk
3. Adding RequestTransferExit at the end
4. Triggering firmware verification after last file
The script works in conjunction with the sequence defined in the ECB file, which executes:
1. Session and communication control services
2. Security access sequence
3. JobFunction0 to prepare download
4. JobFunction1 to transfer data
5. Final verification and reset
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
在当今汽车行业中,汽车电子控制单元(ECU)的开发和测试至关重要。随着汽车技术的飞速发展,对ECU的要求也越来越高。ECU开发工具是帮助工程师实现这些要求的关键工具。这里提到的是一款功能强大的汽车ECU开发工具,它支持UDS(统一诊断服务)、CAN-TP(CAN传输协议)、DoIP(诊断协议上的以太网)和LIN(局部互连网络)协议。这些协议是目前汽车网络通信的主要标准,能够确保汽车内部各控制单元之间的有效通信。 该开发工具提供的类CAPL脚本(TS)功能是一种类似于Vector公司CAPL(CAN访问编程库)的脚本语言,它允许用户通过编写脚本来模拟信号、控制总线通信以及进行数据的捕获与分析。类CAPL脚本(TS)的特性极大地提高了开发和测试的灵活性,使得工程师可以根据特定需求定制开发流程,从而缩短产品上市时间并提升产品性能。 此外,该工具还支持HIL(硬件在环)测试,这是一种高级的测试方法,能够模拟车辆运行环境下的各种情况,使工程师在不依赖实车的情况下进行ECU功能和性能测试。HIL测试不仅能显著提高测试的效率和安全性,还有助于发现和解决潜在的问题,确保ECU在真实环境中的可靠性和稳定性。 从长远来看,这款ECU开发工具的应用,不仅限于特定车型或品牌,它还具有广泛的应用前景。随着自动驾驶、电动汽车和智能网联技术的日益普及,这款工具能够支持未来汽车电子技术的快速发展,对于推动整个汽车行业向智能化和电动化转型具有重要意义。 这款汽车ECU开发工具在支持多种通信协议、提供高级脚本功能以及实现高效安全的HIL测试方面展现出了巨大的优势。它不仅能够大幅提高开发效率,还能确保ECU产品的质量,对整个汽车电子行业而言具有划时代的意义。
资源推荐
资源详情
资源评论





























收起资源包目录





































































































共 762 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论


Java程序员-张凯
- 粉丝: 1w+
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- dachuang-大创资源
- XLang-汇编语言资源
- lilishop 商城 小程序 uni 移动端-C语言资源
- lenosp-C++资源
- 一个病虫害图像识别网站
- 基于 Python 调用摄像头拍照并结合百度 API 进行图像识别的小项目
- AIAS-Java资源
- hikyuu-Python资源
- GiteeIOS-Swift资源
- mcp-playwright-AI人工智能资源
- Rudis-Rust资源
- Python 图像处理技术演示:图像增强、卷积可视化与小型网络识别效果展示
- EcuBus-Pro-硬件开发资源
- Android Course Work-移动应用开发资源
- Pinecone_Pi_Nano-单片机开发资源
- vue-element-plus-admin-Typescript资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
