int main(void) { _entry:; int i; for (i=0; i < 10; i++) sub(); trl(); trvp(i); trvx(i); trvd(i); trvd(sizeof(long long)); trvd(sizeof(size_t)); trvd(sizeof(void*)); trvd(sizeof(int)); trvd(sizeof(short)); trvd(sizeof(char)); return 0; }
Uint32 LOCAL_NANDWriteHeaderAndData(NAND_InfoHandle hNandInfo, NANDBOOT_HeaderHandle hNandBoot, Uint8 *srcBuf) { Uint32 *ptr; Uint32 currBlockNum,currPageNum,pageCnt,i; Uint32 numBlks, numBlksRemaining; trl_(); trvx_(hNandBoot->startBlock); trvx(hNandBoot->endBlock); trvx(srcBuf); hNandWriteBuf = UTIL_allocMem(hNandInfo->dataBytesPerPage); hNandReadBuf = UTIL_allocMem(hNandInfo->dataBytesPerPage); extern __FAR__ Uint32 EXTERNAL_RAM_START, EXTERNAL_RAM_END; trvx(&EXTERNAL_RAM_START); trvx(hNandWriteBuf); trvx(hNandReadBuf); // Unprotect all needed blocks of the flash if (NAND_unProtectBlocks(hNandInfo,hNandBoot->startBlock,hNandBoot->endBlock-hNandBoot->startBlock+1) != E_PASS) { DEBUG_printString("Unprotect failed\r\n"); return E_FAIL; } // Check if device is write protected if (NAND_isWriteProtected(hNandInfo)) { DEBUG_printString("NAND is write protected!\r\n"); return E_FAIL; } // Get total number of blocks needed for each copy numBlks = 0; while ( (numBlks * hNandInfo->pagesPerBlock) < (hNandBoot->numPage + 1) ) { numBlks++; } DEBUG_printString("Number of blocks needed for header and data: 0x"); DEBUG_printHexInt(numBlks); DEBUG_printString("\r\n"); // Init internal current block number counter currBlockNum = hNandBoot->startBlock; // Go to first good block while (NAND_badBlockCheck(hNandInfo,currBlockNum) != E_PASS) { DEBUG_printString("NAND block "); DEBUG_printHexInt(currBlockNum); DEBUG_printString(" is bad!!!\r\n"); currBlockNum++; // Now check to make sure we aren't already out of space if (currBlockNum > (hNandBoot->endBlock + numBlks - 1 )) { DEBUG_printString("No good blocks in allowed range!!!\r\n"); return E_FAIL; } } DEBUG_printString("Attempting to start in block number 0x"); DEBUG_printHexInt(currBlockNum); DEBUG_printString(".\r\n"); // Keep going while we have room to place another copy do { numBlksRemaining = numBlks; // Erase the block where the header goes and the data starts if (NAND_eraseBlocks(hNandInfo,currBlockNum,numBlks) != E_PASS) { // Attempt to mark block bad NAND_badBlockMark(hNandInfo, currBlockNum); currBlockNum++; DEBUG_printString("Erase failed\r\n"); continue; } trl(); // Clear write buffer ptr = (Uint32 *) hNandWriteBuf; for (i=0; i < hNandInfo->dataBytesPerPage >> 2; i++) { ptr[i] = 0xFFFFFFFF; } trl(); // Setup header to be written ptr[0] = hNandBoot->magicNum; ptr[1] = hNandBoot->entryPoint; ptr[2] = hNandBoot->numPage; ptr[3] = currBlockNum; //always start data in current block ptr[4] = 1; //always start data in page 1 (this header goes in page 0) ptr[5] = hNandBoot->ldAddress; // Write the header to page 0 of the current blockNum DEBUG_printString("Writing header and image data to Block "); DEBUG_printHexInt(currBlockNum); DEBUG_printString(", Page "); DEBUG_printHexInt(0); DEBUG_printString("\r\n"); trl(); #ifdef DM35X_REVB #define DM35X_REVC #endif #ifdef DM35X_REVC if (NAND_writePage_ubl_header(hNandInfo, currBlockNum, 0, hNandWriteBuf) != E_PASS) { // Attempt to mark block bad NAND_badBlockMark(hNandInfo, currBlockNum); currBlockNum++; DEBUG_printString("Write failed!\r\n"); continue; } #else if (NAND_writePage(hNandInfo, currBlockNum, 0, hNandWriteBuf) != E_PASS) { // Attempt to mark block bad NAND_badBlockMark(hNandInfo, currBlockNum); currBlockNum++; DEBUG_printString("Write failed!\r\n"); continue; } #endif UTIL_waitLoop(200); // Verify the page just written if (NAND_verifyPage(hNandInfo, currBlockNum, 0, hNandWriteBuf, hNandReadBuf) != E_PASS) { // Attempt to mark block bad NAND_badBlockMark(hNandInfo, currBlockNum); currBlockNum++; DEBUG_printString("Write verify failed!\r\n"); continue; } pageCnt = 1; currPageNum = 1; do { // Write the UBL or APP data on a per page basis if (NAND_writePage(hNandInfo, currBlockNum, currPageNum, srcBuf) != E_PASS) { // Attempt to mark block bad NAND_badBlockMark(hNandInfo, currBlockNum); currBlockNum++; DEBUG_printString("Write failed, skipping block!\r\n"); if ( (numBlksRemaining == numBlks) || (hNandBoot->forceContigImage) ) break; // If we are still in the first block, we have to go rewrite the header too else { srcBuf -= (hNandInfo->dataBytesPerPage * currPageNum); trvx(srcBuf); pageCnt -= currPageNum; currPageNum = 0; continue; } } UTIL_waitLoop(200); // Verify the page just written if (NAND_verifyPage(hNandInfo, currBlockNum, currPageNum, srcBuf, hNandReadBuf) != E_PASS) { // Attempt to mark block bad NAND_badBlockMark(hNandInfo, currBlockNum); currBlockNum++; DEBUG_printString(RED"Write verify failed, skipping block!\r\n"NOCOLOR); if ( (numBlksRemaining == numBlks) || (hNandBoot->forceContigImage) ) break; // If we are still in the first block, we have to go rewrite the header too else { srcBuf -= (hNandInfo->dataBytesPerPage * currPageNum); trvx(srcBuf); pageCnt -= currPageNum; currPageNum = 0; continue; } } srcBuf += hNandInfo->dataBytesPerPage; pageCnt++; currPageNum++; // If we need to go the next block, or our image is complete, increment current block num if ( (currPageNum == hNandInfo->pagesPerBlock) || (pageCnt >= (hNandBoot->numPage+1)) ) { trvi(currPageNum); currBlockNum++; numBlksRemaining--; srcBuf -= hNandInfo->dataBytesPerPage * currPageNum; currPageNum = 0; } } while ( (pageCnt < (hNandBoot->numPage+1)) && ((currBlockNum + numBlksRemaining - 1)<=hNandBoot->endBlock) ); trvi(pageCnt); } while( (currBlockNum + numBlks - 1)<=hNandBoot->endBlock ); // Protect all blocks NAND_protectBlocks(hNandInfo); // We succeeded in writing all copies that would fit return E_PASS; }
int main(int argc, char** argv) { cold::TextResourceLoader trl("data/"); cold::ResourceLoader::provide(&trl); cold::Application app; app.create_window(cold::os::get_screen_width(), cold::os::get_screen_height(), 16, cold::Application::WINDOW_NO_BORDER, cold::Application::TOP_LEFT); app.set_title("Cold test"); cold::Shader shader; shader.compile_file("data\\shader\\test.vert", "data\\shader\\test.frag"); auto ps = glm::perspective(90.0f, 800.0f / 600.0f, 0.1f, 1000.0f); cold::Scene s(new cold::Map(128, 16, 128)); for (int x = 0; x < 128; x++) { for (int z = 0; z < 128; z++) { s.map->get_block(x, 0, z)->set_solid(1); } } srand((unsigned int)time(NULL)); for (int i = 0; i < 2000; i++) { s.map->get_block(rand()%128, rand()%16, rand()%128)->set_solid(1); } s.map->get_block(2, 1, 3)->set_solid(1); s.map->get_block(2, 1, 4)->set_solid(1); s.map->get_block(2, 1, 5)->set_solid(1); s.map->get_block(2, 1, 6)->set_solid(1); s.add(new cold::EntityPlayer(glm::vec3(5.0f, 5.0f, 5.0f))); s.gravity = glm::vec3(0.0f, 0.0f, 0.0f); cold::RenderChunk rs(0, 0, 0, 128, 16, 128); rs.update(*s.map); float time = 0.0f; cold::Bind<bool> exit_bind; exit_bind += new cold::KeyInput(cold::KeyInput::PRESSED, SDLK_ESCAPE); //exit_bind += new cold::AndInput(new cold::KeyInput(cold::KeyInput::DOWN, SDLK_LALT), new cold::KeyInput(cold::KeyInput::PRESSED, SDLK_F4)); //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glEnable(GL_DEPTH_TEST); while (app.is_running()) { app.poll_events(); float elapsed = app.update_elapsed(); if (elapsed > 0.1f) continue; time += elapsed; s.update(elapsed); glClearColor(0.39f, 0.58f, 0.93f, 1.0f); glClearDepth(1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); s.camera.update(); shader.uniforms["WVP"] = s.camera.view_projection; s.draw(); shader.apply(); rs.draw(); SDL_GL_SwapBuffers(); if (exit_bind.get()) app.quit(); } return 0; }