Chinaunix首页 | 论坛 | 博客
  • 博客访问: 438739
  • 博文数量: 78
  • 博客积分: 2030
  • 博客等级: 大尉
  • 技术积分: 1002
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-28 15:25
文章分类

全部博文(78)

文章存档

2012年(1)

2011年(1)

2010年(4)

2009年(12)

2008年(60)

我的朋友

分类: LINUX

2008-10-29 17:51:32

u-boot把所有都链接在一个section里面,方便使用的时候查找。
现在它这个功能,做一个实验。
1. 修改一下u-boot.lds 加入一个section
   jm_start = .;
    .u_boot_jm : { *(.u_boot_jm) }
    jm_end = .;
2. 加入一些自己的内容在这个段里面。
typedef struct _jm {
 int index;
 int (*f)(int args);
}jm_t;

int print_hello(int args)
{
 printf("hello u-boot %d\n", args);
 return 0;
}

jm_t __uboot_jm_test1 __attribute__ ((unused,section (".u_boot_jm"))) = {
  1,
  print_hello,
   
};

jm_t __uboot_jm_test2 __attribute__ ((unused,section (".u_boot_jm"))) = {
  2,
  print_hello,
   
};

jm_t __uboot_jm_test3 __attribute__ ((unused,section (".u_boot_jm"))) = {
  3,
  print_hello,
   
};

jm_t __uboot_jm_test4 __attribute__ ((unused,section (".u_boot_jm"))) = {
  4,
  print_hello,
   
};
extern jm_t  jm_start;
extern jm_t  jm_end;

jm_t *find_jm_entry (int idx)
{
 jm_t *cmdtp;
 const char *p;
 int len;

 for (cmdtp = &jm_start;
      cmdtp != &jm_end;
      cmdtp++) {
  if (idx == cmdtp->index) { 
    printf("found index %d\n", idx);
    return cmdtp; /* full match */   
   
  }
 }

 return NULL; /* not found or ambiguous command */
}
3. u-boot代码搬运后要修改每一项的函数指针
在void board_init_r (gd_t *id, ulong dest_addr)中加入下列代码

for (jmptr = &jm_start; jmptr != &jm_end; jmptr++) {
   ulong addr;
 
   addr = (ulong) (jmptr->f) + gd->reloc_off;
   jmptr->f =    (int(*)(int args))addr;   
  

 }
阅读(1502) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~