static int write_env_area(char *env_buf) { part_t *part; part_dev_t *dev; long len; int i,checksum = 0; #ifdef MTK_EMMC_SUPPORT unsigned long long start_addr; #elif defined(MTK_NAND_SUPPORT) unsigned long start_addr; #endif dev = mt_part_get_device(); if (!dev) { return -ENODEV; } part = mt_part_get_partition(ENV_PART); if (!part) { return -ENOENT; } #ifdef MTK_EMMC_SUPPORT start_addr = (u64)part->startblk * BLK_SIZE; #elif defined(MTK_NAND_SUPPORT) start_addr = part->startblk * BLK_SIZE; #endif memcpy(env_buf,ENV_SIG,sizeof(g_env.sig)); memcpy(env_buf+CFG_ENV_SIG_1_OFFSET,ENV_SIG,sizeof(g_env.sig)); for(i=0;i<(int)CFG_ENV_DATA_SIZE;i++){ checksum += *(env_buf+CFG_ENV_DATA_OFFSET+i); } printf("checksum %d\n",checksum); *((int *)env_buf+CFG_ENV_CHECKSUM_OFFSET/4) = checksum; #if defined(MTK_EMMC_SUPPORT) && defined(MTK_NEW_COMBO_EMMC_SUPPORT) len = dev->write(dev, (uchar*)env_buf, start_addr + CFG_ENV_OFFSET, CFG_ENV_SIZE, part->part_id); #else len = -1; #endif if (len < 0) { return -EIO; } return 0; }
int mmc_get_dl_info(void) { DL_STATUS_EMMC download_info; #if defined(MTK_EMMC_SUPPORT) && defined(MTK_NEW_COMBO_EMMC_SUPPORT) u64 dl_addr = g_emmc_user_size - DL_INFO_SIZE; #else u64 dl_addr = g_emmc_size - DL_INFO_SIZE; #endif part_dev_t *dev = mt_part_get_device(); int i,ret; u8 *dl_buf = malloc(DL_INFO_SIZE); printf("get dl info from 0x%llx\n",dl_addr); #if defined(MTK_EMMC_SUPPORT) && defined(MTK_NEW_COMBO_EMMC_SUPPORT) dev->read(dev,dl_addr,(u8 *)dl_buf,DL_INFO_SIZE,EMMC_PART_USER); #else dev->read(dev,dl_addr,(u8 *)dl_buf,DL_INFO_SIZE); #endif memcpy(&download_info,dl_buf,sizeof(download_info)); if(memcmp(download_info.magic_num,"DOWNLOAD INFORMATION!!",22)){ printf("DL INFO NOT FOUND\n"); ret = DL_NOT_FOUND; } if(!memcmp(download_info.download_status,"DL_DONE",7)||!memcmp(download_info.download_status,"DL_CK_DONE",10)) { printf("dl done. status = %s\n",download_info.download_status); printf("dram checksum : %s\n",download_info.ram_checksum); for(i=0;i<PART_MAX_COUNT;i++) { if(download_info.part_info[i].image_index!=0){ printf("image_index:%d, checksum: %s\n",download_info.part_info[i].image_index,download_info.part_info[i].checksum_status); } } ret = DL_PASS; }else { printf("dl error. status = %s\n",download_info.download_status); printf("dram checksum : %s\n",download_info.ram_checksum); for(i=0;i<PART_MAX_COUNT;i++) { if(download_info.part_info[i].image_index!=0){ printf("image_index:%d, checksum: %s\n",download_info.part_info[i].image_index,download_info.part_info[i].checksum_status); } } ret = DL_FAIL; } free(dl_buf); return ret; }
int sec_dev_write_wrapper(char *part_name, u64 offset, u8* data, u32 size) { part_dev_t *dev; long len; #ifdef MTK_EMMC_SUPPORT #ifdef MTK_NEW_COMBO_EMMC_SUPPORT part_t *part; #endif #endif dev = mt_part_get_device(); if (!dev) return PART_GET_DEV_FAIL; #ifndef MTK_EMMC_SUPPORT if(nand_erase(offset,(u64)size)!=0){ return PART_ERASE_FAIL; } #endif #ifdef MTK_EMMC_SUPPORT #ifdef MTK_NEW_COMBO_EMMC_SUPPORT part = mt_part_get_partition(part_name); if (!part){ dprintf(CRITICAL,"[write_wrapper] mt_part_get_partition error, name: %s\n", part_name); ASSERT(0); } len = dev->write(dev, (uchar *) data, offset, size, part->part_id); #else len = dev->write(dev, (uchar *) data, offset, size); #endif #else #ifdef MTK_NEW_COMBO_EMMC_SUPPORT len = dev->write(dev, (uchar *) data, offset, size, NAND_PART_USER); #else len = dev->write(dev, (uchar *) data, offset, size); #endif #endif if (len != (int)size) { return PART_WRITE_FAIL; } return B_OK; }
int sec_dev_read_wrapper(char *part_name, u64 offset, u8* data, u32 size) { part_dev_t *dev; long len; #ifdef MTK_EMMC_SUPPORT #ifdef MTK_NEW_COMBO_EMMC_SUPPORT part_t *part; #endif #endif dev = mt_part_get_device(); if (!dev){ return PART_GET_DEV_FAIL; } #ifdef MTK_EMMC_SUPPORT #ifdef MTK_NEW_COMBO_EMMC_SUPPORT part = mt_part_get_partition(part_name); if (!part){ dprintf(CRITICAL,"[read_wrapper] mt_part_get_partition error, name: %s\n", part_name); ASSERT(0); } len = dev->read(dev, offset, (uchar *) data, size, part->part_id); #else len = dev->read(dev, offset, (uchar *) data, size); #endif #else #ifdef MTK_NEW_COMBO_EMMC_SUPPORT len = dev->read(dev, offset, (uchar *) data, size, NAND_PART_USER); #else len = dev->read(dev, offset, (uchar *) data, size); #endif #endif if (len != (int)size) { return PART_READ_FAIL; } return B_OK; }
static int read_env_area(char *env_buf) { part_t *part; part_dev_t *dev; long len; #ifdef MTK_EMMC_SUPPORT unsigned long long start_addr; #elif defined(MTK_NAND_SUPPORT) unsigned long start_addr; #endif dev = mt_part_get_device(); if (!dev) { return -ENODEV; } part = mt_part_get_partition(ENV_PART); if (!part) { return -ENOENT; } #ifdef MTK_EMMC_SUPPORT start_addr = (u64)part->startblk * BLK_SIZE; #elif defined(MTK_NAND_SUPPORT) start_addr = part->startblk * BLK_SIZE; #endif #if defined(MTK_EMMC_SUPPORT) && defined(MTK_NEW_COMBO_EMMC_SUPPORT) len = dev->read(dev, start_addr + CFG_ENV_OFFSET, (uchar*)env_buf, CFG_ENV_SIZE, part->part_id); #else len = -1; #endif if (len < 0) { return -EIO; } return 0; }
int __check_mountpoint(void *data, int count, char *mountpoint,char *i_type) { struct ext4_super_block *sb; char buf[64] = {0}; #ifndef MTK_EMMC_SUPPORT part_dev_t *dev = mt_part_get_device(); struct nand_chip *nand = (struct nand_chip *)dev->blkdev; int page_size,spare_size; #endif if (0 == memcmp((void *)data, BOOT_MAGIC, strlen(BOOT_MAGIC))){ if(mountpoint != NULL) strcpy(mountpoint,"boot"); if(i_type != NULL) strcpy(i_type,"raw data"); return 0; } #ifdef MTK_EMMC_SUPPORT if((unsigned int)count < sizeof(struct ext4_super_block)){ printf("[__check_mountpoint] %d littler than ext4 super block size\n",count); return -1; } data += 1024; sb = (struct ext4_super_block *)data; if(sb->s_magic != EXT4_SUPER_MAGIC){ printf("[__check_mountpoint]ext4 magic num error, %x data %p\n",sb->s_magic,data); return -1; } memcpy(buf,sb->s_last_mounted,sizeof(sb->s_last_mounted)); if(strncmp(buf,"/",1)){ printf("[__check_mountpoint]mountpoint %s is not support\n",buf); return -1; } printf("[__check_mountpoint]mountpoint is %s\n",buf); if(i_type != NULL) strcpy(i_type,"ext4"); if(mountpoint != NULL){ if(!strcmp(&buf[1],"data")){ strcpy(mountpoint,"userdata"); }else{ memcpy(mountpoint,&buf[1],strlen(buf)); } } #else page_size = nand->page_size; if(page_size == 2048){ spare_size = 64; }else if(page_size == 4096){ spare_size = 128; }else{ printf("[__check_mountpoint]page size %d is not support\n",page_size); return -1; } //check if ubi image first { char *tp = data; struct ubi_ec_hdr *ec_hdr = (struct ubi_ec_hdr *)tp; struct ubi_vid_hdr *vid_hdr = NULL; struct ubi_vtbl_record *vtbl = NULL; int name_len = 0; int leb_start = 0; /*1. check first page for ec hdr*/ if(be32_to_cpu(ec_hdr->magic) == UBI_EC_HDR_MAGIC){ printf("[__check_mountpoint]find UBI EC HDR\n"); /*2. check 2nd page for vid hdr*/ tp += be32_to_cpu(ec_hdr->vid_hdr_offset); leb_start = be32_to_cpu(ec_hdr->data_offset); vid_hdr = (struct ubi_vid_hdr *)tp; if(be32_to_cpu(vid_hdr->magic) == UBI_VID_HDR_MAGIC){ printf("[__check_mountpoint]find UBI VID HDR\n"); /*3. check 3rd page for layout volume*/ if(be32_to_cpu(vid_hdr->vol_id) == UBI_LAYOUT_VOLUME_ID){ printf("[__check_mountpoint]find UBI LAYOUT VOLUME\n"); tp = data + leb_start; vtbl = (struct ubi_vtbl_record *)tp; name_len = be16_to_cpu(vtbl->name_len); printf("[__check_mountpoint]volume name len %d\n",name_len); if(name_len <= UBI_VOL_NAME_MAX){ memcpy(buf,vtbl->name,name_len); if(i_type != NULL) strcpy(i_type,"ubifs"); goto find; }else{ printf("[__check_mountpoint]volume name len more than %d\n",UBI_VOL_NAME_MAX); } }else{ printf("[__check_mountpoint]can't find UBI LAYOUT VOLUME\n"); } }else{ printf("[__check_mountpoint]can't find UBI VID HDR, %x\n",ec_hdr->magic); } }else{ printf("[__check_mountpoint]can not find UBI EC HDR, check another fs image\n"); } } //check if ubi image data += (page_size+spare_size); if(strcmp((char *)(data-YAFFS_TAG_OFFSET),"yaffs2")){ printf("[__check_mountpoint]yaffs tag can not find in %d\n",page_size+spare_size-YAFFS_TAG_OFFSET); return -1; } if(i_type != NULL) strcpy(i_type,"yaffs2"); memcpy(buf,data-PARTITION_INFO_OFFSET,PARTITION_INFO_OFFSET-YAFFS_TAG_OFFSET); find: printf("[__check_mountpoint]mountpoint is %s\n",buf); if(mountpoint != NULL){ if(!strcmp(buf,"data")){ strcpy(mountpoint,"userdata"); }else{ memcpy(mountpoint,buf,strlen(buf)+1); } } #endif return 0; }
int mmc_get_dl_info(void) { struct dl_status download_info; u64 dl_addr; u8 *dl_buf; part_dev_t *dev; part_t *part; int i, err, loglevel; dev = mt_part_get_device(); if (!dev) { dprintf(CRITICAL, "[DL_INFO]fail to get device\n"); err = -ENODEV; goto out; } part = get_part("flashinfo"); if (!part) { dprintf(CRITICAL, "[DL_INFO]fail to find partition flashinfo\n"); err = -ENODEV; goto out; } dl_addr = (u64)(part->start_sect + part->nr_sects) * 512ULL - DL_INFO_SIZE; dprintf(ALWAYS, "[DL_INFO]get dl info from 0x%llx\n", dl_addr); dl_buf = (u8 *)calloc(1, DL_INFO_SIZE); if (!dl_buf) { dprintf(CRITICAL, "[DL_INFO]fail to calloc buffer(count=%d)\n", DL_INFO_SIZE); err = -ENOMEM; goto fail_malloc; } err = dev->read(dev, dl_addr, dl_buf, DL_INFO_SIZE, part->part_id); if (err != DL_INFO_SIZE) { dprintf(CRITICAL, "[DL_INFO]fail to read data(%d)\n", err); err = -EIO; goto fail_read; } memcpy(&download_info, dl_buf, sizeof(download_info)); if (memcmp(download_info.magic_num, "DOWNLOAD INFORMATION!!", 22)) { dprintf(CRITICAL, "[DL_INFO]fail to find DL INFO magic\n"); err = DL_NOT_FOUND; goto fail_read; } if (!memcmp(download_info.download_status, "DL_DONE", 7) || !memcmp(download_info.download_status, "DL_CK_DONE", 10)) { loglevel = INFO; loglevel = CRITICAL; err = DL_PASS; } else { loglevel = CRITICAL; err = DL_FAIL; } dprintf(loglevel, "[DL_INFO]version: %s\n", download_info.version); dprintf(loglevel, "[DL_INFO]dl_status: %s\n", download_info.download_status); dprintf(loglevel, "[DL_INFO]dram_checksum: %s\n", download_info.ram_checksum); for (i = 0; i < PART_MAX_COUNT; i++) { if (download_info.cs_info[i].image_index != 0) { dprintf(loglevel, "[DL_INFO]image:[%02d]%-12s, checksum: %s\n", download_info.cs_info[i].image_index, download_info.img_info[i].image_name, download_info.cs_info[i].checksum_status); } } fail_read: free(dl_buf); fail_malloc: //put_part(part); out: return err; }