OK6410 uboot1.1.16/lib.arm的board.c相关函数分析(C语言执行的第一个函数start_armboot)

本文主要分析了OK6410设备上uboot1.1.16版本中lib.arm目录下的board.c文件中的关键函数,特别是C语言执行的第一个函数start_armboot,内容涉及链接器、优化和闪存操作。

在分析该函数之前,首先贴两个图

uboot存储器映射
uboot、地址空间分配图
贴上相关代码
void start_armboot (void)
{
 init_fnc_t **init_fnc_ptr;
 char *s;
#ifndef CFG_NO_FLASH
 ulong size;
#endif
#if defined(CONFIG_VFD) || defined(CONFIG_LCD)
 unsigned long addr;
#endif
#if defined(CONFIG_BOOT_MOVINAND)
 uint *magic = (uint *) (PHYS_SDRAM_1);
#endif
 /* Pointer is writable since we allocated a register for it */
#ifdef CONFIG_MEMORY_UPPER_CODE /* by scsuh */
 ulong gd_base;
 gd_base = CFG_UBOOT_BASE + CFG_UBOOT_SIZE - CFG_MALLOC_LEN - CFG_STACK_SIZE - sizeof(gd_t);
#ifdef CONFIG_USE_IRQ
 gd_base -= (CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ);
#endif
 gd = (gd_t*)gd_base;
#else
 gd = (gd_t*)(_armboot_start - CFG_MALLOC_LEN - sizeof(gd_t));
#endif
 /* compiler optimization barrier needed for GCC >= 3.4 */
 __asm__ __volatile__("": : :"memory");
 memset ((void*)gd, 0, sizeof (gd_t));
 gd->bd = (bd_t*)((char*)gd - sizeof(bd_t));
 memset (gd->bd, 0, sizeof (bd_t));
 monitor_flash_len = _bss_start - _armboot_start;
 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
  if ((*init_fnc_ptr)() != 0) {
   hang ();
  }
 }
#ifndef CFG_NO_FLASH
 /* configure available FLASH banks */
 size = flash_init ();
 display_flash_config (size);
#endif /* CFG_NO_FLASH */
#ifdef CONFIG_VFD
# ifndef PAGE_SIZE
#   define PAGE_SIZE 4096
# endif
 /*
  * reserve memory for VFD display (always full pages)
  */
 /* bss_end is defined in the board-specific linker script */
 addr = (_bss_end + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
 size = vfd_setmem (addr);
 gd->fb_base = addr;
#endif /* CONFIG_VFD */
#ifdef CONFIG_LCD
# ifndef PAGE_SIZE
#   define PAGE_SIZE 4096
# endif
 /*
  * reserve memory for LCD display (always full pages)
  */
 /* bss_end is defined in the board-specific linker script */
 addr = (_bss_end + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
 size = lcd_setmem (addr);
 gd->fb_base = addr;
#endif /* CONFIG_LCD */
 /* armboot_start is defined in the board-specific linker script */
#ifdef CONFIG_MEMORY_UPPER_CODE /* by scsuh */
 mem_malloc_init (CFG_UBOOT_BASE + CFG_UBOOT_SIZE - CFG_MALLOC_LEN - CFG_STACK_SIZE);
#else
 mem_malloc_init (_armboot_start - CFG_MALLOC_LEN);
#endif
#if defined(CONFIG_SMDK6400) || defined(CONFIG_SMDK6410) || defined(CONFIG_SMDK6430) || defined(CONFIG_SMDK2450) || defined(CONFIG_SMDK2416)
#if defined(CONFIG_NAND)
 puts ("NAND:    ");
 nand_init();  /* go init the NAND */
#endif
#if defined(CONFIG_ONENAND)
 puts ("OneNAND: ");
 onenand_init();  /* go init the One-NAND */
#endif
#if defined(CONFIG_BOOT_MOVINAND)
 puts ("SD/MMC:  ");
 if ((0x24564236 == magic[0]) && (0x20764316 == magic[1])) {
  printf("Boot up for burning/n");
 } else {
  movi_set_capacity();
  movi_set_ofs(MOVI_TOTAL_BLKCNT);
  movi_init();
 }
#endif
#else
#if (CONFIG_COMMANDS & CFG_CMD_NAND)
 puts ("NAND:    ");
 nand_init();  /* go init the NAND */
#endif
#endif
#ifdef CONFIG_HAS_DATAFLASH
 AT91F_DataflashInit();
 dataflash_print_info();
#endif
 /* initialize environment */
 env_relocate ();
 
#ifdef CONFIG_VFD
 /* must do this after the framebuffer is allocated */
 drv_vfd_init();
#endif /* CONFIG_VFD */
 /* IP Address */
 gd->bd->bi_ip_addr = getenv_IPaddr ("ipaddr");
 /* MAC Address */
 {
  int i;
  ulong reg;
  char *s, *e;
  char tmp[64];
  i = getenv_r ("ethaddr", tmp, sizeof (tmp));
  s = (i > 0) ? tmp : NULL;
  for (reg = 0; reg < 6; ++reg) {
   gd->bd->bi_enetaddr[reg] = s ? simple_strtoul (s, &e, 16) : 0;
   if (s)
    s = (*e) ? e + 1 : e;
  }
#ifdef CONFIG_HAS_ETH1
  i = getenv_r ("eth1addr", tmp, sizeof (tmp));
  s = (i > 0) ? tmp : NULL;
  for (reg = 0; reg < 6; ++reg) {
   gd->bd->bi_enet1addr[reg] = s ? simple_strtoul (s, &e, 16) : 0;
   if (s)
    s = (*e) ? e + 1 : e;
  }
#endif
 }
 devices_init (); /* get the devices list going. */
#ifdef CONFIG_CMC_PU2
 load_sernum_ethaddr ();
#endif /* CONFIG_CMC_PU2 */
 jumptable_init ();
 console_init_r (); /* fully init console as a device */
#if defined(CONFIG_MISC_INIT_R)
 /* miscellaneous platform dependent initialisations */
 misc_init_r ();
#endif
 /* enable exceptions */
 enable_interrupts ();
 /* Perform network card initialisation if necessary */
#ifdef CONFIG_DRIVER_CS8900
 //cs8900_get_enetaddr (gd->bd->bi_enetaddr);
#endif
#if defined(CONFIG_DRIVER_SMC91111) || defined (CONFIG_DRIVER_LAN91C96)
 if (getenv ("ethaddr")) {
  smc_set_mac_addr(gd->bd->bi_enetaddr);
 }
#endif /* CONFIG_DRIVER_SMC91111 || CONFIG_DRIVER_LAN91C96 */
 /* Initialize from environment */
 if ((s = getenv ("loadaddr")) != NULL) {
  load_addr = simple_strtoul (s, NULL, 16);
 }
#if (CONFIG_COMMANDS & CFG_CMD_NET)
 if ((s = getenv ("bootfile")) != NULL) {
  copy_filename (BootFile, s, sizeof (BootFile));
 }
#endif /* CFG_CMD_NET */
#ifdef BOARD_LATE_INIT
 board_late_init ();
#endif
#if (CONFIG_COMMANDS & CFG_CMD_NET)
#if defined(CONFIG_NET_MULTI)
 puts ("Net:     ");
#endif
 eth_initialize(gd->bd);
#endif
 /* main_loop() can return to retry autoboot, if so just run it again. */
 for (;;) {
  main_loop ();
 }
 /* NOTREACHED - no way out of command loop except booting */
}
接下来就该分析该函数了,太晚了,明天继续,哈哈
你遇到的这个 `git checkout` 错误是因为 **当前工作目录中存在“未被 Git 跟踪”的文件(untracked files)**,而这些文件在你要切换到的目标分支 `remotes/origin/nvr_iterator_v18_security` 中是**被跟踪的**。 Git 担心如果你切换分支,这些已存在的本地文件会被目标分支中的同名文件覆盖,造成数据丢失,因此 **中止操作并提示你处理这些冲突文件**。 --- ### 🔍 错误信息解析 ```bash error: The following untracked working tree files would be overwritten by checkout: uboot/mboot/lib/lib_uip/apps/httpd/webs/.rsrc/404.html ... Please move or remove them before you can switch branches. Aborting ``` - 这些文件目前是 **“未跟踪”(untracked)** —— 即它们不在当前分支的 Git 索引中。 - 但在目标分支 `nvr_iterator_v18_security` 中,这些文件是 **被 Git 跟踪的**。 - 所以 Git 不允许直接切换,防止你丢失当前这些文件的内容。 --- ## ✅ 解决方案 你可以根据你的需求选择以下几种方式之一来解决: --- ### ✅ 方案 1:删除这些 untracked 文件(最常见) 如果你确定这些文件是你自己生成的、临时的或不需要保留的,可以直接删除: ```bash git clean -fd -- \ uboot/mboot/lib/lib_uip/apps/httpd/webs/.rsrc/ \ uboot/mboot/lib/lib_uip/apps/httpd/webs/common/ \ uboot/mboot/lib/lib_uip/apps/httpd/webs/fsdata.c \ uboot/mboot/lib/lib_uip/apps/httpd/webs/makefsdatac \ uboot/mboot/lib/lib_uip/apps/httpd/webs/product_spec/ ``` 或者更简单粗暴(慎用!): ```bash # 删除所有 untracked 文件和目录 git clean -fd ``` > ⚠️ 警告:`git clean -fd` 会永久删除所有未跟踪的文件,请确保没有重要数据! 然后再尝试切换分支: ```bash git checkout remotes/origin/nvr_iterator_v18_security ``` --- ### ✅ 方案 2:先暂存(stash)这些文件(如果你想保留) 但注意:`git stash` 默认不包含 untracked 文件。你需要加上 `-u` 参数: ```bash # 暂存包括 untracked 文件在内的所有更改 git stash push -u -m "save untracked web files" ``` 然后切换分支: ```bash git checkout remotes/origin/nvr_iterator_v18_security ``` > 注意:这可能会失败,因为 `checkout` 时仍然要写入那些路径。所以推荐先用 `git clean` 或手动备份。 更好的做法是: --- ### ✅ 方案 3:手动备份 → 清理 → 切换 → 恢复(推荐用于重要文件) ```bash # 1. 创建备份目录 mkdir ~/backup_web_resources # 2. 复制你想保留的文件 cp -r uboot/mboot/lib/lib_uip/apps/httpd/webs/.rsrc/ ~/backup_web_resources/ cp -r uboot/mboot/lib/lib_uip/apps/httpd/webs/common/ ~/backup_web_resources/ cp uboot/mboot/lib/lib_uip/apps/httpd/webs/fsdata.c ~/backup_web_resources/ cp uboot/mboot/lib/lib_uip/apps/httpd/webs/makefsdatac ~/backup_web_resources/ cp -r uboot/mboot/lib/lib_uip/apps/httpd/webs/product_spec/ ~/backup_web_resources/ # 3. 删除这些 untracked 文件以便切换分支 git clean -fd -- \ uboot/mboot/lib/lib_uip/apps/httpd/webs/.rsrc/ \ uboot/mboot/lib/lib_uip/apps/httpd/webs/common/ \ uboot/mboot/lib/lib_uip/apps/httpd/webs/fsdata.c \ uboot/mboot/lib/lib_uip/apps/httpd/webs/makefsdatac \ uboot/mboot/lib/lib_uip/apps/httpd/webs/product_spec/ ``` 现在可以安全切换: ```bash git checkout remotes/origin/nvr_iterator_v18_security ``` 之后如果需要,再把备份恢复回去进行对比或合并。 --- ### ✅ 方案 4:使用 `--force`?❌ 不推荐! 虽然你可以强行覆盖: ```bash git checkout -f remotes/origin/nvr_iterator_v18_security ``` 但即使这样,Git 依然不会允许你覆盖 untracked 文件(这是保护机制),所以仍然会失败。 除非你先清理掉 untracked 文件,否则 `-f` 也没用。 --- ### ✅ 方案 5:检查这些文件是否应该被忽略(`.gitignore`) 如果你发现这些文件本就不该被提交(比如是构建产物),那么你应该确认 `.gitignore` 是否配置正确。 例如,在 `.gitignore` 中添加: ```gitignore uboot/mboot/lib/lib_uip/apps/httpd/webs/.rsrc/ uboot/mboot/lib/lib_uip/apps/httpd/webs/common/ uboot/mboot/lib/lib_uip/apps/httpd/webs/fsdata.c uboot/mboot/lib/lib_uip/apps/httpd/webs/makefsdatac ``` 但这对当前问题帮助不大,因为你只是想切换分支。 --- ## 🧩 补充知识:remote branch 怎么变成本地分支? 你现在执行的是: ```bash git checkout remotes/origin/nvr_iterator_v18_security ``` 这是一个“远程分支”,不能直接编辑。Git 会进入“分离头指针”状态。 建议创建一个本地跟踪分支: ```bash git checkout -b nvr_iterator_v18_security origin/nvr_iterator_v18_security ``` 这样你就有了一个本地分支,并自动设置上游。 --- ## ✅ 最终推荐流程 ```bash # 1. 备份关键 untracked 文件(可选) mkdir ~/backup_nvr_webs cp -r uboot/mboot/lib/lib_uip/apps/httpd/webs/.rsrc/ ~/backup_nvr_webs/ cp -r uboot/mboot/lib/lib_uip/apps/httpd/webs/common/ ~/backup_nvr_webs/ cp uboot/mboot/lib/lib_uip/apps/httpd/webs/fsdata.c ~/backup_nvr_webs/ cp uboot/mboot/lib/lib_uip/apps/httpd/webs/makefsdatac ~/backup_nvr_webs/ cp -r uboot/mboot/lib/lib_uip/apps/httpd/webs/product_spec/ ~/backup_nvr_webs/ # 2. 清理 untracked 文件 git clean -fd -- \ uboot/mboot/lib/lib_uip/apps/httpd/webs/.rsrc/ \ uboot/mboot/lib/lib_uip/apps/httpd/webs/common/ \ uboot/mboot/lib/lib_uip/apps/httpd/webs/fsdata.c \ uboot/mboot/lib/lib_uip/apps/httpd/webs/makefsdatac \ uboot/mboot/lib/lib_uip/apps/httpd/webs/product_spec/ # 3. 切换分支 git checkout -b nvr_iterator_v18_security origin/nvr_iterator_v18_security ``` ---
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值