status_t OggReader::Sniff(int32 *streamCount) { TRACE("OggReader::Sniff\n"); #ifdef STRICT_OGG bool first_page = true; #else bool first_page = false; #endif fSeekable = get_seekable(Source()); fFile = get_file(Source()); ssize_t bytes = ReadPage(first_page); if (bytes < 0) { return bytes; } uint count = 1; while (count++ == fCookies.size()) { ssize_t bytes = ReadPage(); if (bytes < 0) { return bytes; } } if (fSeekable) { status_t status = FindLastPages(); if (status != B_OK) { return status; } } *streamCount = fCookies.size(); return B_OK; }
bool MusBinInput::ImportFile( ) { int i; if ( !IsOk() ) { wxLogMessage(_("Cannot read file '%s'"), m_file->m_fname.c_str() ); return false; } ReadFileHeader( &m_file->m_fheader ); // fileheader m_file->m_pages.Clear(); for (i = 0; i < m_file->m_fheader.nbpage; i++ ) { MusPage *page = new MusPage(); ReadPage( page ); m_file->m_pages.Add( page ); } if ( !ReadSeparator() ) return false; if ( m_file->m_fheader.param.entetePied & PAGINATION ) ReadPagination( &m_file->m_pagination ); if ( m_file->m_fheader.param.entetePied & ENTETE ) ReadHeaderFooter( &m_file->m_header ); if ( m_file->m_fheader.param.entetePied & PIEDDEPAGE ) ReadHeaderFooter( &m_file->m_footer ); //wxLogMessage("OK %d", m_file->m_pages.GetCount() ); //m_file->CheckIntegrity(); return true; }
void BulkStorage_WriteClose(struct BulkStorage *b) { if ( b == NULL ) { return; } if ( b->dirty != 0 ) { WritePage(b); } if ( b->marked != 0 ) { uint32_t image_hash = 0; uint32_t page_hash ; for ( uint32_t i = 1; i < b->token->number_pages ; i ++ ) { ReadPage(b, i); page_hash = CalcCRC(b->data, DATAFLASH_PAGESIZE_NORMAL); image_hash ^= page_hash; } b->head.hash = image_hash; b->head.timestamp = 0; b->marked = 0; WriteHeader(b->token, &b->head); } b->token = NULL; b->loaded_page = 0xFFFF; b->dirty = 0; b->write = 0; }
uint16_t BulkStorage_WriteData(struct BulkStorage *b, uint32_t addr, const uint8_t *buffer, uint16_t size) { if (( b == NULL ) || ( buffer == NULL ) || ( b->write == 0 )) { return 0; } uint16_t page = CalcPage(addr); if ( page != b->loaded_page ) { if ( b->dirty != 0 ) { WritePage(b); b->dirty = 0; } ReadPage(b, page); } uint16_t offset = CalcPageAddr(addr); uint16_t length = size; if (( offset+size) > DATAFLASH_PAGESIZE_NORMAL ) { length = DATAFLASH_PAGESIZE_NORMAL - offset; } if ( memcmp(b->data+offset, buffer, length) != 0 ) { b->dirty = 1; /* only mark as dirty if we actually change data... */ b->marked = 1; memcpy(b->data+offset, buffer, length); } return length; }
/// <summary>Reads the entire language file</summary> /// <param name="path">Full path</param> /// <returns>New language file</returns> /// <exception cref="Logic::ComException">COM Error</exception> /// <exception cref="Logic::FileFormatException">Corrupt XML / Missing elements / missing attributes</exception> /// <exception cref="Logic::InvalidValueException">Invalid languageID or pageID</exception> /// <exception cref="Logic::IOException">An I/O error occurred</exception> LanguageFile LanguageFileReader::ReadFile(Path path) { try { LanguageFile file(path); // Parse document LoadDocument(); // Get root (as node) XmlNodePtr languageNode(Document->documentElement); // Read fileID + language tag file.ID = LanguageFilenameReader(path.FileName).FileID; file.Language = ReadLanguageTag(languageNode); // Read pages for (int i = 0; i < languageNode->childNodes->length; i++) { XmlNodePtr n = languageNode->childNodes->item[i]; if (n->nodeType == Xml::NODE_ELEMENT) file.Pages.Add( ReadPage(n) ); } return file; } catch (_com_error& ex) { throw ComException(HERE, ex); } }
DWORD aobscan(DWORD dwPid, char* Value) { if (dwPid == 0) return (DWORD) - 1; HANDLE hProcess = ::OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwPid); if (hProcess != NULL) { //获得内存大小 PROCESS_MEMORY_COUNTERS pmc; pmc.cb = sizeof(PROCESS_MEMORY_COUNTERS); ::GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc)); //遍历内存 for (int i = 0; i < pmc.WorkingSetSize; i += 4096) { DWORD dwValue = ReadPage(hProcess, i, Value); if (dwValue != -1) { printf("Found:0x%X\n", i + dwValue); return i + dwValue; } } ::CloseHandle(hProcess); } printf("Nothing Found!\n"); return (DWORD) - 1; }
char* PF_BufferPool::GetPage(int fd, PageNum pageNum) { int slot; auto res = indexMap.find(std::pair<int, PageNum>(fd, pageNum)); if (res == indexMap.end()) { // page fault std::cout << "page fault" << std::endl; slot = InternalAllocate(fd, pageNum); bufferPool[slot].fd = fd; bufferPool[slot].pageNum = pageNum; ReadPage(bufferPool[slot]); } else { // hit slot = res->second; } bufferPool[slot].pinCount++; bufferPool[slot].refBit = 1; return bufferPool[slot].pData; }
int EncodeHost( void *data ) { int bytes; char *Pchar; Pchar = (char *)data; Swapb( Pchar[0], Pchar[3] ); Swapb( Pchar[1], Pchar[2] ); dh = (TMessageHeader *)data; memcpy( &DHO, data, sizeof( DHO ) ); //bytes = DHO.Cmd.LCommand - cmdTlsCmd; switch( DHO.Cmd.LCommand ) { case cmdReadData: // LParam[0] - first sector number // WParam[0] - sector number // WParam[1] - offset // WParam[2] - bytes number // if bytes number != 0 read bytes number from offset in one sector // WParam[0] ignore // else read needed sectors (WParam[0]) ReadPage( dh->LParam[0], 512, NetInBuffer ); ReplyDataCom( NetInBuffer, 512 ); break; case cmdGetToolInfo: ReplyDataCom( &tp, sizeof( tp ) ); break; } return 0; }
char* Retriever::Read( const dir_info& di ) /*****************************************/ { // if length larger than one page, then do a direct read and read in // the subsequent page onto input buffer. if ( di.length > DEF_BUF_SIZE ) { if (_heapBuffer) { delete [] _heapBuffer; _heapBuffer=NULL; } _heapBuffer = new char [di.length]; if ( SeekRead(_heapBuffer, _lfaBase+di.offset, di.length) != di.length ) { delete [] _heapBuffer; _heapBuffer=NULL; return NULL; } ReadPage(di.offset+di.length); return _heapBuffer; } ReadPage(di.offset); return _inputBuffer; }
// // Retriever::Retriever(). // Constructs a Retriever object that is attached to inputStream. // Retriever::Retriever( ifstream& inputStream ) : _inputFile ( inputStream.fstreambase::fd() ), _lfaBase ( GetBasePos() ), _aDirectory(_inputFile, GetDirPos()), _pageStartOffset(0), _heapBuffer( NULL ), _missRate(0) /*************************************************************/ { _PEDirEntryBase=GetPEDebugDirCVEntryPos(); ReadPage(0); CheckSig(); }
Page *SQLiter::GetPage(DWORD page_num) { if (opened) { BYTE *buff = new BYTE[hdr.page_size]; if (ReadPage(page_num, buff)) { return new Page(buff, hdr.page_size, page_num); } else { delete[] buff; } } return NULL; }
void PID_NandInit() { int i; uint8 data[2048]; ReadPage(PID_NANDPAGE,data); PID_ListLength=*(uint8*)(data); for(i=0;i<PID_ListLength;i++) { Pid_List[i].PROP=*(fp64*)(data+24*i+8); Pid_List[i].Ti=*(fp64*)(data+24*i+16); Pid_List[i].Td=*(fp64*)(data+24*i+24); } }
void ApiReadPage(DWORD *argv) { void *buf; if ((argv[MSG_ATTR_ID] & MSG_MAP_MASK) != MSG_ATTR_ROMAP) return; if ((argv[MSG_ATTR_ID] & MSG_ATTR_MASK) == MSG_ATTR_ROMAP) { argv[MSG_RES_ID] = FS_ERR_WRONG_ARGS; KUnmapProcAddr((void*)argv[MSG_ADDR_ID], argv); return; } buf = (void*)argv[MSG_ADDR_ID]; argv[MSG_RES_ID] = ReadPage(pret[((THREAD_ID*)&argv[PTID_ID])->ProcID], buf, argv[MSG_SIZE_ID], argv[3]); KUnmapProcAddr(buf, argv); }
uint16_t BulkStorage_ReadData(struct BulkStorage *b, uint32_t addr, uint8_t *buffer, uint16_t size) { if (( b == NULL ) || ( buffer == NULL )) { return 0; } uint16_t page = CalcPage(addr); if ( page != b->loaded_page ) { if ( b->dirty != 0 ) { WritePage(b); b->dirty = 0; } ReadPage(b, page); } uint16_t offset = CalcPageAddr(addr); uint16_t length = size; if (( offset+size) > DATAFLASH_PAGESIZE_NORMAL ) { length = DATAFLASH_PAGESIZE_NORMAL - offset; } memcpy(buffer, b->data+offset, length); return length; }
/** * Insert the record whose contents is pointed at by recPtr into relation relNum. * * @param relNum - Relation number * @param recPtr - A pointer to a record-sized byte array whose contents * will be copied to an empty record slot in the relation. * @return OK or NOTOK * * @author nithin * * GLOBAL VARIABLES MODIFIED: * g_Buffer[relNum] * g_CatCache[relNum] * * ERRORS REPORTED: * NULL_ARGUMENT_RECEIVED * DUPLICATE_TUPLE * * ALGORITHM: * 1. Check if the record pointed by recPtr already exists in the relation * (only if the check duplicates flag is set) * 2. Find the first free slot in the relation by linear search * 3. Copy the contents into that slot * (using a loop and not strcpy) * 4. Update the dirty bit and slotmap in Buffer * 5. Update the dirty bit, numRecs and numPgs in CatCache * * IMPLEMENTATION NOTES: * Uses ReadPage() * * */ int InsertRec(const int relNum, char*recPtr) { if (recPtr == NULL) { return ErrorMsgs(NULL_ARGUMENT_RECEIVED, g_PrintFlag); } /* Checking for duplicates */ Rid *fRid, sRid = { 0, 0 }; char *record; while (GetNextRec(relNum, &sRid, &fRid, &record) == OK && g_CheckDuplicateTuples == OK) { if (compareRecords(record, recPtr, g_CatCache[relNum].recLength) == OK) { return ErrorMsgs(DUPLICATE_TUPLE, g_PrintFlag); } sRid = *fRid; free(fRid); } Rid startRid = { 1, 0 }, foundRid; /* Insert record */ getNextFreeSlot(relNum, startRid, &foundRid); ReadPage(relNum, foundRid.pid); unsigned int recLength = g_CatCache[relNum].recLength; int i, j; int offset = (foundRid.slotnum - 1) * recLength; for (i = offset, j = 0; j < recLength; ++i, j++) { g_Buffer[relNum].page.contents[i] = recPtr[j]; } /* Update dirty bits and slotmap*/ g_Buffer[relNum].dirty = TRUE; g_Buffer[relNum].page.slotmap = (g_Buffer[relNum].page.slotmap | 1 << (32 - foundRid.slotnum)); /* Update numRecs in catCache*/ g_CatCache[relNum].dirty = TRUE; g_CatCache[relNum].numRecs++; g_CatCache[relNum].numPgs = g_CatCache[relNum].numPgs > foundRid.pid ? g_CatCache[relNum].numPgs : foundRid.pid; return OK; }
void nand_boot(void) { unsigned int i; #if NADN_BOOT_DEBUG unsigned char *ram_addr = 0x30000000; #else unsigned char *ram_addr = TEXT_BASE; #endif int iSize = 0x60000; int iStartPage = 0; Uart_SendByte('N'); Uart_SendByte('B'); InitNandCfg(); i = ReadChipId(); if(i == 0xecda){ NandAddr = 1; Uart_SendByte('I'); Uart_SendByte('D'); } for(i=0; iSize>0; ) { if(!(i&0x3f)) { if(CheckBadBlk(i+iStartPage)) { i += 64; //iSize -= 64<<11; Uart_SendByte('C'); Uart_SendByte('B'); continue; } } ReadPage((i+iStartPage), ram_addr); i++; iSize -= 2048; ram_addr += 2048; } DsNandFlash(); }
/** * Gets the next free record in the relation starting from (not including) startRid * * @param relNum * @param startRid * @param foundRid * @return OK or NOTOK */ int getNextFreeSlot(const int relNum, const Rid startRid, Rid *foundRid) { int numPgs = g_CatCache[relNum].numPgs; int recsPerPg = g_CatCache[relNum].recsPerPg; Rid prevRid, curRid = getNextRid(startRid.pid, startRid.slotnum, recsPerPg, numPgs, getLastRid(relNum)); prevRid = curRid; int flag = NOTOK; while (curRid.pid <= numPgs && flag == NOTOK) { ReadPage(relNum, curRid.pid); do { //If slotmap says it is free if (!(g_Buffer[relNum].page.slotmap & (1 << (32 - curRid.slotnum)))) { flag = OK; break; } prevRid = curRid; curRid = getNextRid(curRid.pid, curRid.slotnum, recsPerPg, numPgs, getLastRid(relNum)); } while (prevRid.slotnum <= curRid.slotnum); } (*foundRid) = curRid; return OK; }
int _i2c_firmware_update_dp703(struct scaler_private_data *scaler) { int i=0,j=0,k=0,m=0; int fail = 0; int result = 0; int err_count = 0; //Step 1: Stop MPU and Reset SPI result = WriteReg(scaler, PAGE2_ADDRESS, 0xbc, 0xc0); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0xbc, 0x40); //stop MPU if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0xb0, 0x03); //set WP pin high if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0x90, 0x04); // Write-Disable if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0x92, 0x00); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0x93, 0x05); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0xb0, 0x02); // set WP pin low if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } //Step 2: Chip Erase //enable write status register result = WriteReg(scaler, PAGE2_ADDRESS, 0xb0, 0x03); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0x90, 0x50); // Enable-Write-Status-Register if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0x92, 0x00); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0x93, 0x05); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0xb0, 0x02); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } //disable all protection result = WriteReg(scaler, PAGE2_ADDRESS, 0xb0, 0x03); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0x90, 0x01); //Write-Status-Register if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0x90, 0x00); //Status Register if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0x92, 0x01); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0x93, 0x05); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0xb0, 0x02); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } //wait for SPI module ready result = wait_till_ready(scaler, PAGE2_ADDRESS, 0x9e, 0x0c); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } for(i=0; i<3; i++) { result = WriteReg(scaler, PAGE2_ADDRESS, 0x90, 0x05); // 0x05 RDSR; command of flash if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0x92, 0x00); // command length if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0x93, 0x01); // trigger read if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = wait_till_ready(scaler, PAGE2_ADDRESS, 0x93, 0x01);// wait for SPI command done if(!result) break; } if(i >= 3) return result; //enable DP701 mapping function result = WriteReg(scaler, PAGE2_ADDRESS, 0xb0, 0x03); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0xda, 0xaa); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0xda, 0x55); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0xda, 0x50); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0xda, 0x41); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0xda, 0x52); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0xda, 0x44); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } //write enable result = WriteReg(scaler, PAGE2_ADDRESS, 0xb0, 0x03); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0x90, 0x06); // Write-Enable command if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0x92, 0x00); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0x93, 0x05); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0xb0, 0x02); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } //chip erase result = WriteReg(scaler, PAGE2_ADDRESS, 0xb0, 0x03); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0x90, 0x60); //chip erase command if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0x92, 0x00); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0x93, 0x05); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } //wait for SPI interface ready result = wait_till_ready(scaler, PAGE2_ADDRESS,0x9e, 0x0c); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } //wait for SPI ROM until not busy for(i=0; i<3; i++) { result = WriteReg(scaler, PAGE2_ADDRESS, 0x90, 0x05); // 0x05 RDSR; Read-Status-Register if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0x92, 0x00); // command length if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0x93, 0x01); // trigger read if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = wait_till_ready(scaler, PAGE2_ADDRESS, 0x93, 0x01);// wait for SPI command done if(!result) break; } if(i >= 3) return result; result = WriteReg(scaler, PAGE2_ADDRESS, 0xb0, 0x02); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } //Step 3: Load F/W to SPI ROM result = WriteReg(scaler, PAGE2_ADDRESS, 0x82, 0x20); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } msleep(100); result = WriteReg(scaler, PAGE2_ADDRESS, 0x82, 0x00); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } for(k=0;k<16;k++) //1Mbytes SPI ROM Size (16 banks) { for(j=0; j<256; j++) { result = WriteReg(scaler, PAGE2_ADDRESS, 0x8e, j); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0x8f, k); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } for( i = 0; i <256; i++ ) { result = WriteReg(scaler, PAGE7_ADDRESS, i, binary_data_dp703[(k<<16) + (j<<8) + i]); // if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } // maybe should add some delay here } } } //Step 4: Verify SPI ROM fail=0; for(k=0;k<16;k++) //1Mbytes SPI ROM Size (16 banks) { for(j=0;j<256;j++) //read SPI ROM data to ReadHex { result = WriteReg(scaler, PAGE2_ADDRESS, 0x8e, j); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0x8f, k); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = ReadPage(scaler, PAGE7_ADDRESS, 0, 256, &binary_data_dp703_read[(k<<16) + (j<<8)]); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } } err_count = 0; for(m=0; m<65536; m++) { if(binary_data_dp703_read[m + (k<<16)] != binary_data_dp703[m + (k<<16)]) { err_count ++; printk("%d:0x%x,0x%x ", m + (k<<16), binary_data_dp703[m + (k<<16)], binary_data_dp703_read[m + (k<<16)]); if((m%6) == 0) printk("\n"); } } if(err_count > 0) { printk("%s:err_count=%d\n",__func__, err_count); return -1; } } //Step 5: Enable Write Protection //write enable result = WriteReg(scaler, PAGE2_ADDRESS, 0xb0, 0x03); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0x90, 0x50); // Enable-Write-Status-Register if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0x92, 0x00); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0x93, 0x05); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0xb0, 0x02); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } //enable write register protection result = WriteReg(scaler, PAGE2_ADDRESS, 0xb0, 0x03); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0x90, 0x01); //write status register value if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0x90, 0x8C); //protect BPL/BP0/BP1 if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0x92, 0x01); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0x93, 0x05); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0xb0, 0x02); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } //wait for SPI module ready result = wait_till_ready(scaler, PAGE2_ADDRESS, 0x9e, 0x0c); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } for(i=0; i<3; i++) { result = WriteReg(scaler, PAGE2_ADDRESS, 0x90, 0x05); // 0x05 RDSR; command of flash if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0x92, 0x00); // command length if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = WriteReg(scaler, PAGE2_ADDRESS, 0x93, 0x01); // trigger read if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } result = wait_till_ready(scaler, PAGE2_ADDRESS, 0x93, 0x01);// wait for SPI command done if(!result) break; } //disable DP701 mapping function if(i >= 3) return result; result = WriteReg(scaler, PAGE2_ADDRESS, 0xda, 0x00); if(result) { printk("%s:line=%d, error\n",__func__, __LINE__); return result; } return result; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { register int nVpn; FILE *pFileOutPtr = NULL; int nFileLength; char *cBuffer = NULL; #ifdef USE2PLANE_L UINT8 pData[(SECTORS_PER_PAGE_L*BYTES_PER_SECTOR_L)*2]; UINT8 pSpare[(SECTORS_PER_PAGE_L*BYTES_PER_SPARE_L)*2]; #else UINT8 pData[(SECTORS_PER_PAGE_L*BYTES_PER_SECTOR_L)]; UINT8 pSpare[(SECTORS_PER_PAGE_L*BYTES_PER_SPARE_L)]; #endif DWORD dwOSStartPage; DWORD dwOSEndPage; DWORD dwFTLStartPage; DWORD dwFTLEndPage; #ifdef DUMPOS // Extract OS Image routine... RETAILMSG(1,(TEXT("Dump OS Image\r\n"))); pFileOutPtr = fopen("Temp/OSIMG.IMG", "wb"); if (!pFileOutPtr) { RETAILMSG(1,(TEXT("Storage Card/OSIMG.IMG file is not opened.!!!\r\n"))); goto Fail; } fseek(pFileOutPtr, 0, SEEK_SET); dwOSStartPage = SPECIAL_AREA_START_L * PAGES_PER_SUBLK_L; dwOSEndPage = (SPECIAL_AREA_START_L+SPECIAL_AREA_SIZE_L) * PAGES_PER_SUBLK_L - 1; RETAILMSG(1,(TEXT("OS Area is from %d to %d\r\n"), dwOSStartPage, dwOSEndPage)); RETAILMSG(1,(TEXT("Scanning...\r\n"))); // Scan All FF area for ( nVpn = dwOSEndPage; nVpn > dwOSStartPage; nVpn-- ) { memset(pData, 0xFF, sizeof(pData)); memset(pSpare, 0xFF, sizeof(pSpare)); ReadPage( nVpn, pData, pSpare ); if ( CheckAllFF(pData, sizeof(pData)) == TRUE32 && CheckAllFF(pSpare, sizeof(pSpare)) ) // TRUE32 means All FF { continue; } else { break; } } dwOSEndPage = nVpn + 1; RETAILMSG(1,(TEXT("Read Sector from %d to %d\r\n"), dwOSStartPage, dwOSEndPage)); for( nVpn=dwOSStartPage; nVpn<dwOSEndPage; nVpn++ ) { // RETAILMSG(1,(TEXT("Read Page %d\r\n"), nVpn)); RETAILMSG(1,(TEXT(" %02d Percent Completed"), ((nVpn - dwOSStartPage)*100)/(dwOSEndPage - dwOSStartPage))); memset(pData, 0xFF, sizeof(pData)); memset(pSpare, 0xFF, sizeof(pSpare)); ReadPage( nVpn, pData, pSpare ); #ifdef USE2PLANE_L // Write First plane // RETAILMSG(1,(TEXT("Write First plane : page number (%d) mem (0x%x)\r\n"), nVpn*2, (nVpn-dwOSStartPage)*(2048+64))); fwrite(pData, sizeof(char), (SECTORS_PER_PAGE_L*BYTES_PER_SECTOR_L), pFileOutPtr); fwrite(pSpare, sizeof(char), (SECTORS_PER_PAGE_L*BYTES_PER_SPARE_L), pFileOutPtr); // Write Second plane // RETAILMSG(1,(TEXT("Write Second plane : page number (%d) mem (0x%x)\r\n"), nVpn*2+128, (nVpn-dwOSStartPage+128)*(2048+64))); fwrite(pData+(SECTORS_PER_PAGE_L*BYTES_PER_SECTOR_L), sizeof(char), (SECTORS_PER_PAGE_L*BYTES_PER_SECTOR_L), pFileOutPtr); fwrite(pSpare+(SECTORS_PER_PAGE_L*BYTES_PER_SPARE_L), sizeof(char), (SECTORS_PER_PAGE_L*BYTES_PER_SPARE_L), pFileOutPtr); #else // Write First plane // RETAILMSG(1,(TEXT("Write First plane : page number (%d) mem (0x%x)\r\n"), nVpn*2, (nVpn-dwOSStartPage)*(2048+64))); fwrite(pData, sizeof(char), (SECTORS_PER_PAGE_L*BYTES_PER_SECTOR_L), pFileOutPtr); fwrite(pSpare, sizeof(char), (SECTORS_PER_PAGE_L*BYTES_PER_SPARE_L), pFileOutPtr); #endif RETAILMSG(1,(TEXT("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"))); } if (pFileOutPtr) fclose(pFileOutPtr); RETAILMSG(1,(TEXT("Dump OS Image Finished\r\n"))); #endif #ifdef DUMPFS // Extract FileSystem Image routine... RETAILMSG(1,(TEXT("Dump FTL Image\r\n"))); pFileOutPtr = fopen("Temp/FTLIMG.IMG", "wb"); if (!pFileOutPtr) { RETAILMSG(1,(TEXT("Storage Card/FTLIMG.IMG file is not opened.!!!\r\n"))); goto Fail; } fseek(pFileOutPtr, 0, SEEK_SET); dwFTLStartPage = FTL_AREA_START_L * PAGES_PER_SUBLK_L; dwFTLEndPage = (FTL_AREA_START_L+FTL_AREA_SIZE_L) * PAGES_PER_SUBLK_L - 1; RETAILMSG(1,(TEXT("FTL Area is from %d to %d\r\n"), dwFTLStartPage, dwFTLEndPage)); RETAILMSG(1,(TEXT("Scanning...\r\n"))); // Scan All FF area for ( nVpn = dwFTLEndPage; nVpn > dwFTLStartPage; nVpn-- ) { memset(pData, 0xFF, sizeof(pData)); memset(pSpare, 0xFF, sizeof(pSpare)); ReadPage( nVpn, pData, pSpare ); if ( CheckAllFF(pData, sizeof(pData)) == TRUE32 && CheckAllFF(pSpare, sizeof(pSpare)) ) // TRUE32 means All FF { continue; } else { break; } } dwFTLEndPage = nVpn + 1; RETAILMSG(1,(TEXT("Read Sector from %d to %d\r\n"), dwFTLStartPage, dwFTLEndPage)); for( nVpn=dwFTLStartPage; nVpn<dwFTLEndPage; nVpn++ ) { // RETAILMSG(1,(TEXT("Read Page %d\r\n"), nVpn)); RETAILMSG(1,(TEXT(" %02d Percent Completed"), ((nVpn - dwFTLStartPage)*100)/(dwFTLEndPage - dwFTLStartPage))); memset(pData, 0xFF, sizeof(pData)); memset(pSpare, 0xFF, sizeof(pSpare)); ReadPage( nVpn, pData, pSpare ); #ifdef USE2PLANE_L // Write First plane // RETAILMSG(1,(TEXT("Write First plane : page number (%d) mem (0x%x)\r\n"), nVpn*2, (nVpn-dwOSStartPage)*(2048+64))); fwrite(pData, sizeof(char), (SECTORS_PER_PAGE_L*BYTES_PER_SECTOR_L), pFileOutPtr); fwrite(pSpare, sizeof(char), (SECTORS_PER_PAGE_L*BYTES_PER_SPARE_L), pFileOutPtr); // Write Second plane // RETAILMSG(1,(TEXT("Write Second plane : page number (%d) mem (0x%x)\r\n"), nVpn*2+128, (nVpn-dwOSStartPage+128)*(2048+64))); fwrite(pData+(SECTORS_PER_PAGE_L*BYTES_PER_SECTOR_L), sizeof(char), (SECTORS_PER_PAGE_L*BYTES_PER_SECTOR_L), pFileOutPtr); fwrite(pSpare+(SECTORS_PER_PAGE_L*BYTES_PER_SPARE_L), sizeof(char), (SECTORS_PER_PAGE_L*BYTES_PER_SPARE_L), pFileOutPtr); #else // Write First plane // RETAILMSG(1,(TEXT("Write First plane : page number (%d) mem (0x%x)\r\n"), nVpn*2, (nVpn-dwOSStartPage)*(2048+64))); fwrite(pData, sizeof(char), (SECTORS_PER_PAGE_L*BYTES_PER_SECTOR_L), pFileOutPtr); fwrite(pSpare, sizeof(char), (SECTORS_PER_PAGE_L*BYTES_PER_SPARE_L), pFileOutPtr); #endif RETAILMSG(1,(TEXT("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"))); } if (pFileOutPtr) fclose(pFileOutPtr); RETAILMSG(1,(TEXT("Dump FTL Image Finished\r\n"))); #endif return 0; Fail: RETAILMSG(1,(TEXT("WMR_RW_test is failed.!!\r\n"))); if (pFileOutPtr) fclose(pFileOutPtr); return 0; }
status_t OggTobiasSeekable::GetStreamInfo(int64 *frameCount, bigtime_t *duration, media_format *format) { TRACE("OggTobiasSeekable::GetStreamInfo\n"); status_t result = B_OK; ogg_packet packet; // get header packet if (GetHeaderPackets().size() < 1) { result = GetPacket(&packet); if (result != B_OK) { return result; } SaveHeaderPacket(packet); } packet = GetHeaderPackets()[0]; if (!packet.b_o_s) { return B_ERROR; // first packet was not beginning of stream } // parse header packet if (packet.bytes < 1+(signed)sizeof(tobias_stream_header)) { return B_ERROR; } void * data = &(packet.packet[1]); tobias_stream_header * header = (tobias_stream_header *)data; if (strcmp(header->streamtype, "video") == 0) { result = get_video_format(header, format); if (result != B_OK) { return result; } } else if (strcmp(header->streamtype, "audio") == 0) { result = get_audio_format(header, format); if (result != B_OK) { return result; } } else if (strcmp(header->streamtype, "text") == 0) { result = get_text_format(header, format); if (result != B_OK) { return result; } } else { *frameCount = 0; // unknown streamtype return B_BAD_VALUE; } // get comment packet if (GetHeaderPackets().size() < 2) { result = GetPacket(&packet); if (result != B_OK) { return result; } SaveHeaderPacket(packet); } format->SetMetaData((void*)&GetHeaderPackets(),sizeof(GetHeaderPackets())); fMediaFormat = *format; fMicrosecPerFrame = header->time_unit / 10.0; fFrameRate = header->samples_per_unit * 1000000.0 / fMicrosecPerFrame; // TODO: count the frames in the first page.. somehow.. :-/ int64 frames = 0; ogg_page page; // read the first page result = ReadPage(&page); if (result != B_OK) { return result; } int64 fFirstGranulepos = ogg_page_granulepos(&page); TRACE("OggVorbisSeekable::GetStreamInfo: first granulepos: %lld\n", fFirstGranulepos); // read our last page off_t last = inherited::Seek(GetLastPagePosition(), SEEK_SET); if (last < 0) { return last; } result = ReadPage(&page); if (result != B_OK) { return result; } int64 last_granulepos = ogg_page_granulepos(&page); // seek back to the start int64 frame = 0; bigtime_t time = 0; result = Seek(B_MEDIA_SEEK_TO_TIME, &frame, &time); if (result != B_OK) { return result; } // compute frame count and duration from sample count frames = last_granulepos - fFirstGranulepos; *frameCount = frames; *duration = (long long)((1000000LL * frames) / (double)fFrameRate); return B_OK; }
status_t OggVorbisSeekable::GetStreamInfo(int64 *frameCount, bigtime_t *duration, media_format *format) { TRACE("OggVorbisSeekable::GetStreamInfo\n"); status_t result = B_OK; ogg_packet packet; // get header packet if (GetHeaderPackets().size() < 1) { result = GetPacket(&packet); if (result != B_OK) { return result; } SaveHeaderPacket(packet); } packet = GetHeaderPackets()[0]; if (!packet.b_o_s) { return B_ERROR; // first packet was not beginning of stream } // parse header packet // based on libvorbis/info.c vorbis_synthesis_headerin(...) oggpack_buffer opb; oggpack_readinit(&opb, packet.packet, packet.bytes); int packtype = oggpack_read(&opb, 8); if (packtype != 0x01) { return B_ERROR; // first packet was not an info packet } // discard vorbis string for (uint i = 0 ; i < sizeof("vorbis") - 1 ; i++) { oggpack_read(&opb, 8); } vorbis_info info; if (_vorbis_unpack_info(&info, &opb) != 0) { return B_ERROR; // couldn't unpack info } // get the format for the description media_format_description description = vorbis_description(); BMediaFormats formats; result = formats.InitCheck(); if (result == B_OK) { result = formats.GetFormatFor(description, format); } if (result != B_OK) { *format = vorbis_encoded_media_format(); // ignore error, allow user to use ReadChunk interface } // fill out format from header packet if (info.bitrate_nominal > 0) { format->u.encoded_audio.bit_rate = info.bitrate_nominal; } else if (info.bitrate_upper > 0) { format->u.encoded_audio.bit_rate = info.bitrate_upper; } else if (info.bitrate_lower > 0) { format->u.encoded_audio.bit_rate = info.bitrate_lower; } if (info.channels == 1) { format->u.encoded_audio.multi_info.channel_mask = B_CHANNEL_LEFT; } else { format->u.encoded_audio.multi_info.channel_mask = B_CHANNEL_LEFT | B_CHANNEL_RIGHT; } fFrameRate = format->u.encoded_audio.output.frame_rate = (float)info.rate; format->u.encoded_audio.output.channel_count = info.channels; format->u.encoded_audio.output.buffer_size = AudioBufferSize(&format->u.encoded_audio.output); // get comment packet if (GetHeaderPackets().size() < 2) { result = GetPacket(&packet); if (result != B_OK) { return result; } SaveHeaderPacket(packet); } // get codebook packet if (GetHeaderPackets().size() < 3) { result = GetPacket(&packet); if (result != B_OK) { return result; } SaveHeaderPacket(packet); } format->SetMetaData((void*)&GetHeaderPackets(),sizeof(GetHeaderPackets())); // TODO: count the frames in the first page.. somehow.. :-/ int64 frames = 0; ogg_page page; // read the first page result = ReadPage(&page); if (result != B_OK) { return result; } int64 fFirstGranulepos = ogg_page_granulepos(&page); TRACE("OggVorbisSeekable::GetStreamInfo: first granulepos: %lld\n", fFirstGranulepos); // read our last page off_t last = inherited::Seek(GetLastPagePosition(), SEEK_SET); if (last < 0) { return last; } result = ReadPage(&page); if (result != B_OK) { return result; } int64 last_granulepos = ogg_page_granulepos(&page); // seek back to the start int64 frame = 0; bigtime_t time = 0; result = Seek(B_MEDIA_SEEK_TO_TIME, &frame, &time); if (result != B_OK) { return result; } // compute frame count and duration from sample count frames = last_granulepos - fFirstGranulepos; *frameCount = frames; *duration = (1000000LL * frames) / (long long)fFrameRate; return B_OK; }