现在的位置: 首页 > 综合 > 正文

修改Bootp实验

2013年07月20日 ⁄ 综合 ⁄ 共 3668字 ⁄ 字号 评论关闭
修改Bootp实验
实验目的:
1.        修改Bootp,去掉其自动获得IP的功能
2.        重新编译BootLoader,下载到开发板上进行测试
实验原理
1.      bootp的主要功能是使开发板动态获得宿主机分配的IP地址,所以可以设想,如果静态设定开发板的地址信息,就可以在BootLoader中去除bootp。
2.      基于bootp的实现可能牵涉到一些环境变量信息的设置,所以我们没有完全去除bootp的原代码,只是去掉了其获得IP的功能。
实验内容
       1.查看net.h文件,可以发现以下声明:
       extern uchar        clientEther[6];            // Our ethernet address.
       extern ulong        clientIP;        // Our IP addr (0 = unknown).
       extern uchar        hostEther[6];              // Boot server enet address.
       extern ulong        hostIP;                 // Server IP addr (0 = unkn).
       所以,我们可以在BootLoader中的环境变量中设置这些参数。
       2.修改command.c文件,在命令表中增加一条设置参数的命令,这里我们给它起名为       CMD_TBL_SETENV,相应的回调函数为setenv();注意command.c文件需要增加后面提      到的头文件setenv.h,因为setenv.h中声明了CMD_TBL_SETENV参数。
       CMD_TBL cmdTbl[] = {
       CMD_TBL_RELOAD,
       CMD_TBL_BOOTP,
       CMD_TBL_TFTP,
       CMD_TBL_FLASH,
       CMD_TBL_ERASE,
       CMD_TBL_LOCK,
       CMD_TBL_UNLOCK,
       CMD_TBL_BOOT,
       CMD_TBL_MEMCPY,
       CMD_TBL_MEMDUMP,
       CMD_TBL_HEXDUMP,
       CMD_TBL_MEMCMP,
       CMD_TBL_MEMSET,
       CMD_TBL_WRITE,
       CMD_TBL_READ,
       CMD_TBL_STATUS,
       CMD_TBL_REBOOT,
       CMD_TBL_TEST,
       CMD_TBL_SETENV,     //used to set environment,such as ip or ethernet address
       CMD_TBL_END
       };
       3.新建 setenv.c和setenv.h文件如下:
//setenv.h
#include net.h
#define CMD_TBL_SETENV                                                                                                                                  /
                       {"setenv", setenv,                                                                                                         /
                            " setenv                           Set Environment./n",                                        /
                            “setenv [ethaddr/ipaddr/serverip/serverethaddr] [value(s)] all the four        args must be seted and be in sequence”,                                                                                                                                              /
                            " setenv                           Such as (host&developboard)IP and Ethernet        Address./n"                                     /
                            }
       bool setevn(CMD_TBL *cptr, int argc, char **argv);//设置主机和开发板的IP及网卡地址信息
//setenv.c
#include “setenv.h”
bool setevn(CMD_TBL *cptr, int argc, char **argv){
{
//set environment,note that “<=” means pass the right one to the left one
if (argc!=9){
         printf(cptr->usage);
         return false;
 }
 
 if (!StrCmp(argv[1], "ethaddr")){
         clientEther<=argv[2];       
 }
 else if (!StrCmp(argv[3], "ipaddr")){
         clientIP<=argv[4];
 }
 else if (!StrCmp(argv[5], "serverip")){
         hostIP<=argv[6];
 }
 else if(!StrCmp(argv[7], "serverethaddr")){
          hostEther<=argv[8];
 }
 else{
         printf(cptr->usage);
         return false;
 }
 }
}
4.修改bootp.c的bool BootpTx(void)(第50行处)函数如下,使其仅仅显示相关地址信息:
bool BootpTx(void){
         bootpState==BOOTP_SUCCESS)
        
         printf("/tHost   (server) Ethernet : ");
         PrintEthAddr(hostEther);
         printf("/n");
        
        printf("/tHost   (server) IP       : ");
         PrintIPAddr(hostIP);
         printf("/n");
 
         printf("/tClient (target) Ethernet : ");
              PrintEthAddr(clientEther);
              printf("/n");
             
              printf("/tClient (target) IP       : ");
              PrintIPAddr(clientIP);
              printf("/n");
              return true;
       }     // BootpTx.
5.将tftp.c 第80行开始的以下代码删除,因为板子的IP地址已经由环境变量设定:
if (clientIP==0){
          printf("No IP. Bootp start.../n");
          if (DoBootp(0, 0,0)==false){
                 printf("/tBootp failed. try again./n");
                 return false;
          }
6.将改动的代码实现后,在交叉编译环境中重新编译BootLoader,将其下载到开发板进行测试。

 

抱歉!评论已关闭.