zoukankan      html  css  js  c++  java
  • 第1阶段——uboot分析之仿照bootm制作hello命令(7)

    仿照bootm命令生成来制作一个hello命令,功能:打印出hello,world!和参数值

    1.点击New File ,创建cmd_hello.c
    将./common/cmd_bootm.c的头文件复制到 cmd_hello.c中
    (因为cmd_bootm.c的头文件都是包括的命令相关的文件):

    #include <common.h>
    #include <watchdog.h>
    #include <command.h>
    #include <image.h>
    #include <malloc.h>
    #include <zlib.h>
    #include <bzlib.h>
    #include <environment.h>
    #include <asm/byteorder.h>

    2.点击保存:
    保存在./common文件下,(命令文件都存在common文件里)

    3.写执行命令需要调用的函数:
    复制./common/cmd_bootm.c里
    int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
    {
    }
    改成:
    int do_hello (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) //执行命令需要调用的函数
    {
    int i;
    printf ("hello,world!,arg_numble=%d ",argc); //打印"hello,world!"和参数个数arg_numble
    for(i=0;i<argc;i++)
    printf("argv[i]=%s",i,arg[i]); //打印命令名字和参数值

    return 0;
    }

    4. 添加U_BOOT_CMD宏(实现:通过U_BOOT_CMD宏来将命令保存在.u_boot_cmd段里):
    U_BOOT_CMD(
    hello, //命令名
    CFG_MAXARGS, //参数最大值
    1, //支持重复使用命令
    do_hello, //函数指针,用于命令执行时需要调用什么函数,就是第2节的do_hello函数
    "hello - just for help...", //短的使用说明
    "hello - long help... ..." //长的使用说明,敲打"help hello"命令,就会出现这段字符串
    #endif
    );
    5.将cmd_hello.c复制到虚拟机中u-boot-1.1.6/common目录下。
    6.进入common目录,输入"vi mkfine" 修改conmon目录下mkfine,在mkefine第54行,COBJS里添加cmd_hello.o文件
    7.输入"make",生成u-boot.bin文件重新下载就可以使用hello命令了.

    cmd_hello.C源码:

    #include <common.h>
    #include <watchdog.h>
    #include <command.h>
    #include <image.h>
    #include <malloc.h>
    #include <zlib.h>
    #include <bzlib.h>
    #include <environment.h>
    #include <asm/byteorder.h>
    
    int do_hello (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) //执行命令需要调用的函数
    {
    int i;
    printf ("hello,world!,arg_numble=%d
    ",argc); //打印"hello,world!"和参数个数arg_numble 
    for(i=0;i<argc;i++)
    printf("argv[i]=%s",i,arg[i]); //打印参数
    
    return 0;
    }
    U_BOOT_CMD(
    hello,    //命令名
    CFG_MAXARGS, //参数最大值
    1,    //支持重复使用命令
    do_hello, //函数指针,用于命令执行时需要调用什么函数,就是第2节的do_hello函数
    "hello - just for help...
    ", //短的使用说明
    "hello - long help... ...
    " //长的使用说明,敲打"help hello"命令,就会出现这段字符串 
    #endif
    );
  • 相关阅读:
    Javascript进阶(7)---函数参数
    Django连接mssql(SqlServer)
    ORM查询
    Django-Model操作数据库
    Django去操作已经存在的数据库
    如何设置CentOS 7获取动态及静态IP地址
    nginx代理设置
    Django+Linux+Uwsgi+Nginx项目部署文档
    nginx的安装部署
    Django项目在linux系统中虚拟环境部署
  • 原文地址:https://www.cnblogs.com/lifexy/p/7309864.html
Copyright © 2011-2022 走看看