unsigned int go_exec (u32 run_addr, u32 para_addr, int out_secure) { if(out_secure) { //切换到非安全模式 asm volatile("stmfd sp!, {r0, r1}"); struct spare_boot_head_t *bfh = (struct spare_boot_head_t *)para_addr; toc0_private_head_t *toc0 = (toc0_private_head_t *)CONFIG_SBROMSW_BASE; int boot_type = toc0->platform[0]; uint dram_size; if(!boot_type) { boot_type = 1; } else if(boot_type == 1) { boot_type = 0; }else if(boot_type == 2){ //char storage_data[384]; // 0-159,存储nand信息;160-255,存放卡信息^M set_mmc_para(2,(void *)(toc0_config->storage_data+160)); } printf("storage_type=%d\n", boot_type); bfh->boot_data.storage_type = boot_type; if(out_secure == SECURE_SWITCH_NORMAL) { bfh->boot_data.secureos_exist = 1; sunxi_spc_set_to_ns(0); } dram_size = toc0_config->dram_para[4] & 0xffff; if(out_secure == SECURE_SWITCH_NORMAL) { printf("dram =%d M, reserved size = %d M\n", dram_size, toc0_config->secure_dram_mbytes); sunxi_smc_config(dram_size, toc0_config->secure_dram_mbytes); printf("switch to ns\n"); memcpy(bfh->boot_data.dram_para, toc0_config->dram_para, 32 * 4); bfh->boot_data.dram_para[4] -= toc0_config->secure_dram_mbytes; } else { printf("still in secure world \n"); printf("dram = %d M \n",dram_size); bfh->boot_data.secureos_exist = 0; memcpy(bfh->boot_data.dram_para, toc0_config->dram_para, 32 * 4); } asm volatile("ldmfd sp!, {r0, r1}"); //if(out_secure == SECURE_SWITCH_NORMAL) //asm volatile("bx %0"::"r" (secure_switch_unsecure)); // else asm volatile("blx %0"::"r" (secure_switch_other)); } else {
/******************************************************************************* *函数名称: load_boot1_from_sdmmc *函数原型:int32 load_boot1_from_sdmmc( __u8 card_no ) *函数功能: 将一份好的Boot1从sdmmc flash中载入到SRAM中。 *入口参数: void *返 回 值: OK 载入并校验成功 * ERROR 载入并校验失败 *备 注: *******************************************************************************/ __s32 load_boot1_from_sdmmc( char *buf) { __u32 length; __s32 card_no, i; struct spare_boot_head_t *bfh = (struct spare_boot_head_t *) CONFIG_SYS_TEXT_BASE;; boot_sdcard_info_t *sdcard_info = (boot_sdcard_info_t *)buf; i = BT0_head.boot_head.platform[0]; printf("card boot number = %d\n", i); //for(i=0;i<4;i++) { /* open sdmmc */ card_no = i; printf("card no is %d\n", card_no); if(card_no < 0) { printf("bad card number %d in card boot\n", card_no); goto __card_op_fail__; } printf("sdcard %d line count %d\n", card_no, sdcard_info->line_count[i] ); if(!sdcard_info->line_count[i]) { sdcard_info->line_count[i] = 4; } if( sunxi_mmc_init( card_no, sdcard_info->line_count[i], BT0_head.prvt_head.storage_gpio, 16 ) == -1) //高速卡,4线配置 { printf("Fail in Init sdmmc.\n"); goto __card_op_fail__; } printf("sdcard %d init ok\n", card_no); #ifndef CONFIG_SUNXI_SECURE_SYSTEM /* load 1k uboot head */ if( mmc_bread( card_no, UBOOT_START_SECTOR_IN_SDMMC, 1024/512, (void *)CONFIG_SYS_TEXT_BASE ) != (1024/512)) { printf("Fail in reading uboot head.\n"); goto __card_op_fail__; } /* check head */ if( check_magic( (__u32 *)CONFIG_SYS_TEXT_BASE, UBOOT_MAGIC ) != 0 ) { printf("ERROR! NOT find the head of uboot.\n"); goto __card_op_fail__; } /* check length */ length = bfh->boot_head.length; printf("The size of uboot is %x.\n", length ); if( ( length & ( 8 * 1024 - 1 ) ) != 0 ) { printf("boot0 length is NOT align.\n"); goto __card_op_fail__; } if( mmc_bread( card_no, UBOOT_START_SECTOR_IN_SDMMC, length/512, (void *)CONFIG_SYS_TEXT_BASE )!= (length/512)) { printf("Fail in reading uboot head.\n"); goto __card_op_fail__; } /* 检查校验和 */ if( check_sum( (__u32 *)CONFIG_SYS_TEXT_BASE, length ) != 0 ) { printf("Fail in checking uboot.\n"); goto __card_op_fail__; } #else uint start_sector = UBOOT_START_SECTOR_IN_SDMMC - (UBOOT_START_SECTOR_PRE_IN_SDMMC - UBOOT_START_SECTOR_IN_SDMMC); do { start_sector += UBOOT_START_SECTOR_PRE_IN_SDMMC - UBOOT_START_SECTOR_IN_SDMMC; if(start_sector > UBOOT_START_SECTOR_PRE_IN_SDMMC) { printf("read all u-boot blk failed\n"); goto __card_op_fail__; } /* load 1k uboot head */ if( mmc_bread( card_no, start_sector, 1024/512, (void *)CONFIG_SYS_TEXT_BASE ) != (1024/512)) { printf("Fail in reading uboot head.\n"); continue; } /* check head */ if( check_magic( (__u32 *)CONFIG_SYS_TEXT_BASE, UBOOT_MAGIC ) != 0 ) { printf("ERROR! NOT find the head of uboot.\n"); continue; } /* check length */ length = bfh->boot_head.length; printf("The size of uboot is %x.\n", length ); if( ( length & ( 8 * 1024 - 1 ) ) != 0 ) { printf("boot0 length is NOT align.\n"); continue; } if( mmc_bread( card_no, start_sector, length/512, (void *)CONFIG_SYS_TEXT_BASE )!= (length/512)) { printf("Fail in reading uboot head.\n"); continue; } /* 检查校验和 */ if( check_sum( (__u32 *)CONFIG_SYS_TEXT_BASE, length ) != 0 ) { printf("Fail in checking uboot.\n"); continue; } break; } while(1); #endif if(i == 0) { bfh->boot_data.storage_type = 1; } else { bfh->boot_data.storage_type = 2; set_mmc_para(2,(void *)&BT0_head.prvt_head.storage_data); } printf("Succeed in loading uboot from sdmmc flash.\n"); sunxi_mmc_exit( card_no, BT0_head.prvt_head.storage_gpio, 16 ); return 0; __card_op_fail__: sunxi_mmc_exit(card_no, BT0_head.prvt_head.storage_gpio, 16 ); } return -1; }