天嵌 ARM开发社区

 找回密码
 注册
查看: 2252|回复: 0

关于天嵌提供的U-BOOT-1.1.6

[复制链接]
zhongfushun 发表于 2012-8-4 11:38:48 | 显示全部楼层 |阅读模式
最近在学习UBOOT,自已也已成功移植了UBOOT1.1.6版本,但跟天嵌提供的UBOOT1.1.6版本相比,不能引导未加头信息的内核(zImage),于是看了天嵌的UBOOT,详细如下:
1、定义了“boot_zImage”这个命令,命令的函数在lib_arm/boot_zImage.c中实现;
2、执行“boot_zImage”命令时调用do_boot_zImage(), do_boot_zImage()调用boot_zImage(0x200000,0x300000)(传入的参数意义是:0x200000是内核映像文件在NAND的偏移地址,0x300000是内核映像文件的SIZE);
3、在boot_zImage()函数中实现了从NAND拷贝到SDRAM、设置机器ID、设置启动参数等并最终调用call_linux(0, mach_type, to),跳转到内核入口处执行了。

代码如下:

  1. int boot_zImage(ulong from, size_t size)
  2. {
  3. int ret;
  4. ulong boot_mem_base; /* base address of bootable memory */
  5. ulong to;
  6. ulong mach_type;
  7. boot_mem_base = 0x30000000;
  8. /* copy kerne image */
  9. to = boot_mem_base + LINUX_KERNEL_OFFSET;//内核入口地址 = 0x30008000
  10. printf("Copy linux kernel from 0x%08lx to 0x%08lx, size = 0x%08lx ... ",
  11.   from, to, size);
  12. ret = copy_kernel_img(to, (char *)from, size);//从NAND的0x200000处读0x300000大小的内核到0x30008000处
  13. if (ret) {
  14.   printf("failed\n");
  15.   return -1;
  16. } else {
  17.   printf("Copy Kernel to SDRAM done,");
  18. }
  19. if (*(ulong *)(to + 9*4) != LINUX_ZIMAGE_MAGIC) {
  20.   printf("Warning: this binary is not compressed linux kernel image\n");
  21.   printf("zImage magic = 0x%08lx\n", *(ulong *)(to + 9*4));
  22. } else {
  23. //  printf("zImage magic = 0x%08lx\n", *(ulong *)(to + 9*4));
  24.   ;
  25. }
  26. /* Setup linux parameters and linux command line */
  27. setup_linux_param(boot_mem_base + LINUX_PARAM_OFFSET);//0x30000100,设置内存、命令行参数等
  28. /* Get machine type */
  29. mach_type = MACH_TYPE_S3C2440;//机器ID
  30. // printf("MACH_TYPE = %d\n", mach_type);
  31. /* Go Go Go */
  32. printf("NOW, Booting Linux......\n");
  33. call_linux(0, mach_type, to);//启动内核
  34. return 0;
  35. }


  36. //启动内核 r0 = 0,r1 = ID,r2 = 0x30008000
  37. void  call_linux(long a0, long a1, long a2)
  38. {
  39.   local_irq_disable();
  40. cache_clean_invalidate();
  41. tlb_invalidate();
  42. __asm__(
  43. "mov r0, %0\n"
  44. "mov r1, %1\n"
  45. "mov r2, %2\n"
  46. "mov ip, #0\n"
  47. "mcr p15, 0, ip, c13, c0, 0\n" /* zero PID */
  48. "mcr p15, 0, ip, c7, c7, 0\n" /* invalidate I,D caches */
  49. "mcr p15, 0, ip, c7, c10, 4\n" /* drain write buffer */
  50. "mcr p15, 0, ip, c8, c7, 0\n" /* invalidate I,D TLBs */
  51. "mrc p15, 0, ip, c1, c0, 0\n" /* get control register */
  52. "bic ip, ip, #0x0001\n"  /* disable MMU */
  53. "mcr p15, 0, ip, c1, c0, 0\n" /* write control register */
  54. "mov pc, r2\n"//pc = 0x30008000,跳到内核处执行
  55. "nop\n"
  56. "nop\n"
  57. : /* no outpus */
  58. : "r" (a0), "r" (a1), "r" (a2)
  59. : "r0","r1","r2","ip"
  60. );
复制代码
疑问:以上“r2”为什么是内核的入口地址而不是参数的地址,因为还未学习内核,所以不懂。难道这就是zImage和uImage的区别?{:2_30:}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号 )

GMT+8, 2024-6-3 21:03 , Processed in 1.093750 second(s), 20 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表