打开menuconfig
make menuconfig
查找nvme配置,在Kconfig页面输入:/nvme
Symbol: NVME [=n]
Type : boolean
Prompt: NVM Express device support
Location:
(1) -> Device Drivers
Defined at drivers/nvme/Kconfig:7
Depends on: BLK [=y] && PCI [=n]
Symbol: CMD_NVME [=y]
Type : boolean
Prompt: nvme
Location:
-> Command line interface
(2) -> Device access commands
Defined at cmd/Kconfig:885
Depends on: NVME [=y]
由上述搜索信息可知nvme命令的配置开关是CMD_NVME 在--> Command line interface - -> Device access commands 中可以打开而CMD_NVME依赖于NVME设备需要先打开nvme设备。有搜索信息可知NVME在-> Device Drivers-->NVM Express device support当我们进入Device Drivers中没有发现该选项。继续查看帮助信息可知NVME依赖于两个配置“BLK“和”PCI“,已知BLK为yPCI为n此时需要我们打开PCI功能。
选中Device Drivers --->PCI support并配置成y后即可出现NVM Express device support选项。我们选中该选项即打开NVME设备。
此时回到Kconfig顶层目录进入CMD_NVME 在--> Command line interface - -> Device access commands 中我们发现nvme选项已经出现并被自动选中,我们退出尝试编译:
#把配置信息保存到 defconfig 文件中
make savedefconfig
#用 defconfig 文件替换 rk3588_defconfig
cp defconfig configs/rk3588_defconfig
#编译
./make.sh CROSS_COMPILE=/home/xxxx/rk3588_linux_sdk/prebuilts/gcc/linux-x86/aarch64/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu- rk3588
编译后发现有报错:
drivers/nvme/nvme.c: 在函数‘nvme_blk_probe’中:
drivers/nvme/nvme.c:724:39: 错误: invalid use of undefined type ‘struct pci_child_platdata’
724 | sprintf(desc->vendor, "0x%.4x", pplat->vendor);
| ^~
drivers/nvme/nvme.c: 在函数‘nvme_probe’中:
drivers/nvme/nvme.c:851:14: 错误: implicit declaration of function ‘dm_pci_map_bar’; did you mean ‘pci_map_bar’? [-Werror=implicit-function-declaration]
851 | ndev->bar = dm_pci_map_bar(udev, PCI_BASE_ADDRESS_0,
| ^~~~~~~~~~~~~~
| pci_map_bar
drivers/nvme/nvme.c:851:12: 错误: assignment to ‘struct nvme_bar *’ from ‘int’ makes pointer from integer without a cast [-Werror=int-conversion]
851 | ndev->bar = dm_pci_map_bar(udev, PCI_BASE_ADDRESS_0,
| ^
cc1:所有的警告都被当作是错误
make[2]: *** [scripts/Makefile.build:281:drivers/nvme/nvme.o] 错误 1
查找结构体发现在./include/pci.h +813 中有定义我们打开头文件
#ifdef CONFIG_DM_PCI
/**
* struct pci_child_platdata - information stored about each PCI device
*
* Every device on a PCI bus has this per-child data.
*
* It can be accessed using dev_get_parent_priv(dev) if dev->parent is a
* PCI bus (i.e. UCLASS_PCI)
*
* @devfn: Encoded device and function index - see PCI_DEVFN()
* @vendor: PCI vendor ID (see pci_ids.h)
* @device: PCI device ID (see pci_ids.h)
* @class: PCI class, 3 bytes: (base, sub, prog-if)
*/
struct pci_child_platdata {
int devfn;
unsigned short vendor;
unsigned short device;
unsigned int class;
};
头文件显示需要CONFIG_DM_PCI即可编译
我们打开menuconfig找到CONFIG_DM_PCI即:Device Drivers --->PCI support--> Enable driver model for PCI 选中后会弹出三个提示框,我们尝试选中其中两个[] Enable compatible functions for PCI []Rockchip DesignWare PCIe controller
继续编译无报错,编译完成后烧录后即可使用该命令。
=> nvme
nvme - NVM Express sub-system
Usage:
nvme scan - scan NVMe devices
nvme detail - show details of current NVMe device
nvme info - show all available NVMe devices
nvme device [dev] - show or set current NVMe device
nvme part [dev] - print partition table of one or all NVMe devices
nvme read addr blk# cnt - read `cnt' blocks starting at block
`blk#' to memory address `addr'
nvme write addr blk# cnt - write `cnt' blocks starting at block
`blk#' from memory address `addr'
=>
至此nvme命令配置完成。打开的配置如下
CONFIG_NVME=y
CONFIG_PCI=y
CONFIG_DM_PCI=y
CONFIG_DM_PCI_COMPAT=y
CONFIG_PCIE_DW_ROCKCHIP=y