使用 JLink 获取 SoC 出厂信息¶
Panchip 会在每一颗量产的 PAN108x SoC 芯片中预写入一些硬件信息,如 UUID、MAC Address 等供用户使用。
有时候,我们需要在最终产品的量产阶段使用这些信息,这里介绍一种使用 JLink Command Line 方式读取这些信息的方法。
例如,为获取 SoC 芯片预存储的蓝牙 MAC Address,我们可以执行以下步骤:
在
<PAN1080-DK>\01_SDK
目录下,新建一个名为GetMacAddress.JLinkScript
的文本文件,填入如下内容并保存:/* * JLink Script File * For more infomation using this script, please refer to Segger Wiki Website: * https://wiki.segger.com/J-Link_script_files#Using_J-Link_script_files */ /* * PAN108X FMC Registers Map: * * #define FLCTL_BASE (0x40050000UL) * #define FLCTL_BUFF_BASE (0x40050400UL) * * #define FLCTL_CTL (0x40050000UL) * #define FLCTL_TRG (0x40050004UL) * #define FLCTL_CONFIG (0x40050005UL) * #define FLCTL_WD0 (0x40050006UL) * #define FLCTL_WD1 (0x40050007UL) * #define FLCTL_WD2 (0x40050008UL) * #define FLCTL_WD3 (0x40050009UL) * #define FLCTL_WD4 (0x4005000AUL) * #define FLCTL_WD5 (0x4005000BUL) * #define FLCTL_X_MODE (0x4005000CUL) */ int GetMacAddressFromFlashInfoArea(void) { U8 flctl_config; U32 flctl_ctl; int offset, size; int i; U8 mac_addr[6]; offset = 0x1B; // offset where stores mac address size = 0x6; // mac address size i = 0; // Enable access of flash info area flctl_config = JLINK_MEM_ReadU8(0x40050005); JLINK_MEM_WriteU8(0x40050005, flctl_config | 0x2); // Read Mac Address from flash info area (offset: 0x1B ~ 0x20) JLINK_MEM_WriteU32(0x40050000, (size << 8) | 0x5); // CTL, configure to read <size> bytes JLINK_MEM_WriteU8(0x40050006, 0x3B); // WD0, CMD_DREAD JLINK_MEM_WriteU8(0x40050007, 0x00); // WD1 JLINK_MEM_WriteU8(0x40050008, 0x00); // WD2 JLINK_MEM_WriteU8(0x40050009, offset); // WD3, configure to read from info <offset> location JLINK_MEM_WriteU8(0x4005000A, 0xFF); // WD4 JLINK_MEM_WriteU8(0x4005000B, 0xFF); // WD5 JLINK_MEM_WriteU8(0x40050004, 0x01); // Trigger flash operation while (JLINK_MEM_ReadU8(0x40050004)) { // busy wait FLCTL_TRG flag cleared JLINK_SYS_Sleep(10); } // Re-disable access of flash info area flctl_config = JLINK_MEM_ReadU8(0x40050005); JLINK_MEM_WriteU8(0x40050005, flctl_config & ~0x2); // Copy data from FLCTL buffer to array mac_addr[6] do { mac_addr[i] = JLINK_MEM_ReadU8(0x40050400 + i); i += 1; } while (i < 6); // Print out Mac Address JLINK_SYS_Report1("Mac Address [0]: ", mac_addr[0]); JLINK_SYS_Report1("Mac Address [1]: ", mac_addr[1]); JLINK_SYS_Report1("Mac Address [2]: ", mac_addr[2]); JLINK_SYS_Report1("Mac Address [3]: ", mac_addr[3]); JLINK_SYS_Report1("Mac Address [4]: ", mac_addr[4]); JLINK_SYS_Report1("Mac Address [5]: ", mac_addr[5]); return 0; } int SetupTarget(void) { JLINK_SYS_Report("SetupTarget()"); GetMacAddressFromFlashInfoArea(); return 0; } int AfterResetTarget(void) { JLINK_SYS_Report("AfterResetTarget()"); return 0; }
双击当前目录下的
PAN1080 SDK CLI
图标,打开 PAN1080 SDK Command Line 命令行界面:输入以下命令并回车:
jlink -autoconnect 1 -device PAN1080XB -if swd -speed 2000 -JLinkScriptFile GetMacAddress.JLinkScript
即可读取到当前 SoC 的 MAC Address:
D:\PDK\pan1080-dk-internal\01_SDK>jlink -autoconnect 1 -device PAN1080XB -if swd -speed 2000 -JLinkScriptFile GetMacAddress.JLinkScript SEGGER J-Link Commander V6.44b (Compiled Mar 15 2019 12:10:40) DLL version V6.44b, compiled Mar 15 2019 12:08:42 Connecting to J-Link via USB...O.K. Firmware: J-Link V9 compiled Oct 25 2018 11:46:07 Hardware version: V9.40 S/N: 59404884 License(s): RDI, GDB, FlashDL, FlashBP, JFlash VTref=3.369V Device "PAN1080XB" selected. Connecting to target via SWD Found SW-DP with ID 0x0BB11477 Scanning AP map to find all available APs AP[1]: Stopped AP scan as end of AP map has been reached AP[0]: AHB-AP (IDR: 0x04770021) Iterating through AP map to find AHB-AP to use AP[0]: Core found AP[0]: AHB-AP ROM base: 0xE00FF000 CPUID register: 0x410CC200. Implementer code: 0x41 (ARM) Found Cortex-M0 r0p0, Little endian. FPUnit: 4 code (BP) slots and 0 literal slots CoreSight components: ROMTbl[0] @ E00FF000 ROMTbl[0][0]: E000E000, CID: B105E00D, PID: 000BB008 SCS ROMTbl[0][1]: E0001000, CID: B105E00D, PID: 000BB00A DWT ROMTbl[0][2]: E0002000, CID: B105E00D, PID: 000BB00B FPB SetupTarget() Mac Address [0]: 0x000000D0 Mac Address [1]: 0x00000000 Mac Address [2]: 0x0000000A Mac Address [3]: 0x00000000 Mac Address [4]: 0x00000009 Mac Address [5]: 0x00000074 Cortex-M0 identified. J-Link>
上述 Log 中,有效信息为末尾的 Mac Address [0] ~ [5],每个 32 bit 数据中,低 8 位为 Mac Address 信息。例如,从上述 Log 可知,当前芯片的 Mac Address 为:0xD0 0x00 0x0A 0x00 0x09 0x74