首页 > 技术文章 > petalinux+nvme, doesn't match header type 01

han-guang-xue 2022-04-13 14:08 原文

说明

petalinux + nvme, 在系统下对ssd盘识别并挂载读写
在逻辑工程师导出对应的hdf文件后,需要通过petalinux去做系统,系统做完之后, 系统能起来, PCI能起来,但是检测设备信息错误如下:

[    2.006434] nwl-pcie fd0e0000.pcie: Link is UP
[    2.010353] OF: PCI: host bridge /amba/pcie@fd0e0000 ranges:
[    2.015954] OF: PCI:   MEM 0xe0000000..0xefffffff -> 0xe0000000
[    2.021827] OF: PCI:   MEM 0x600000000..0x7ffffffff -> 0x600000000
[    2.028076] nwl-pcie fd0e0000.pcie: PCI host bridge to bus 0000:00
[    2.034112] pci_bus 0000:00: root bus resource [bus 00-ff]
[    2.039558] pci_bus 0000:00: root bus resource [mem 0xe0000000-0xefffffff]
[    2.046391] pci_bus 0000:00: root bus resource [mem 0x600000000-0x7ffffffff pref]
[    2.053860] pci 0000:00:00.0: ignoring class 0x058000 (doesn't match header type 01)
[    2.061964] pci 0000:01:00.0: BAR 0: no space for [mem size 0x00004000 64bit]
[    2.068624] pci 0000:01:00.0: BAR 0: failed to assign [mem size 0x00004000 64bit]
[    2.076061] pci 0000:00:00.0: not setting up bridge for bus 0000:01

使用lspci查看

root@mynvme01:~# lspci 
00:00.0 Non-VGA unclassified device: Xilinx Corporation Device d011
01:00.0 Non-Volatile memory controller: Device 1bc0:1002 (rev 01)

解决方案

查看 petalinux源码, pci启动时候 报错信息对应代码如下 doesn't match header type 01
image

整体代码如下: 总共有三处 goto bad;分支
image

因为dev->hdr_type01, 所以代码走PCI_HEADER_TYPE_BRIDGE分支,

	case PCI_HEADER_TYPE_BRIDGE:		    /* bridge header */  //PCI_HEADER_TYPE_BRIDGE 为 1
		if (class != PCI_CLASS_BRIDGE_PCI)   //PCI_CLASS_BRIDGE_PCI 为 0x0604
			goto bad;

也就说是 dev->hdr_type01的时候, class 的值只能是 0x0604, 系统内核才不会报错
class 代码片段如下

1398: u32 class;
// #define PCI_CLASS_REVISION	0x08	/* High 24 bits are class, low 8 revision */
1425: pci_read_config_dword(dev, PCI_CLASS_REVISION, &class);

1427: dev->class = class >> 8;		    /* upper 3 bytes */

1444: class = dev->class >> 8;

可以看出 class是32bit, 最后对比的是 前 16bit 的数据, class 前24bit代表等级
其中 pci_read_config_dword 读取的应该是配置
查看 dev->class 属性
image

可以看出 class 前两个字节分别代表 base 和 sub, 打开 vivado 工程, 点开pci设备, 设置信息如下, 0x0604 即可
image

petalinux 源代码下载地址:
https://github.com/han-guang-xue/linux-xlnx-xilinx-v2018.3
其中相关宏定义和 pci_dev 定义文件如下

linux->linux->pci.h
linux->linux->pci_ids.h
linux->linux->pci_regs.h

推荐阅读