/* ************************************************************************************************************ * * function * * name : * * parmeters : * * return : * * note : * * ************************************************************************************************************ */ int sunxi_sprite_download_boot0(void *buffer, int production_media) { boot0_file_head_t *boot0 = (boot0_file_head_t *)buffer; //校验特征字符是否正确 debug("%s\n", boot0->boot_head.magic); if(strncmp((const char *)boot0->boot_head.magic, BOOT0_MAGIC, MAGIC_SIZE)) { printf("sunxi sprite: boot0 magic is error\n"); return -1; } //校验数据是否正确 if(sunxi_sprite_verify_checksum(buffer, boot0->boot_head.length, boot0->boot_head.check_sum)) { printf("sunxi sprite: boot0 checksum is error\n"); return -1; } //读出dram参数 //填充FLASH信息 if(!production_media) { nand_uboot_get_flash_info((void *)boot0->prvt_head.storage_data, STORAGE_BUFFER_SIZE); } { int i; uint *addr = (uint *)DRAM_PARA_STORE_ADDR; for(i=0;i<32;i++) { printf("dram para[%d] = %x\n", i, addr[i]); } } memcpy((void *)&boot0->prvt_head.dram_para, (void *)DRAM_PARA_STORE_ADDR, 32 * 4); /* regenerate check sum */ boot0->boot_head.check_sum = sunxi_sprite_generate_checksum(buffer, boot0->boot_head.length, boot0->boot_head.check_sum); //校验数据是否正确 if(sunxi_sprite_verify_checksum(buffer, boot0->boot_head.length, boot0->boot_head.check_sum)) { printf("sunxi sprite: boot0 checksum is error\n"); return -1; } printf("storage type = %d\n", production_media); if(!production_media) { return nand_download_boot0(boot0->boot_head.length, buffer); } else { return card_download_boot0(boot0->boot_head.length, buffer); } }
/* ************************************************************************************************************ * * function * * name : * * parmeters : * * return : * * note : * * ************************************************************************************************************ */ int sunxi_sprite_download_uboot(void *buffer, int production_media, int mode) { struct spare_boot_head_t *uboot = (struct spare_boot_head_t *)buffer; //校验特征字符是否正确 debug("%s\n", uboot->boot_head.magic); if(strncmp((const char *)uboot->boot_head.magic, UBOOT_MAGIC, MAGIC_SIZE)) { printf("sunxi sprite: uboot magic is error\n"); return -1; } //校验数据是否正确 if(!mode) { if(sunxi_sprite_verify_checksum(buffer, uboot->boot_head.length, uboot->boot_head.check_sum)) { printf("sunxi sprite: uboot checksum is error\n"); return -1; } //读出dram参数 //填充FLASH信息 if(!production_media) { nand_uboot_get_flash_info((void *)uboot->boot_data.nand_spare_data, STORAGE_BUFFER_SIZE); } } /* regenerate check sum */ uboot->boot_head.check_sum = sunxi_sprite_generate_checksum(buffer, uboot->boot_head.length, uboot->boot_head.check_sum); //校验数据是否正确 if(sunxi_sprite_verify_checksum(buffer, uboot->boot_head.length, uboot->boot_head.check_sum)) { printf("sunxi sprite: uboot checksum is error\n"); return -1; } printf("uboot size = 0x%x\n", uboot->boot_head.length); printf("storage type = %d\n", production_media); if(!production_media) { debug("nand down uboot\n"); return nand_download_uboot(uboot->boot_head.length, buffer); } else { printf("mmc down uboot\n"); return card_download_uboot(uboot->boot_head.length, buffer); } }
/* ************************************************************************************************************ * * function * * name : * * parmeters : * * return : * * note : * * ************************************************************************************************************ */ int sunxi_sprite_download_uboot(void *buffer, int production_media, int mode) { if(!gd->securemode) { struct spare_boot_head_t *uboot = (struct spare_boot_head_t *)buffer; //校验特征字符是否正确 debug("%s\n", uboot->boot_head.magic); if(strncmp((const char *)uboot->boot_head.magic, UBOOT_MAGIC, MAGIC_SIZE)) { printf("sunxi sprite: uboot magic is error\n"); return -1; } //校验数据是否正确 if(!mode) { if(sunxi_sprite_verify_checksum(buffer, uboot->boot_head.length, uboot->boot_head.check_sum)) { printf("sunxi sprite: uboot checksum is error\n"); return -1; } } /* regenerate check sum */ uboot->boot_head.check_sum = sunxi_sprite_generate_checksum(buffer, uboot->boot_head.length, uboot->boot_head.check_sum); //校验数据是否正确 if(sunxi_sprite_verify_checksum(buffer, uboot->boot_head.length, uboot->boot_head.check_sum)) { printf("sunxi sprite: uboot checksum is error\n"); return -1; } printf("uboot size = 0x%x\n", uboot->boot_head.length); return card_download_uboot(uboot->boot_head.length, buffer); } else { sbrom_toc1_head_info_t *toc1 = (sbrom_toc1_head_info_t *)buffer; printf("mmc down uboot\n"); return card_download_uboot(toc1->valid_len, buffer); } }
int sunxi_sprite_download_boot0_simple(void) { u8 buffer[200 * 1024]; if(!(uboot_spare_head.boot_data.reserved[0] & 0xff)) //不需要保存boot0/toc0 return 0; card_upload_boot0(200 * 1024, buffer); if(!gd->securemode) { boot0_file_head_t *boot0 = (boot0_file_head_t *)buffer; //校验特征字符是否正确 debug("%s\n", boot0->boot_head.magic); if(strncmp((const char *)boot0->boot_head.magic, BOOT0_MAGIC, MAGIC_SIZE)) { printf("sunxi sprite: boot0 magic is error\n"); return -1; } //校验数据是否正确 if(sunxi_sprite_verify_checksum(buffer, boot0->boot_head.length, boot0->boot_head.check_sum)) { printf("sunxi sprite: boot0 checksum is error\n"); return -1; } boot0->boot_head.boot_cpu = uboot_spare_head.boot_data.reserved[0] & 0xff00; printf("next boot_cpu=0x%x\n", boot0->boot_head.boot_cpu); /* regenerate check sum */ boot0->boot_head.check_sum = sunxi_sprite_generate_checksum(buffer, boot0->boot_head.length, boot0->boot_head.check_sum); //校验数据是否正确 if(sunxi_sprite_verify_checksum(buffer, boot0->boot_head.length, boot0->boot_head.check_sum)) { printf("sunxi sprite: boot0 checksum is error\n"); return -1; } return card_download_boot0(boot0->boot_head.length, buffer); } else { toc0_private_head_t *toc0 = (toc0_private_head_t *)buffer; sbrom_toc0_config_t *toc0_config = (sbrom_toc0_config_t *)(buffer + 0x80); //校验特征字符是否正确 debug("%s\n", (char *)toc0->name); if(strncmp((const char *)toc0->name, TOC0_MAGIC, MAGIC_SIZE)) { printf("sunxi sprite: boot0 magic is error\n"); return -1; } //校验数据是否正确 if(sunxi_sprite_verify_checksum(buffer, toc0->length, toc0->check_sum)) { printf("sunxi sprite: toc0 verify error\n"); return -1; } toc0_config->boot_cpu = uboot_spare_head.boot_data.reserved[0] & 0xff00; printf("next boot_cpu=0x%x\n", toc0_config->boot_cpu); toc0->check_sum = sunxi_sprite_generate_checksum(buffer, toc0->length, toc0->check_sum); //校验数据是否正确 if(sunxi_sprite_verify_checksum(buffer, toc0->length, toc0->check_sum)) { printf("sunxi sprite: boot0 checksum is error\n"); return -1; } return card_download_boot0(toc0->length, buffer); } }
/* ************************************************************************************************************ * * function * * name : * * parmeters : * * return : * * note : * * ************************************************************************************************************ */ int sunxi_sprite_download_boot0(void *buffer, int production_media) { if(!gd->securemode) { boot0_file_head_t *boot0 = (boot0_file_head_t *)buffer; //校验特征字符是否正确 debug("%s\n", boot0->boot_head.magic); if(strncmp((const char *)boot0->boot_head.magic, BOOT0_MAGIC, MAGIC_SIZE)) { printf("sunxi sprite: boot0 magic is error\n"); return -1; } //校验数据是否正确 if(sunxi_sprite_verify_checksum(buffer, boot0->boot_head.length, boot0->boot_head.check_sum)) { printf("sunxi sprite: boot0 checksum is error\n"); return -1; } //读出dram参数 //填充FLASH信息 if(0){ }else{ extern int mmc_write_info(int dev_num,void *buffer,u32 buffer_size); mmc_write_info(2,(void *)boot0->prvt_head.storage_data,STORAGE_BUFFER_SIZE); } { int i; uint *addr = (uint *)DRAM_PARA_STORE_ADDR; for(i=0;i<32;i++) { printf("dram para[%d] = %x\n", i, addr[i]); } } memcpy((void *)&boot0->prvt_head.dram_para, (void *)DRAM_PARA_STORE_ADDR, 32 * 4); /* regenerate check sum */ boot0->boot_head.check_sum = sunxi_sprite_generate_checksum(buffer, boot0->boot_head.length, boot0->boot_head.check_sum); //校验数据是否正确 if(sunxi_sprite_verify_checksum(buffer, boot0->boot_head.length, boot0->boot_head.check_sum)) { printf("sunxi sprite: boot0 checksum is error\n"); return -1; } return card_download_boot0(boot0->boot_head.length, buffer); } else { toc0_private_head_t *toc0 = (toc0_private_head_t *)buffer; sbrom_toc0_config_t *toc0_config = (sbrom_toc0_config_t *)(buffer + 0x80); //校验特征字符是否正确 debug("%s\n", (char *)toc0->name); if(strncmp((const char *)toc0->name, TOC0_MAGIC, MAGIC_SIZE)) { printf("sunxi sprite: toc0 magic is error\n"); return -1; } //校验数据是否正确 if(sunxi_sprite_verify_checksum(buffer, toc0->length, toc0->check_sum)) { printf("sunxi sprite: toc0 checksum is error\n"); return -1; } //读出dram参数 //填充FLASH信息 if(0) { }else{ extern int mmc_write_info(int dev_num,void *buffer,u32 buffer_size); //storage_data[384]; // 0-159,存储nand信息;160-255,存放卡信息 mmc_write_info(2,(void *)(toc0_config->storage_data+160),384-160); } { int i; uint *addr = (uint *)DRAM_PARA_STORE_ADDR; for(i=0;i<32;i++) { printf("dram para[%d] = 0x%x\n", i, addr[i]); } } memcpy((void *)toc0_config->dram_para, (void *)DRAM_PARA_STORE_ADDR, 32 * 4); /* regenerate check sum */ toc0->check_sum = sunxi_sprite_generate_checksum(buffer, toc0->length, toc0->check_sum); //校验数据是否正确 if(sunxi_sprite_verify_checksum(buffer, toc0->length, toc0->check_sum)) { printf("sunxi sprite: boot0 checksum is error\n"); return -1; } return card_download_boot0(toc0->length, buffer); } }