更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
mtd_shellcmd.c 文件参考

浏览源代码.

函数

INT32 osShellCmdPartitionShow (INT32 argc, const CHAR **argv)
 
 SHELLCMD_ENTRY (partition_shellcmd, CMD_TYPE_EX, "partition", XARGS,(CmdCallBackFunc) osShellCmdPartitionShow)
 

函数说明

◆ osShellCmdPartitionShow()

INT32 osShellCmdPartitionShow ( INT32  argc,
const CHAR **  argv 
)

在文件 mtd_shellcmd.c55 行定义.

56{
57 mtd_partition *node = NULL;
58 const CHAR *fs = NULL;
59 partition_param *param = NULL;
60
61 if (argc != 1) {//只接受一个参数
62 PRINT_ERR("partition [nand/spinor]\n");
63 return -EPERM;
64 } else {
65 fs = argv[0];
66 }
67
68 if (strcmp(fs, "nand") == 0) { // #partition nand
69 param = GetNandPartParam(); //获取 nand flash 信息
70 } else if (strcmp(fs, "spinor") == 0) { // #partition spinor
71 param = GetSpinorPartParam(); //获取 spi nor flash 信息
72 } else {
73 PRINT_ERR("not supported!\n");
74 return -EINVAL;
75 }
76
77 if ((param == NULL) || (param->flash_mtd == NULL)) {
78 PRINT_ERR("no partition!\n");
79 return -EINVAL;
80 }
81
82 LOS_DL_LIST_FOR_EACH_ENTRY(node, &param->partition_head->node_info, mtd_partition, node_info) {
83 PRINTK("%s partition num:%u, blkdev name:%s, mountpt:%s, startaddr:0x%08x, length:0x%08x\n",
84 fs, node->patitionnum, node->blockdriver_name, node->mountpoint_name,
85 (node->start_block * param->block_size),
86 ((node->end_block - node->start_block) + 1) * param->block_size);
87 }
88 return ENOERR;
89}
char CHAR
Definition: los_typedef.h:63
partition_param * GetNandPartParam(VOID)
partition_param * GetSpinorPartParam(VOID)
Definition: mtd_partition.c:81
通过mknod在/dev子目录下建立MTD块设备节点(主设备号为31)和MTD字符设备节点(主设备号为90)
CHAR * mountpoint_name
挂载点名称 例如: /
CHAR * blockdriver_name
块设备驱动名称 例如: /dev/spinorblk0p0
UINT32 patitionnum
分区编号
UINT32 end_block
结束块索引
UINT32 start_block
开始块索引
LOS_DL_LIST node_info
双循环节点,挂在首个分区节点上
分区参数描述符,一个分区既可支持按块访问也可以支持按字符访问,只要有驱动程序就阔以
mtd_partition * partition_head
首个分区,其他分区都挂在.node_info节点上
struct MtdDev * flash_mtd
flash设备描述符,属于硬件驱动层
UINT32 block_size
块单位(4K),对文件系统而言是按块读取数据,方便和内存页置换
函数调用图:

◆ SHELLCMD_ENTRY()

SHELLCMD_ENTRY ( partition_shellcmd  ,
CMD_TYPE_EX  ,
"partition"  ,
XARGS  ,
(CmdCallBackFunc osShellCmdPartitionShow 
)