• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
一蓑烟雨
C/C++,Linux,语音技术
博客园    首页    新随笔    联系   管理    订阅  订阅
U-Boot移植(12)u-boot的重要细节

主要过程:查看环境参数stdin,stdout,stderr中对标准IO的指定的设备名称,再按照环境指定的名称搜索devlist,将搜到的设备指针赋给标准IO数组stdio_devices[]。置gd->flag标志 GD_F*G_DEVINIT。这个标志影响putc,getc函数的实现,未定义此标志时直接由串口serial_getc和serial_putc实现,定义以后通过标准设备数组stdio_devices[]中的putc和getc来实现IO。

下面是相关代码:

    void putc (const char c)

         {

         #ifdef CONFIG_SILENT_CONSOLE

          if (gd->flags & GD_F*G_SILENT)//GD_F*G_SILENT无输出标志

           return;

         #endif

          if (gd->flags & GD_F*G_DEVINIT) {//设备list已经初始化

           /* Send to the standard output */

           fputc (stdout, c);

          } else {

           /* Send directly to the handler */

           serial_putc (c);//未初始化时直接从串口输出。

          }

         }

       void fputc (int file, const char c)

        {

         if (file < MAX_FILES)

          stdio_devices[file]->putc (c);

        }

为什么要使用devlist,std_device[]?

为了更灵活地实现标准IO重定向,任何可以作为标准IO的设备,如USB键盘,LCD屏,串口等都可以对应一个device_t的结构体变量,只需要实现getc和putc等函数,就能加入到devlist列表中去,也就可以被assign为标准IO设备std_device中去。如函数

int console_assign (int file, char *devname); /* Assign the console 重定向标准输入输出*/

这个函数功能就是把名为devname的设备重定向为标准IO文件file(stdin,stdout,stderr)。其执行过程是在devlist中查找devname的设备,返回这个设备的device_t指针,并把指针值赋给std_device[file]。

20)enable_interrupts(),使能中断。由于CONFIG_USE_IRQ没有定义,空实现。

    #ifdef CONFIG_USE_IRQ

    /* enable IRQ interrupts */

    void enable_interrupts (void)

    {

     unsigned long temp;

     __asm__ __volatile__("mrs %0, cpsr\n"

            "bic %0, %0, #0x80\n"

            "msr cpsr_c, %0"

            : "=r" (temp)

            :

            : "memory");

    }

    #else

        void enable_interrupts (void)

    { 

    } 

  21)设置CS8900的MAC地址。

  cs8900_get_enetaddr (gd->bd->bi_enetaddr); 

  22)初始化以太网。

  eth_initialize(gd->bd);//bd中已经IP,MAC已经初始化

  23)main_loop ();定义于common/main.c

  至此所有初始化工作已经完毕。main_loop在标准转入设备中接受命令行,然后分析,查找,执行。

参考:http://deshunfan.blog.163.com/blog/static/34244101200972832324749/#comment=fks_083066081081088066083081094095087082083071080087086066

posted on 2011-07-14 15:33  lovemu  阅读(579)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3