ppcboot 添加命令

來源:互聯網
上載者:User

Author-------Dansen-----xzd2734@163.com

因為每次修改核心添加列印資訊需要調試,重新載入核心,不過挺煩的,
需要輸入3條命令,為了調試核心方便,所以要在ppcboot中添加一條簡單
命令來執行這3條命令,這樣調試核心的時候會方便很多了。
先到ppcboot-2.0.0/common/main.c下看看主迴圈是怎樣處理輸入的命令的
 for (;;)
 {
  len = readline (CFG_PROMPT);   //把輸入的命令讀到console_buffer中
  flag = 0;         //並返回所輸入的長度
  if (len > 0)
   strcpy (lastcommand, console_buffer);
  else if (len == 0)
   flag |= CMD_FLAG_REPEAT;

  if (len == -1)
   printf ("<INTERRUPT>/n");
  else
   rc = run_command (lastcommand, flag);
  if (rc <= 0) lastcommand[0] = 0;
 }
顯然是由run_command這個函數去執行輸入的命令了,在run_command中對輸入的命令列進行參數分解,分解的參數由argv指示。
  if ((cmdtp = find_cmd(argv[0])) == NULL) {
   printf ("Unknown command '%s' - try 'help'/n", argv[0]);
   return -1; /* give up after bad command */
  }
通過find_cmd去命令表中,這樣我們就需要在命令表中去添加自己的命令
ppcboot-2.0.0/common/command.c中找到了find_cmd函數,還有命令表。
cmd_tbl_t cmd_tbl[] = {
 CMD_TBL_ASKENV
 CMD_TBL_ASM
....................}
這樣我們就可以在其中添加自己的命令了,我就在最上面添加了CMD_TBL_DANSEN,顯然這是一個宏,
所以還要找到宏的定義,參考其它的宏定義,把CMD_TBL_DANSEN的定義為
#define CMD_TBL_DANSEN  MK_CMD_TBL_ENTRY(    /
 "dansen", 3, CFG_MAXARGS, 0, do_dansen,  /
 "dansen  - do tftp 30008000 zImage/n"     /
 "        tftp 30800000 ramdisk.image.gz/n"    /
 "       go 30008000/n",      /
 "enter dansen or more than dan,it is eazy,hehe/n"   /
),
為了方便我們可以直接把CMD_TBL_DANSEN定義在command.c中,可以看到,在command.c中也有類似的表項定義的。然後還要添加命令真正的執行函數do_dansen
int do_dansen   (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
 run_command("tftp 30008000 zImage",0);
 run_command("tftp 30800000 ramdisk.image.gz",0);
 run_command("go 30008000",0);
 return 1;
}
編譯以後可以燒到flash中,ok
不過還可以再方便點,我在沒入主迴圈前添加代碼,這樣只要在啟動時判斷輸入的鍵就可以了。不輸入或輸入是y的話從flash啟動,輸入d的話是從主機tftp啟動,其他的話就進入命令列
bootm:
  if(c == 'y'||c == 'Y')
  {
   strcpy(lastcommand , "bootm 30008000 30800000");
   flag = 0;
   rc = run_command (lastcommand, flag);
   if (rc <= 0)
   {
    lastcommand[0] = 0;
   }
  }
  else
  {
   printf("/n/n");
  }
修改上面的代碼為
bootm:
  if(c == 'y'||c == 'Y')
  {
   strcpy(lastcommand , "bootm 30008000 30800000");
   flag = 0;
   rc = run_command (lastcommand, flag);
   if (rc <= 0)
   {
    lastcommand[0] = 0;
   }
  }
  else if(c == 'd'||c == 'Y')
  {
   strcpy(lastcommand , "tftp 30008000 zImage");
   run_command(lastcommand,0);
   strcpy(lastcommand , "tftp 30800000 ramdisk.image.gz");
   run_command(lastcommand,0);
   strcpy(lastcommand , "go 30008000");
   run_command(lastcommand,0);
  }
  else
  {
   printf("/n/n");
  }
這樣調試可以方便好多了,千萬別把ppcboot弄壞了,不然又要用JTAG重新燒寫,要等好久.用ppcboot自己更新自己方便多了.
ppcboot的一些參數可以在ppcboot-2.0.0/include/configs/smdk2410.h中修改. 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.