int load_ptbl(int mmc_cont) { static unsigned char data[512]; static struct efi_entry entry[4]; int n,m,r; fastboot_flash_reset_ptn(); r = mmc_read(mmc_cont, 1, data, 512); if (r != 1) { printf("error reading partition table\n"); return -1; } if (memcmp(data, "EFI PART", 8)) { //printf("efi partition table not found\n"); return -1; } for (n = 0; n < (128/4); n++) { r = mmc_read(mmc_cont, 2 + n, (void*) entry, 512); if (r != 1) { printf("partition read failed\n"); return 1; } for (m = 0; m < 4; m ++) import_efi_partition(entry + m); } return 0; }
//$230c (VDPL), $230d (VDPH) use this bus to read variable-length data. //this is used both to keep VBR-reads from accessing MMIO registers, and //to avoid syncing the S-CPU and SA-1*; as both chips are able to access //these ports. uint8 SA1::vbr_read(unsigned addr) { if((addr & 0x408000) == 0x008000) { //$00-3f|80-bf:8000-ffff return mmc_read(addr); } if((addr & 0xc00000) == 0xc00000) { //$c0-ff:0000-ffff return mmc_read(addr); } if((addr & 0x40e000) == 0x006000) { //$00-3f|80-bf:6000-7fff return bwram.read(addr & (bwram.size() - 1)); } if((addr & 0xf00000) == 0x400000) { //$40-4f:0000-ffff return bwram.read(addr & (bwram.size() - 1)); } if((addr & 0x40f800) == 0x000000) { //$00-3f|80-bf:0000-07ff return iram.read(addr & 2047); } if((addr & 0x40f800) == 0x003000) { //$00-3f|80-bf:3000-37ff return iram.read(addr & 0x2047); } }
int load_ptbl(void) { static unsigned char data[512]; static struct efi_entry entry[4]; int n,m,r; r = mmc_read(1, 1, data, 512); if (r != 1) { printf("error reading partition table\n"); return -1; } if (memcmp(data, "EFI PART", 8)) { printf("efi partition table not found\n"); printf("===============================\n"); printf(" format \n"); printf("===============================\n"); do_format(); return -1; } for (n = 0; n < (128/4); n++) { r = mmc_read(1, 1 + n, (void*) entry, 512); if (r != 1) { printf("partition read failed\n"); return 1; } for (m = 0; m < 4; m ++) import_efi_partition(entry + m); } return 0; }
static int load_ptbl(void) { static unsigned char data[512]; static struct efi_entry entry[4]; int n,m,r; printf("ptbl slot: %s:(%d).\n", mmc_slot?"EMMC":"SD", mmc_slot); r = mmc_read(mmc_slot, 1, data, 512); if (r != 1) { printf("error reading partition table\n"); return -1; } if (memcmp(data, "EFI PART", 8)) { printf("efi partition table not found\n"); return -1; } for (n = 0; n < (128/4); n++) { r = mmc_read(mmc_slot, 1 + n, (void*) entry, 512); if (r != 1) { printf("partition read failed\n"); return 1; } for (m = 0; m < 4; m ++) import_efi_partition(entry + m); } return 0; }
static void ssd_load_keystore_from_emmc() { uint64_t ptn = 0; int index = -1; uint32_t size = SSD_PARTITION_SIZE; int ret = -1; uint32_t *buffer = (uint32_t *)memalign(CACHE_LINE, ROUNDUP(SSD_PARTITION_SIZE, CACHE_LINE)); if (!buffer) { dprintf(CRITICAL, "Error Allocating memory for SSD buffer\n"); ASSERT(0); } index = partition_get_index("ssd"); ptn = partition_get_offset(index); if(ptn == 0) { dprintf(CRITICAL,"ERROR: ssd parition not found"); return; } if(mmc_read(ptn, buffer, size)) { dprintf(CRITICAL,"ERROR:Cannot read data\n"); return; } ret = scm_protect_keystore((uint32_t *)&buffer[0],size); if(ret != 0) dprintf(CRITICAL,"ERROR: scm_protect_keystore Failed"); free(buffer); }
/** * Load images from EMMC */ static struct mdtp_fbimage* mdtp_read_mmc_image(uint32_t offset, uint32_t width, uint32_t height) { int index = INVALID_PTN; unsigned long long ptn = 0; struct mdtp_fbimage *logo = &g_mdtp_header; uint32_t block_size = mmc_get_device_blocksize(); index = partition_get_index("mdtp"); if (index == 0) { dprintf(CRITICAL, "ERROR: mdtp Partition table not found\n"); return NULL; } ptn = partition_get_offset(index); if (ptn == 0) { dprintf(CRITICAL, "ERROR: mdtp Partition invalid\n"); return NULL; } if (fb_config) { uint8_t *base = logo->image; unsigned bytes_per_bpp = ((fb_config->bpp) / BITS_PER_BYTE); if (mmc_read(ptn+offset, (void*)base, ROUNDUP(width*height*bytes_per_bpp, block_size))) { fbcon_clear(); dprintf(CRITICAL, "ERROR: mdtp image read failed\n"); return NULL; } logo->width = width; logo->height = height; } return logo; }
int lge_static_nvdata_emmc_read(enum lge_dynamic_nvdata_offset offset,char* buf,int size) { int pos = (int)offset; int start_sector_no; int pos_in_sector; char sector_buf[LGE_NVDATA_SECTOR_SIZE]; if(size <= 0) return LGE_NVDATA_EMMC_ERR_SIZE_TOO_SMALL; if(size > LGE_NVDATA_SECTOR_SIZE) return LGE_NVDATA_EMMC_ERR_SIZE_TOO_LARGE; start_sector_no = LGE_STATIC_NVDATA_PARTITION_START_SECTOR + (int)(pos/LGE_NVDATA_SECTOR_SIZE); pos_in_sector = pos % LGE_NVDATA_SECTOR_SIZE; if(start_sector_no > LGE_STATIC_NVDATA_PARTITION_LAST_SECTOR) return LGE_NVDATA_EMMC_ERR_SECTOR_MISMATCH; if(size+pos_in_sector > LGE_NVDATA_SECTOR_SIZE) return LGE_NVDATA_EMMC_ERR_ALIGN_MISMATCH; //mmc_init(1); // read nvdata partition mmc_read(1,start_sector_no,sector_buf,LGE_NVDATA_SECTOR_SIZE); memcpy(buf,&(sector_buf[pos_in_sector]),size); return size; }
static int emmc_get_recovery_msg(struct recovery_message *in) { char *ptn_name = "misc"; unsigned long long ptn = 0; unsigned int size; int index = INVALID_PTN; size = mmc_get_device_blocksize(); index = partition_get_index((const char *) ptn_name); if (index < 0) { dprintf(CRITICAL, "%s: Partition not found\n", ptn_name); return -1; } ptn = partition_get_offset(index); mmc_set_lun(partition_get_lun(index)); if(ptn == 0) { dprintf(CRITICAL,"partition %s doesn't exist\n",ptn_name); return -1; } if (mmc_read(ptn , (unsigned int*)in, size)) { dprintf(CRITICAL,"mmc read failure %s %d\n",ptn_name, size); return -1; } return 0; }
int mmc_read_bootloader(int dev, int part) { long size; unsigned long offset = CFG_LOADADDR; block_dev_desc_t *dev_desc = NULL; unsigned char ret = 0; ret = mmc_init(dev); if (ret != 0){ printf("\n MMC init failed \n"); return -1; } if (part) { /* FAT Read for extenal SD card */ dev_desc = mmc_get_dev(dev); size = file_fat_read("u-boot.bin", (unsigned char *)offset, 0); if (size == -1) return -1; } else { /* RAW read for EMMC */ ret = mmc_read(dev, 0x400, (unsigned char *)offset, 0x60000); if (ret != 1) return -1; } return 0; }
int mmc_read_bootloader(int dev) { unsigned char ret = 0; unsigned long offset = ( CFG_LOADADDR - 0x120 ); ret = mmc_init(dev); if (ret != 0){ printf("\n MMC init failed \n"); return -1; } #ifdef CFG_CMD_FAT long size; block_dev_desc_t *dev_desc = NULL; if (fat_boot()) { dev_desc = mmc_get_dev(dev); fat_register_device(dev_desc, 1); size = file_fat_read("u-boot.bin", (unsigned char *)offset, 0); if (size == -1) return -1; } else { /* FIXME: OMAP4 specific */ mmc_read(dev, 0x200, (unsigned char *)( CFG_LOADADDR - 0x120 ), 0x00060000); } #endif return 0; }
int32 readfat(int32 fatoffset){ int16 temp; int32 tempb; char los; temp=0; fatoffset=fatoffset*2; los = *(((char*)&fatoffset)+0); //the bottom byte of the address goes directly to a word in the FAT fatoffset=fatoffset / 256; fatoffset+=fatstart; if(mmc_open_block(fatoffset)==1){ //putc('^'); // printf("fat retry..."); if(mmc_open_block(fatoffset)==1){ //putc('&'); mmc_init(0); // printf("fat RETRY..."); if(mmc_open_block(fatoffset)==1){ //putc('*'); mmc_init(0); // printf("fat LOOKS BAD..."); if(mmc_open_block(fatoffset)==1){ //printf("problem reading fat table, quitting chain. Sorry!"); error=7; return 0xffffffff; } } } } mmc_skip(los); mmc_read(); temp = ((int16) data_hi * 256)+ (int16) data_lo; mmc_read();//for fat32, four bytes per entry tempb=0; tempb = ((int16) data_hi * 256)+ (int16) data_lo; tempb=tempb<<16; tempb=tempb+(int32) temp; mmc_skip(255-(los));//trouble??? mmc_read(); mmc_read(); mmc_close_block(); return tempb; }
ulong /****************************************************/ mmc_bread(int dev_num, ulong blknr, ulong blkcnt, ulong *dst) /****************************************************/ { int mmc_block_size = MMC_BLOCK_SIZE; ulong src = blknr * mmc_block_size + CFG_MMC_BASE; mmc_read(src, (uchar *)dst, blkcnt*mmc_block_size); return blkcnt; }
/** * get_partition_sz: Returns size of requested paritition in eMMC * @buf: Caller buffer pointer the size will be returned in * @partname: partittion name being requested */ char * get_partition_sz(char *buf, const char *partname) { struct ptable *ptbl = &the_ptable; struct efi_header *hdr = &ptbl->header; struct efi_entry *entry = ptbl->entry; unsigned n, i; char curr_partname[EFI_NAMELEN]; u64 fist_lba, last_lba, sz; u32 crc_orig; u32 crc; u32 *szptr = (u32 *) &sz; if (mmc_read(mmc_slot, 0, (void *)ptbl, sizeof(struct ptable)) != 1){ printf("\n ERROR Reading Partition Table \n"); return buf; } /*Make sure there is a legit partition table*/ if (load_ptbl()){ printf("\n INVALID PARTITION TABLE \n"); return buf; } /*crc needs to be computed with crc zeroed out.*/ crc_orig = hdr->crc32; hdr->crc32 = 0; crc = crc32(0,0,0); crc = crc32(0, (void *) &ptbl->header, sizeof(ptbl->header)); if (crc != crc_orig){ printf("\n INVALID HEADER CRC!!\n"); return buf; } for (n=0; n < EFI_ENTRIES; n++, entry++) { for (i = 0; i < EFI_NAMELEN; i++) curr_partname[i] = (char) entry->name[i]; if (!strcmp(curr_partname, partname)){ if (entry->last_lba < entry->first_lba){ printf("\n REDICULOUS LENGTH!! \n"); break; } sz = (entry->last_lba - entry->first_lba)/2; if (sz >= 0xFFFFFFFF) sprintf(buf, "0x%08x , %08x KB", szptr[1], szptr[0]); else sprintf(buf, "%d KB", szptr[0]); break; } } return buf; }
unsigned long grub_tar_read(struct tar_io *tio, ulong start, ulong blkcnt, void *buffer) { struct tar_io_priv *priv = (struct tar_io_priv*) tio->priv; unsigned long long ptn = ((unsigned long long) start)*BLOCK_SIZE; if(priv->is_ramdisk) { memcpy(buffer, (void*)(unsigned long)(priv->ptn+ptn), blkcnt*BLOCK_SIZE); } else { if(mmc_read(priv->ptn + ptn, buffer, blkcnt*BLOCK_SIZE)) return 0; } return blkcnt*BLOCK_SIZE; }
static int read_misc(unsigned page_offset, void *buf, unsigned size) { const char *ptn_name = "misc"; uint32_t pagesize = get_page_size(); unsigned offset; if (size == 0 || buf == NULL) return -1; offset = page_offset * pagesize; if (target_is_emmc_boot()) { int index; unsigned long long ptn; unsigned long long ptn_size; index = partition_get_index(ptn_name); if (index == INVALID_PTN) { dprintf(CRITICAL, "No '%s' partition found\n", ptn_name); return -1; } ptn = partition_get_offset(index); ptn_size = partition_get_size(index); mmc_set_lun(partition_get_lun(index)); if (ptn_size < offset + size) { dprintf(CRITICAL, "Read request out of '%s' boundaries\n", ptn_name); return -1; } if (mmc_read(ptn + offset, (unsigned int *)buf, size)) { dprintf(CRITICAL, "Reading MMC failed\n"); return -1; } } else { dprintf(CRITICAL, "Misc partition not supported for NAND targets.\n"); return -1; } return 0; }
DRESULT disk_read(BYTE drv, BYTE *buff, DWORD sector, BYTE count) { #if CFG_HAVE_SDCARD == 1 switch (drv) { case 0: #endif return dataflash_read(buff, sector, count); #if CFG_HAVE_SDCARD == 1 case 1: return mmc_read(buff, sector, count); default: return RES_PARERR; } #endif }
static int mmcdev_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id, uint32_t blk_cnt) { struct private_mmc_data* mmcdata = mmcdev_get_privatedata(bdev); uint64_t offset = blk_id * bdev->ph_bsize; if (mmc_read(mmcdata->ptn + offset, buf, bdev->ph_bsize * blk_cnt)) { dprintf(CRITICAL, "ERROR: mmc_read() fail.\n"); return EIO; } return EOK; }
uint8 SA1::bus_read(unsigned addr) { if((addr & 0x40fe00) == 0x002200) { //$00-3f|80-bf:2200-23ff return mmio_read(addr); } if((addr & 0x408000) == 0x008000) { //$00-3f|80-bf:8000-ffff return mmc_read(addr); } if((addr & 0xc00000) == 0xc00000) { //$c0-ff:0000-ffff return mmc_read(addr); } if((addr & 0x40e000) == 0x006000) { //$00-3f|80-bf:6000-7fff return mmc_sa1_read(addr); } if((addr & 0x40f800) == 0x000000) { //$00-3f|80-bf:0000-07ff synchronize_cpu(); return iram.read(addr & 2047); } if((addr & 0x40f800) == 0x003000) { //$00-3f|80-bf:3000-37ff synchronize_cpu(); return iram.read(addr & 2047); } if((addr & 0xf00000) == 0x400000) { //$40-4f:0000-ffff synchronize_cpu(); return bwram.read(addr & (bwram.size() - 1)); } if((addr & 0xf00000) == 0x600000) { //$60-6f:0000-ffff synchronize_cpu(); return bitmap_read(addr & 0x0fffff); } }
byte memory_readb(word address) { switch (address >> 13) { case 0: return cpu_ram_read(address & 0x07FF); case 1: return ppu_io_read(address); case 2: return psg_io_read(address); case 3: return cpu_ram_read(address & 0x1FFF); default: return mmc_read(address); } }
uint32_t fs_sd_read_sectors (uint32_t start_sector, uint32_t n_sectors, void *buffer) { int status; status = mmc_read (sd, start_sector, n_sectors, (uint32_t*)buffer); if (MMC_OK == status) { return 0; } dprintf (CRITICAL, "fs_sd_read_sectors failed: s 0x%08x, n 0x%08x, status = %d\n", start_sector, n_sectors, status); return 1; }
static int read_user_keystore_ptn() { int index = INVALID_PTN; unsigned long long ptn = 0; index = partition_get_index(KEYSTORE_PTN_NAME); ptn = partition_get_offset(index); if(ptn == 0) { dprintf(CRITICAL, "boot_verifier: No keystore partition found\n"); return -1; } if (mmc_read(ptn, (unsigned int *) keystore_buf, mmc_page_size())) { dprintf(CRITICAL, "boot_verifier: Cannot read user keystore\n"); return -1; } return 0; }
/* This function read the 1st bootmsg block and return the command which stores at * the begining of this block */ char* bootmsg_get_command() { unsigned int mmc_cont = 1; struct fastboot_ptentry *pte; pte = fastboot_flash_find_ptn(bootmsg_partition); if (!pte) { printf("bootmsg_get_command: cannot find '%s' partition\n", bootmsg_partition); return NULL; } mmc_read(mmc_cont, pte->start, bootmsg_1st_block, BOOTMSG_BLOCK_SIZE); /* Ensure that command is null terminated */ bootmsg_1st_block[COMMAND_SIZE-1] = '\0'; return bootmsg_1st_block; }
static int read_from_mmc(struct ptentry* ptn, int size, void *dest) { void *buffer = NULL; unsigned sector_mask = 511; int read_size = (size + sector_mask) & (~sector_mask); buffer = malloc(read_size); if(!buffer){ dprintf(CRITICAL, "ERROR : Malloc failed for read_from_flash \n"); return -1; } if(mmc_read(ptn, buffer, read_size)) { dprintf(CRITICAL, "ERROR : Flash read failed \n"); return -1; } memcpy(dest, buffer, size); free(buffer); return 0; }
void target_load_ssd_keystore(void) { uint64_t ptn; int index; uint64_t size; uint32_t *buffer; if (!target_is_ssd_enabled()) return; index = partition_get_index("ssd"); ptn = partition_get_offset(index); if (ptn == 0){ dprintf(CRITICAL, "Error: ssd partition not found\n"); return; } size = partition_get_size(index); if (size == 0) { dprintf(CRITICAL, "Error: invalid ssd partition size\n"); return; } buffer = memalign(CACHE_LINE, ROUNDUP(size, CACHE_LINE)); if (!buffer) { dprintf(CRITICAL, "Error: allocating memory for ssd buffer\n"); return; } if (mmc_read(ptn, buffer, size)) { dprintf(CRITICAL, "Error: cannot read data\n"); free(buffer); return; } clock_ce_enable(SSD_CE_INSTANCE); scm_protect_keystore(buffer, size); clock_ce_disable(SSD_CE_INSTANCE); free(buffer); }
static int emmc_get_recovery_msg(struct recovery_message *in) { char *ptn_name = "misc"; unsigned long long ptn = 0; unsigned int size = ROUND_TO_PAGE(sizeof(*in),511); unsigned char data[size]; int index = INVALID_PTN; index = partition_get_index((unsigned char *) ptn_name); ptn = partition_get_offset(index); if(ptn == 0) { dprintf(CRITICAL,"partition %s doesn't exist\n",ptn_name); return -1; } if (mmc_read(ptn , (unsigned int*)data, size)) { dprintf(CRITICAL,"mmc read failure %s %d\n",ptn_name, size); return -1; } memcpy(in, data, sizeof(*in)); return 0; }
/* This function read the 1st bootmsg block and return the command which stores at * the begining of this block */ void bootmsg_write_command(const char* command) { unsigned int mmc_cont = 1; struct fastboot_ptentry *pte; pte = fastboot_flash_find_ptn(bootmsg_partition); if (!pte) { printf("bootmsg_get_command: cannot find '%s' partition\n", bootmsg_partition); } /* read the 1st bootmsg block */ mmc_read(mmc_cont, pte->start, bootmsg_1st_block, BOOTMSG_BLOCK_SIZE); /* Copy the new string */ strncpy(bootmsg_1st_block, command, COMMAND_SIZE); /* Write it back */ mmc_write(mmc_cont, bootmsg_1st_block, pte->start, BOOTMSG_BLOCK_SIZE); /* Ensure that command is null terminated */ bootmsg_1st_block[COMMAND_SIZE-1] = '\0'; }
static int mdss_dsi_dfps_get_stored_pll_codes(struct msm_panel_info *pinfo) { int ret = NO_ERROR; int index; unsigned long long ptn; uint32_t blocksize; struct dfps_info *dfps; index = partition_get_index("splash"); if (index == INVALID_PTN) { dprintf(INFO, "%s: splash partition table not found\n", __func__); ret = NO_ERROR; goto splash_err; } ptn = partition_get_offset(index); if (ptn == 0) { dprintf(CRITICAL, "ERROR: splash Partition invalid offset\n"); ret = ERROR; goto splash_err; } mmc_set_lun(partition_get_lun(index)); blocksize = mmc_get_device_blocksize(); if (blocksize == 0) { dprintf(CRITICAL, "ERROR:splash Partition invalid blocksize\n"); ret = ERROR; goto splash_err; } dfps = (struct dfps_info *)memalign(CACHE_LINE, ROUNDUP(PAGE_SIZE, CACHE_LINE)); if (!dfps) { dprintf(CRITICAL, "ERROR:splash Partition invalid memory\n"); ret = ERROR; goto splash_err; } if (mmc_read(ptn, (uint32_t *) dfps, blocksize)) { dprintf(CRITICAL, "mmc read splash failure%d\n", PAGE_SIZE); ret = ERROR; free(dfps); goto splash_err; } dprintf(SPEW, "enable=%d cnt=%d\n", dfps->panel_dfps.enabled, dfps->panel_dfps.frame_rate_cnt); if (!dfps->panel_dfps.enabled || dfps->panel_dfps.frame_rate_cnt > DFPS_MAX_FRAME_RATE) { ret = ERROR; free(dfps); goto splash_err; } pinfo->dfps = *dfps; free(dfps); splash_err: return ret; }
int next_dir_buffer() { unsigned char data[32]; int32 ccltemp, eocmark;; ++curr_window; if(curr_window==1) { fp_dir_nentries=0; reset_title(&fp_dir_entries[0]); } else { fp_dir_entries[0] = fp_dir_entries[MAX_DIR_ENTRY]; fp_dir_nentries=1; reset_title(&fp_dir_entries[1]); } do { if (fp_cur_sector==BPB_SecPerClus) { // Going to next cluster fp_cur_cluster=readfat(fp_cur_cluster); fp_cur_sector=0; } eocmark=fp_cur_cluster & 0x0FFFFFFF; if( eocmark<0x0ffffff0 ) { ccltemp=fp_cur_cluster-2; ccltemp=ccltemp * (int32)BPB_SecPerClus; ccltemp=ccltemp + (int32)datsec; ccltemp=ccltemp + (int32)fp_cur_sector; if (mmc_open_block(ccltemp) != 0) { //LED=0; error=8; } mmc_skip(fp_sec_offset); do { int32 ccl; mmc_read(); if((data_lo==0x00)||(data_lo == 0xe5)){//these are either blank entries or deleted ones. probably should escape from the loop if they are blank, but just to be sure we'll look to the end. mmc_skip(15); } else { signed int i; char Emm,Pee,Three; int32 Largeccl /*, ccltemp */; struct t_dir_entry* entry = &fp_dir_entries[fp_dir_nentries]; for(i=0;i<30;) { data[i]=data_lo; i++; data[i]=data_hi; i++; mmc_read(); } data[i]=data_lo; data[i+1]=data_hi; if ( (data[11] & 0xFCU) == 0x20 && data[0] >= '0' && data[0] <= '9' && data[1] >= '0' && data[1] <= '9' && data[2] >= '0' && data[2] <= '9' && data[3] >= '0' && data[3] <= '9' ) { int indexs[4]; int16 track; for(i=0;i<4;i++) { indexs[i] = data[i] - 48; } track = indexs[0]*1000 + indexs[1]*100 + indexs[2]*10 + indexs[3]; Emm= data[8]; //Emm=data_lo; Pee= data[9]; //Pee=data_hi; Three= data[10]; //Three=data_lo; if ( ((Emm=='m') || (Emm=='M')|| (Emm=='W')|| (Emm=='w')) && ((Pee=='P') || (Pee=='p')|| (Pee=='A')|| (Pee=='a')) && ((Three=='3')||(Three=='V')||(Three=='v')) ) { int32 songlength; Largeccl= ((int16)data[21]<<8)+data[20]; Largeccl=Largeccl<<16; ccl= ((int32)data[27]<<8)+data[26]; *(((char*)&songlength)+0)=data[28]; *(((char*)&songlength)+1)=data[29]; *(((char*)&songlength)+2)=data[30]; *(((char*)&songlength)+3)=data[31]; if( track > 0) { fp_dir_entries[fp_dir_nentries].ccl = ccl+ Largeccl; //add on the high bytes of the cluster address fp_dir_entries[fp_dir_nentries].songlength = songlength; fp_dir_entries[fp_dir_nentries].track = track; entry->tit_offset = 0; entry->title[entry->tit_p]=' '; // Entry in 8.3 format if( entry->tit_p==31 && !entry->tit_full) { get_short_name_entry(entry,data); } ++fp_dir_nentries; ++fp_dir_global_entries; if( fp_dir_nentries < (MAX_DIR_ENTRY+1)) reset_title(&fp_dir_entries[fp_dir_nentries]); } else { cclzero = ccl+ Largeccl; //add on the high bytes of the cluster address songlengthzero = songlength; } } } else if ( data[11] == 0x0F ) { get_long_name_entry(entry,data); } } fp_sec_offset += 16; } while ( fp_sec_offset!=0 && fp_dir_nentries<(MAX_DIR_ENTRY+1) ); if( fp_sec_offset == 0 ) { ++fp_cur_sector; } mmc_skip(256-fp_sec_offset); mmc_close_block(); } }while(eocmark<0x0ffffff0 && fp_dir_nentries<(MAX_DIR_ENTRY+1)); // printf("file does not exist!");putc(13);putc(10); delay_cycles(1); return (eocmark<0x0ffffff0); }
///////////// ///////////// ////////////////// ///////////????????????////////////// void find_bpb(){ int32 bigtemp; bpbstart=0; mmc_open_block(0); mmc_skip(0xE3); mmc_read(); bpbstart=((int16) data_hi<<8); bpbstart+=data_lo; // mmc_cancel_block(); mmc_skip(27); // mmc_skip(35); mmc_close_block(); mmc_open_block((int32) bpbstart); mmc_skip(5); mmc_read(); BPB_bytspersec=data_hi; //11 mmc_read(); BPB_bytspersec=BPB_bytspersec+((int16) data_lo<<8); //11.12 BPB_SecPerClus=data_hi; //13 mmc_read(); BPB_ResvdSecCnt=((int16) data_hi<<8)+data_lo; //14.15 mmc_read(); BPB_NumFATs=data_lo; //16 //BPB_RootEntCnt=data_hi; //17 mmc_read();// BPB_RootEntCnt=BPB_RootEntCnt+((int16) data_lo<<8); //17.18 mmc_read(); mmc_read();// BPB_FATSz16=data_lo+((int16) data_hi<<8); //22.23 mmc_skip(6); mmc_read(); BPB_FATSz32=0; BPB_FATSz32=data_lo+((int32) data_hi<<8); //36.37 bigtemp=BPB_FATSz32; mmc_read(); BPB_FATSz32=data_lo+((int32) data_hi<<8); //36.37.38.39 BPB_FATSz32=BPB_FATSz32 <<16; BPB_FATSz32=bigtemp+BPB_FATSz32; mmc_read(); mmc_read(); mmc_read(); BPB_RootClus=data_lo+((int32) data_hi<<8); //44.45 bigtemp=BPB_RootClus; mmc_read(); mmc_skip(231); // mmc_cancel_block(); mmc_close_block(); BPB_RootClus=data_lo+((int32) data_hi<<8); //44.45.46.47 BPB_RootClus=BPB_RootClus<<16; BPB_RootClus=BPB_RootClus+bigtemp; root_ccl=BPB_RootClus; fatstart=bpbstart+BPB_ResvdSecCnt; FirstDataSector = BPB_ResvdSecCnt + (BPB_NumFATs * BPB_FATSz32);// + RootDirSectors; datsec = (int32)bpbstart + (int32)firstdatasector; /* putc(13);putc(10); printf("some info about card:"); putc(13);putc(10); printf(" bpbst:%4LX ",bpbstart); putc(13);putc(10); printf(" BPB_bpsec:%4LX ",BPB_bytspersec); putc(13);putc(10); printf(" BPB_ScPeC:%4LX ",BPB_SecPerClus); putc(13);putc(10); printf(" BPB_RsvdScCt:%4LX ",BPB_ResvdSecCnt); putc(13);putc(10); printf(" BPB_NmFAT:%4LX ",BPB_NumFATs); putc(13);putc(10); printf(" fatstart: %4LX ",fatstart); putc(13);putc(10); printf(" FirstDataSector:%4LX ",FirstDataSector); putc(13);putc(10); */ }
int do_mem_cp ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { ulong addr, dest, count; int size; if (argc != 4) { printf ("Usage:\n%s\n", cmdtp->usage); return 1; } /* Check for size specification. */ if ((size = cmd_get_data_size(argv[0], 4)) < 0) return 1; addr = simple_strtoul(argv[1], NULL, 16); addr += base_address; dest = simple_strtoul(argv[2], NULL, 16); dest += base_address; count = simple_strtoul(argv[3], NULL, 16); if (count == 0) { puts ("Zero length ???\n"); return 1; } #ifndef CFG_NO_FLASH /* check if we are copying to Flash */ if ( (addr2info(dest) != NULL) #ifdef CONFIG_HAS_DATAFLASH && (!addr_dataflash(dest)) #endif ) { int rc; puts ("Copy to Flash... "); rc = flash_write ((char *)addr, dest, count*size); if (rc != 0) { flash_perror (rc); return (1); } puts ("done\n"); return 0; } #endif #if defined(CONFIG_CMD_MMC) if (mmc2info(dest)) { int rc; puts ("Copy to MMC... "); switch (rc = mmc_write ((uchar *)addr, dest, count*size)) { case 0: putc ('\n'); return 1; case -1: puts ("failed\n"); return 1; default: printf ("%s[%d] FIXME: rc=%d\n",__FILE__,__LINE__,rc); return 1; } puts ("done\n"); return 0; } if (mmc2info(addr)) { int rc; puts ("Copy from MMC... "); switch (rc = mmc_read (addr, (uchar *)dest, count*size)) { case 0: putc ('\n'); return 1; case -1: puts ("failed\n"); return 1; default: printf ("%s[%d] FIXME: rc=%d\n",__FILE__,__LINE__,rc); return 1; } puts ("done\n"); return 0; } #endif #ifdef CONFIG_HAS_DATAFLASH /* Check if we are copying from RAM or Flash to DataFlash */ if (addr_dataflash(dest) && !addr_dataflash(addr)){ int rc; puts ("Copy to DataFlash... "); rc = write_dataflash (dest, addr, count*size); if (rc != 1) { dataflash_perror (rc); return (1); } puts ("done\n"); return 0; } /* Check if we are copying from DataFlash to RAM */ if (addr_dataflash(addr) && !addr_dataflash(dest) && (addr2info(dest)==NULL) ){ int rc; rc = read_dataflash(addr, count * size, (char *) dest); if (rc != 1) { dataflash_perror (rc); return (1); } return 0; } if (addr_dataflash(addr) && addr_dataflash(dest)){ puts ("Unsupported combination of source/destination.\n\r"); return 1; } #endif #ifdef CONFIG_BLACKFIN /* See if we're copying to/from L1 inst */ if (addr_bfin_on_chip_mem(dest) || addr_bfin_on_chip_mem(addr)) { memcpy((void *)dest, (void *)addr, count * size); return 0; } #endif while (count-- > 0) { if (size == 4) *((ulong *)dest) = *((ulong *)addr); else if (size == 2) *((ushort *)dest) = *((ushort *)addr); else *((u_char *)dest) = *((u_char *)addr); addr += size; dest += size; } return 0; }