u-boot 2016.05 添加u-boot cmd
2024-08-29 03:40:57
记录一下如何在u-boot 添加一个自己想要的命令。
首先来看一下宏,include/command.h
218 #define U_BOOT_CMD(_name, _maxargs, _rep, _cmd, _usage, _help) \
219 U_BOOT_CMD_COMPLETE(_name, _maxargs, _rep, _cmd, _usage, _help, NULL)
U_BOOT_CMD 宏第一个参数是你的命令的名字。
第二个参数你最大参数个数
第三个参数是是否能复用。
第四个参数是实现的函数名
第五个简单说明。
后面是help
- 举例:
nandecc.c
#include <common.h>
#include <linux/mtd/mtd.h>
#include <command.h>
#include <console.h>
#include <watchdog.h>
#include <malloc.h>
#include <asm/byteorder.h>
#include <jffs2/jffs2.h>
#include <nand.h>
#include <asm/io.h>
#include <asm/errno.h>
#if defined(CONFIG_SOC_KEYSTONE)
#include <asm/ti-common/ti-gpmc.h>
#else
#include <asm/arch/mem.h>
#endif
#include <linux/mtd/omap_gpmc.h>
#include <linux/mtd/nand_ecc.h>
#include <linux/bch.h>
#include <linux/compiler.h>
#include <nand.h>
#include <linux/mtd/omap_elm.h>
#include <dm.h>
#ifdef CONFIG_CMD_NANDECC
extern void omap_nand_switch_ecc(nand_ecc_modes_t hardware, int32_t mode);
static int do_switch_ecc(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
{
int type = 1;
if (argc < 2)
goto usage;
if (strncmp(argv[1], "hw", 2) == 0) {
if (argc == 3)
type = simple_strtoul(argv[2], NULL, 10);
omap_nand_switch_ecc(NAND_ECC_HW, type);
}
else if (strncmp(argv[1], "sw", 2) == 0)
omap_nand_switch_ecc(NAND_ECC_NONE, 1);
else
goto usage;
return 0;
usage:
printf("Usage: nandecc %s\n", cmdtp->usage);
return 1;
}
U_BOOT_CMD(
nandecc, 3, 1, do_switch_ecc,
"Switch NAND ECC calculation algorithm b/w hardware and software",
"[sw|hw <hw_type>] \n"
" [sw|hw]- Switch b/w hardware(hw) & software(sw) ecc algorithm\n"
" hw_type- 0 for Hamming code\n"
" 4 for bch4\n"
" 8 for bch8\n"
" 16 for bch16\n"
);
#endif
- 将该文件添加进所属文件的Makefile,上述例子所在目录是cmd 目录。
我将在该目录里面加入如下选项:
cat cmd/Makefile
//...
98 obj-$(CONFIG_CMD_NANDECC) += nandecc.o
//...
- 然后在你的config.h 里面添加相关宏定义开关:
cat include/configs/am335x_sbc7109.h
//...
343 #define CONFIG_CMD_NANDECC
//...
- 然后启动u-boot ,看是否有nandecc 这条命令。有即成功加入。
最新文章
- listbox 多选删除(找了好多都不行,终于让我写出来了)
- 高性能javascript(记录一)
- LeetCode Combination Sum III
- windows p12(pfx)个人证书安装过程
- scala高级内容(二) - Implicit
- Android Monkey测试
- Matlab工具箱安装体会
- caffe源码阅读(3)-Datalayer
- visual studio vs2010 vs2013 显示详细调试信息方法;vs debug 出错怎么办,你需要的不是答案,是方法。
- ##DAY12 UITableViewCell自定义
- CSS3秘笈:第十三章
- python_求相邻数
- 201521123108《Java程序设计》第3周学习总结
- 十八、泛型 l 注解 l Servlet3.0 l 动态代理 l 类加载器基础加强
- SpringBoot四大核心
- 用redis构建分布式锁
- 使用Sphinx为你的python模块自动生成文档
- 收藏点webservice接口
- 导出导入grafana完整的dashboard(非单个图表)
- Java动态代理(三)——模拟AOP实现
热门文章
- java.lang.UnsupportedClassVersionError: org/hibernate/SessionFactory : Unsupported major.minor version 52.0
- java 安装配置时出现的问题
- HDUOJ----湫湫系列故事——减肥记I
- 如何用python的装饰器定义一个像C++一样的强类型函数
- Eclipse智能提示设置
- 【js】with 语句
- js实现多物体运动框架并兼容各浏览器
- HttpClient详解,Java发送Http的post、get方式请求 --待整理
- sklearn 中的交叉验证
- 模拟HTTP请求获取返回值