文章目录
前言
在车载以太网架构设计中,Marvell 88Q5152 是一款应用广泛的高性能交换机芯片。本文将基于实际项目需求,详细介绍如何从底层的端口寄存器配置开始,生成 Configuration Bin 文件,合成 Secure Image,并最终通过 Shell 脚本完成对设备 Flash 的双分区烧录。
一. 需求分析与寄存器配置
在生成固件之前,首先需要明确硬件设计的端口需求。根据本项目规划,我们需要配置 6 个 PHY 端口,混合了千兆(1G)和百兆(100M)速率,且全部配置为 Master 模式。
端口配置需求
- P1, P2: 内部 PHY Master 100M (千兆主)
- P3, P4: 内部 PHY Master 100M (百兆主)
- P5: 外部 PHY Master 1G (对接 88Q2220)
- P6: 外部 PHY Master 1G (对接 88Q2221)
寄存器映射表
针对上述需求,我们在 XML 配置文件中需设定对应的寄存器值。以下是 88Q5152 常用的 PHY 模式寄存器对照表:
| 速率 | Master | Slave |
|---|---|---|
| 100M | C000 | 8000 |
| 1G | C001 | 8001 |
| 2.5G | C004 | 8004 |
| 10G | C006 | 8006 |
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<switch_config_1>
<board_config>D:/eth/board_config_0xb52_0x9101_demo_base.xml</board_config>
<ptp>
<entity_order_no>0x0002</entity_order_no>
<entity_enabled>true</entity_enabled>
<ptp_entity_autocds>
<ptp_id>0x0000</ptp_id>
<ptp_entity_config_autocds_v2>
<feature_mask>0x00000002</feature_mask>
<sync_receipt_timeout>0x000007d0</sync_receipt_timeout>
</ptp_entity_config_autocds_v2>
<ptp_port_autocds>
<ptp_port_index>0x0001</ptp_port_index>
<ptp_role>0x06</ptp_role>
<init_log_pdelay_req_interval>0x00</init_log_pdelay_req_interval>
<init_log_sync_interval>-0x03</init_log_sync_interval>
<operation_pdelay_req_interval>0x00</operation_pdelay_req_interval>
<operation_sync_interval>-0x03</operation_sync_interval>
<neighbor_prop_delay>0x00000000</neighbor_prop_delay>
</ptp_port_autocds>
<ptp_port_autocds>
<ptp_port_index>0x0002</ptp_port_index>
<ptp_role>0x06</ptp_role>
<init_log_pdelay_req_interval>0x00</init_log_pdelay_req_interval>
<init_log_sync_interval>-0x03</init_log_sync_interval>
<operation_pdelay_req_interval>0x00</operation_pdelay_req_interval>
<operation_sync_interval>-0x03</operation_sync_interval>
<neighbor_prop_delay>0x00000000</neighbor_prop_delay>
</ptp_port_autocds>
<ptp_port_autocds>
<ptp_port_index>0x0003</ptp_port_index>
<ptp_role>0x06</ptp_role>
<init_log_pdelay_req_interval>0x00</init_log_pdelay_req_interval>
<init_log_sync_interval>-0x03</init_log_sync_interval>
<operation_pdelay_req_interval>0x00</operation_pdelay_req_interval>
<operation_sync_interval>-0x03</operation_sync_interval>
<neighbor_prop_delay>0x00000000</neighbor_prop_delay>
</ptp_port_autocds>
<ptp_port_autocds>
<ptp_port_index>0x0004</ptp_port_index>
<ptp_role>0x06</ptp_role>
<init_log_pdelay_req_interval>0x00</init_log_pdelay_req_interval>
<init_log_sync_interval>-0x03</init_log_sync_interval>
<operation_pdelay_req_interval>0x00</operation_pdelay_req_interval>
<operation_sync_interval>-0x03</operation_sync_interval>
<neighbor_prop_delay>0x00000000</neighbor_prop_delay>
</ptp_port_autocds>
<ptp_port_autocds>
<ptp_port_index>0x0005</ptp_port_index>
<ptp_role>0x06</ptp_role>
<init_log_pdelay_req_interval>0x00</init_log_pdelay_req_interval>
<init_log_sync_interval>-0x03</init_log_sync_interval>
<operation_pdelay_req_interval>0x00</operation_pdelay_req_interval>
<operation_sync_interval>-0x03</operation_sync_interval>
<neighbor_prop_delay>0x00000000</neighbor_prop_delay>
</ptp_port_autocds>
<ptp_port_autocds>
<ptp_port_index>0x0006</ptp_port_index>
<ptp_role>0x06</ptp_role>
<init_log_pdelay_req_interval>0x00</init_log_pdelay_req_interval>
<init_log_sync_interval>-0x03</init_log_sync_interval>
<operation_pdelay_req_interval>0x00</operation_pdelay_req_interval>
<operation_sync_interval>-0x03</operation_sync_interval>
<neighbor_prop_delay>0x00000000</neighbor_prop_delay>
</ptp_port_autocds>
<ptp_port_autocds>
<ptp_port_index>0x0007</ptp_port_index>
<ptp_role>0x06</ptp_role>
<init_log_pdelay_req_interval>0x00</init_log_pdelay_req_interval>
<init_log_sync_interval>-0x03</init_log_sync_interval>
<operation_pdelay_req_interval>0x00</operation_pdelay_req_interval>
<operation_sync_interval>-0x03</operation_sync_interval>
<neighbor_prop_delay>0x00000000</neighbor_prop_delay>
</ptp_port_autocds>
<ptp_port_autocds>
<ptp_port_index>0x0008</ptp_port_index>
<ptp_role>0x06</ptp_role>
<init_log_pdelay_req_interval>0x00</init_log_pdelay_req_interval>
<init_log_sync_interval>-0x03</init_log_sync_interval>
<operation_pdelay_req_interval>0x00</operation_pdelay_req_interval>
<operation_sync_interval>-0x03</operation_sync_interval>
<neighbor_prop_delay>0x00000000</neighbor_prop_delay>
</ptp_port_autocds>
<ptp_port_autocds>
<ptp_port_index>0x0009</ptp_port_index>
<ptp_role>0x09</ptp_role>
<init_log_pdelay_req_interval>0x00</init_log_pdelay_req_interval>
<init_log_sync_interval>-0x03</init_log_sync_interval>
<operation_pdelay_req_interval>0x00</operation_pdelay_req_interval>
<operation_sync_interval>-0x03</operation_sync_interval>
<neighbor_prop_delay>0x00000000</neighbor_prop_delay>
</ptp_port_autocds>
</ptp_entity_autocds>
</ptp>
<reg_list>
<entity_order_no>0x0011</entity_order_no>
<entity_enabled>true</entity_enabled>
<op_list_name>internel_phy_mode</op_list_name>
<phy_operation>
<op_name>port1</op_name>
<smi_address>0x0001</smi_address>
<smi_external>false</smi_external>
<offset>0x0834</offset>
<value>0xC001</value>
<clause>0x002D</clause>
<smi_device>0x0001</smi_device>
</phy_operation>
<phy_operation>
<op_name>port2</op_name>
<smi_address>0x0002</smi_address>
<smi_external>false</smi_external>
<offset>0x0834</offset>
<value>0xC001</value>
<clause>0x002D</clause>
<smi_device>0x0001</smi_device>
</phy_operation>
<phy_operation>
<op_name>port3</op_name>
<smi_address>0x0003</smi_address>
<smi_external>false</smi_external>
<offset>0x0834</offset>
<value>0xC000</value>
<clause>0x002D</clause>
<smi_device>0x0001</smi_device>
</phy_operation>
<phy_operation>
<op_name>port4</op_name>
<smi_address>0x0004</smi_address>
<smi_external>false</smi_external>
<offset>0x0834</offset>
<value>0xC000</value>
<clause>0x002D</clause>
<smi_device>0x0001</smi_device>
</phy_operation>
</reg_list>
<reg_list>
<entity_order_no>0x0012</entity_order_no>
<entity_enabled>true</entity_enabled>
<op_list_name>externel_phy_mode</op_list_name>
<phy_operation>
<op_name>2220</op_name>
<smi_address>0x0000</smi_address>
<smi_external>true</smi_external>
<offset>0x0834</offset>
<value>0x8001</value>
<clause>0x002D</clause>
<smi_device>0x0001</smi_device>
</phy_operation>
<phy_operation>
<op_name>2221</op_name>
<smi_address>0x0001</smi_address>
<smi_external>true</smi_external>
<offset>0x0834</offset>
<value>0x8001</value>
<clause>0x002D</clause>
<smi_device>0x0001</smi_device>
</phy_operation>
</reg_list>
</switch_config_1>
二. 固件生成工具链操作
固件生成主要分为两步:配置转换(XML 转 Bin)和 镜像合成(Bin 转 Image)。
生成 Configuration Bin (XML -> Bin)
使用 AutomotiveSwitchV4 工具将编辑好的 XML 配置文件转换为二进制文件。
命令语法:
.\AutomotiveSwitchV4 -switchcfg="final_cfg.xml" -productioncfg="final_cfg_bin.bin" -targetid=<地址>
注意:配置时请确保 XML 中的 Target ID 与实际硬件设计一致。
生成 Secure Image (Bin -> Image)
使用 create_secure_image_v3.exe 将生成的 Config Bin 合并到基础固件中。由于支持双分区或不同的启动偏移,通常需要执行两次命令或指定不同的 Offset。
命令示例:
- 生成第一个分区段(Offset 0x100000):
.\create_secure_image_v3.exe -imagefile="基础固件" -partitionoffset=0x100000 -partitionsize=0x0F0000 -cfgimagefile="final_cfg_bin.bin" -acceptanycfg
- 生成第二个分区段(Offset 0x010000):
.\create_secure_image_v3.exe -imagefile="基础固件" -partitionoffset=0x010000 -partitionsize=0x0F0000 -cfgimagefile="final_cfg_bin.bin" -acceptanycfg
#.\run.ps1 -ProductName "xxxx" -Version "v2.0"
param(
[string]$ProductName = 'xxxx',
[string]$Version = 'v1.0'
)
$SwitchTool = ".\AutomotiveSwitchV4.exe"
$SecureImageTool = "..\create_secure_image_v3.04.0001\create_secure_image_v3.exe"
$BaseImage = "88Q5152_flash_7_5_base.bin"
$DirName = "SwitchConfig_${ProductName}_$(Get-Date -Format 'yyyyMMdd')_${Version}"
New-Item -ItemType Directory -Path $DirName -Force
$configs = @(
@{ChipCpu = "88Q5152_flash"; CfgPrefix = "88Q5152-switch-cfg"; TargetId = 7},
@{ChipCpu = "5192A-cpu0"; CfgPrefix = "5192A-cpu0-switch-cfg"; TargetId = 6},
@{ChipCpu = "5192A-cpu1"; CfgPrefix = "5192A-cpu1-switch-cfg"; TargetId = 7},
@{ChipCpu = "5192B-cpu0"; CfgPrefix = "5192B-cpu0-switch-cfg"; TargetId = 8},
@{ChipCpu = "5192B-cpu1"; CfgPrefix = "5192B-cpu1-switch-cfg"; TargetId = 9}
)
foreach ($config in $configs) {
if ($config.ChipCpu -notlike "*$(if ($ProductName -like 'xxxx*') { '5152' } else { '5192' })*") { continue }
cp ..\${BaseImage} .
& $SwitchTool -switchcfg="..\switch\$($config.CfgPrefix)-${ProductName}.xml" -productioncfg="$($config.CfgPrefix).bin" -targetid="$($config.TargetId)"
& $SecureImageTool -imagefile="$BaseImage" -partitionoffset=0x100000 -partitionsize=0x0F0000 -cfgimagefile="$($config.CfgPrefix).bin" -acceptanycfg
& $SecureImageTool -imagefile="$BaseImage" -partitionoffset=0x010000 -partitionsize=0x0F0000 -cfgimagefile="$($config.CfgPrefix).bin" -acceptanycfg
rm "$($config.CfgPrefix).bin"
mv ${BaseImage} "${DirName}\$($config.ChipCpu)-${Version}.bin" -Force
}
三. Flash 内存布局与烧录脚本
生成最终的固件文件后,我们需要通过管理接口将其写入 Flash。为了保证系统的可靠性,通常采用 双分区(Primary & Secondary) 备份机制。
Flash 内存地址映射 (Memory Map)
根据下文的烧录脚本,我们可以整理出 88Q5152 在 Flash 中的详细内存布局:
分区 (Partition) 组件 (Component) 起始地址 (Offset) 大小 (Size) 描述
Primary TIM 0x010000 0x2000 Trusted Image Module
Primary PIE 0x012000 0x1E000 Packet Instruction Engine
Primary Firmware 0x030000 0x80000 主固件
Primary Configuration 0x0B0000 0x50000 交换机配置
Secondary TIM 0x100000 0x2000 备份 TIM
Secondary PIE 0x102000 0x1E000 备份 PIE
Secondary Firmware 0x120000 0x80000 备份固件
Secondary Configuration 0x1A0000 0x50000 备份配置
自动化烧录脚本 (flash_script_xxx.sh)
以下脚本封装了 MarvFlashImageMP 命令,可一键完成双分区的烧录。
#! /bin/bash
NET_INTERFACE="${3:-mgbe3_0}"
# Function to display usage information
usage() {
echo "Usage: $0 <FIRMWARE_PATH> <CHIP_TYPE>"
#echo "Usage: $0 <LOCAL_MAC_ADDR> <FIRMWARE_PATH> <CHIP_TYPE>"
#echo " LOCAL_MAC_ADDR : The MAC address of mgbe3_0 (Format: XX:XX:XX:XX:XX:XX)"
echo " FIRMWARE_PATH : The full path to the firmware file."
echo " CHIP_TYPE : The chip type (choose from: 5192-A-die0, 5192-A-die1, 5192-B-die0, 5192-B-die1)"
exit 1
}
# Ensure all required parameters are provided
if [ $# -lt 2 ]; then
usage
fi
DOWNLOAD_TOOL="MarvFlashImageMP"
PC_MAC_ADDR=`ifconfig $NET_INTERFACE | grep ether | awk '{print $2}'`
FIRMWARE="$1"
case $2 in
"5192-A-die0")
BANK_MAC_ADDR="02:00:00:01:06:00"
BANK_SMI_ADDR="6"
;;
"5192-A-die1")
BANK_MAC_ADDR="02:00:00:02:07:00"
BANK_SMI_ADDR="7"
;;
"5192-B-die0")
BANK_MAC_ADDR="02:00:00:01:08:00"
BANK_SMI_ADDR="8"
;;
"5192-B-die1")
BANK_MAC_ADDR="02:00:00:02:09:00"
BANK_SMI_ADDR="9"
;;
*)
echo "Invalid chip type provided. Please choose one from: 5192-A-die0, 5192-A-die1, 5192-B-die0, 5192-B-die1."
exit 1
;;
esac
echo "LOCAL_MAC_ADDR is $PC_MAC_ADDR"
echo "FIRMWARE_PATH is $FIRMWARE"
echo "SWITCH_MAC_ADDR is $BANK_MAC_ADDR"
echo -e "\n\nflash Primary Partion - Firmware\n\n"
sleep 2
sudo $DOWNLOAD_TOOL -ha$PC_MAC_ADDR -if"$FIRMWARE" -dt1 -io0x030000 -is0x80000 -da$BANK_MAC_ADDR -dn$BANK_SMI_ADDR || exit
echo -e "\n\nflash Primary Partion - Configuration\n\n"
sleep 2
sudo $DOWNLOAD_TOOL -ha$PC_MAC_ADDR -if"$FIRMWARE" -dt2 -io0x0B0000 -is0x50000 -da$BANK_MAC_ADDR -dn$BANK_SMI_ADDR || exit
echo -e "\n\nflash Primary Partion - PIE\n\n"
sleep 2
sudo $DOWNLOAD_TOOL -ha$PC_MAC_ADDR -if"$FIRMWARE" -dt5 -io0x012000 -is0x1E000 -da$BANK_MAC_ADDR -dn$BANK_SMI_ADDR || exit
echo -e "\n\nflash Primary Partion - TIM\n\n"
sleep 2
sudo $DOWNLOAD_TOOL -ha$PC_MAC_ADDR -if"$FIRMWARE" -dt3 -io0x10000 -is0x2000 -da$BANK_MAC_ADDR -dn$BANK_SMI_ADDR || exit
echo -e "\n\nflash Secondary Partion - Firmware\n\n"
sleep 2
sudo $DOWNLOAD_TOOL -ha$PC_MAC_ADDR -if"$FIRMWARE" -dt1 -io0x120000 -is0x80000 -da$BANK_MAC_ADDR -dn$BANK_SMI_ADDR || exit
echo -e "\n\nflash Secondary Partion - Configuration\n\n"
sleep 2
sudo $DOWNLOAD_TOOL -ha$PC_MAC_ADDR -if"$FIRMWARE" -dt2 -io0x1A0000 -is0x50000 -da$BANK_MAC_ADDR -dn$BANK_SMI_ADDR || exit
echo -e "\n\nflash Secondary Partion - PIE\n\n"
sleep 2
sudo $DOWNLOAD_TOOL -ha$PC_MAC_ADDR -if"$FIRMWARE" -dt5 -io0x102000 -is0x1E000 -da$BANK_MAC_ADDR -dn$BANK_SMI_ADDR || exit
echo -e "\n\nflash Secondary Partion - TIM\n\n"
sleep 2
sudo $DOWNLOAD_TOOL -ha$PC_MAC_ADDR -if"$FIRMWARE" -dt4 -io0x100000 -is0x2000 -da$BANK_MAC_ADDR -dn$BANK_SMI_ADDR || exit
烧录方式
- 保存上述代码为
flash_script_xxx.sh。 - 赋予执行权限:
chmod +x flash_script_xxx.sh。 - 执行烧录(需在开发板系统内并确认 P9 所连接的网卡 MAC):
./flash_script_xxx.sh flash_image.bin 5192-A-die0
注意:脚本中的 BANK0_MAC_ADDR 和 SMI 地址需要改为自己实际板子上 Switch 地址
调试


P6 mirror 到 P5

其他
phytool read eqos_0/0:1/0x834
phytool write eqos_0/0:1/0x834 0xC001 #1G Master
phytool write mgbe0_0/4:1/0x834 0xC006 #10G Master
phytool write mgbe1_0/5:1/0x834 0xC006 #10G Master
phytool write mgbe1_0/5:1/0x905 0x8000 #10G Slave Reset
PTP vlantag



合作base64:ZGFpeGlhbmc3ODlAaWNsb3VkLmNvbQ==

232

被折叠的 条评论
为什么被折叠?



