// erase bootloader's section and write over it with new bootloader code void write_new_bootloader(void) { uint16_t outgoing_page[SPM_PAGESIZE / 2]; int iter = 0; while (iter < sizeof(bootloader_data)) { // read in one page's worth of data from progmem int word_addr = 0; while (word_addr < SPM_PAGESIZE) { int subaddress = ((int) bootloader_data) + iter + word_addr; if (subaddress >= ((int) bootloader_data) + sizeof(bootloader_data)) { outgoing_page[word_addr / 2] = 0xFFFF; } else { outgoing_page[word_addr / 2] = pgm_read_word(subaddress); } word_addr += 2; } // erase page in destination erase_page(bootloader_address + iter); // write updated page write_page(bootloader_address + iter, outgoing_page); iter += 64; } }
u64 disk_read( u32 block, u16 address ) { printf( "Reading block %d from disk\n", block ); u32 delta = rand( ); if ( time_get( ) > disk_time ) { disk_time = time_get( ); } if ( delta & 1 ) { disk_time += read_latency + ( delta & 0x3FFFFF ); } else { disk_time += read_latency - ( delta & 0x1FFFFF ); } if ( block < SWAP_SIZE ) { write_page( address ); } return disk_time; }
static int flush_swap_writer(struct swap_map_handle *handle) { if (handle->cur && handle->cur_swap) return write_page(handle->cur, handle->cur_swap); else return -EINVAL; }
int main(void) { CLKPR = 0x80; CLKPR = 0x00; MCUCR = (1<<IVCE); MCUCR = (1<<IVSEL); i2c_slave_transmit = transmit; i2c_slave_receive = receive; i2c_slave_init(0x10); addr = 0x0000; read_page(addr); sei(); do { _delay_ms(1000); } while (state != BOOT); cli(); write_page(); MCUCR = (1<<IVCE); MCUCR = (0<<IVSEL); app_main = (void *)addr; boot_rww_enable_safe(); app_main(); }
/* this is the callback that the NAND core calls to write a page. Since * writing a page with ECC or without is similar, all the work is done * by write_page above. * */ static int denali_write_page(struct mtd_info *mtd, struct nand_chip *chip, const uint8_t *buf, int oob_required) { /* for regular page writes, we let HW handle all the ECC * data written to the device. */ return write_page(mtd, chip, buf, false); }
int main(int ac, char **av) { if(ac > 1) { param_t p; int parse_ret; if((parse_ret = parse_opts(&p, ac, av)) < 0) { std::fprintf(stderr, USAGE, av[0]); if (ac == 1) return (EXIT_SUCCESS); return (EXIT_FAILURE); } disp_info_bmp(p.input_bitmap); write_page(&p); free_bitmap(p.input_bitmap); } else { QApplication app(ac, av); AscurpiQ gui; gui.show(); return app.exec(); } }
/* this is the callback that the NAND core calls to write a page. Since * writing a page with ECC or without is similar, all the work is done * by write_page above. * */ static void denali_write_page(struct mtd_info *mtd, struct nand_chip *chip, const uint8_t *buf) { /* for regular page writes, we let HW handle all the ECC * data written to the device. */ write_page(mtd, chip, buf, false); }
void ftl_write(UINT32 const lba, UINT32 const num_sectors) { SET_WRITE; ftl_w++; UINT32 remain_sects, num_sectors_to_write; UINT32 lpn, sect_offset; lpn = lba / SECTORS_PER_PAGE; sect_offset = lba % SECTORS_PER_PAGE; remain_sects = num_sectors; while (remain_sects != 0) { if ((sect_offset + remain_sects) < SECTORS_PER_PAGE) { num_sectors_to_write = remain_sects; } else { num_sectors_to_write = SECTORS_PER_PAGE - sect_offset; } write_page(lpn, sect_offset, num_sectors_to_write); sect_offset = 0; remain_sects -= num_sectors_to_write; lpn++; } CLEAR_WRITE; }
/* This is the callback that the NAND core calls to write a page without ECC. * raw access is similar to ECC page writes, so all the work is done in the * write_page() function above. */ static void denali_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip, const uint8_t *buf) { /* for raw page writes, we want to disable ECC and simply write whatever data is in the buffer. */ write_page(mtd, chip, buf, true); }
void ftl_write(UINT32 const lba, UINT32 const num_sectors) { UINT32 remain_sects, num_sectors_to_write; UINT32 lpn, sect_offset; lpn = lba / SECTORS_PER_PAGE; sect_offset = lba % SECTORS_PER_PAGE; remain_sects = num_sectors; while (remain_sects != 0) { if ((sect_offset + remain_sects) < SECTORS_PER_PAGE) { num_sectors_to_write = remain_sects; } else { num_sectors_to_write = SECTORS_PER_PAGE - sect_offset; } // single page write individually write_page(lpn, sect_offset, num_sectors_to_write); sect_offset = 0; remain_sects -= num_sectors_to_write; lpn++; } }
obj write_dirty_pages( struct RStore *store ) { struct VMPageRecord *page; while ((page = store->first_dirty)) { obj unresolved = write_page( store, page ); if (!EQ(unresolved,NIL_OBJ)) { /* note that if there was anything unresolved, we do NOT mark this page as clean, because it wasn't written */ return unresolved; } page->ref.dirty = 0; store->num_dirty--; if (!(store->first_dirty = page->next_dirty)) { store->last_dirty = NULL; } page->next_dirty = NULL; mm_set_prot( page->mem_address, MM_PAGE_SIZE, MM_MODE_READ_ONLY ); } return NIL_OBJ; }
int swap_out(struct addrspace* as, vaddr_t va, void* kbuf){ (void)kbuf; int itr = 0; for(; itr < MAX_VAL; itr++){ if(sw_space[itr].sw_vaddr == 0){ sw_space[itr].sw_addrspace = as; sw_space[itr].sw_vaddr = va; if(write_page(kbuf, &sw_space[itr].sw_offset, itr)){ panic("Error while swapping out\n"); return 1; } break; } } if(itr == MAX_VAL){ panic("Running out of memory\n"); return 1; }else{ return 0; } }
long eprom24x_io::write(uint32_t addr, const void *data, uint16_t len) { try { // Lockdown the write operation pthread_mutex_lock(&m_rw_mutex); // Check that there is enough room for data on chip check_valid_access(addr, len); // Use page write if supported by chip if (m_page_size_in_bytes) { write_page(addr, (const uint8_t *)data, len); } else { write_byte(addr, (const uint8_t *)data, len); } pthread_mutex_unlock(&m_rw_mutex); return EPROM24x_SUCCESS; } catch (...) { pthread_mutex_unlock(&m_rw_mutex); throw; } }
void finit_write() { if (m_out) { files[0].first = next_findex; write_page(1, (UCHAR*)files); fclose(m_out); m_out = NULL; } }
void write_to_file(std::string const & filename) { if( page_size != 0x4000){ std::cout << "need 0x4000 page_size..\n"; return; } std::ofstream out(filename); out << "#include <cstdint>\n\n"; out << " static __attribute__((section(\".flash_variables\"),used)) "; out << " uint8_t const flash_variables_array["<< (page_size * 2) << "] = {\n"; write_page(out,page1_array, page_size); out << ",\n //---------------------------------------------\n"; write_page(out,page2_array,page_size); out << "\n };\n"; }
void ogg_ostream::write_packet(ogg_packet & packet) { CHECK(ogg_stream_packetin(&stream_state_, &packet) == 0); ogg_page page; while (ogg_stream_pageout(&stream_state_, &page)) { write_page(page); } }
/* * This is the callback that the NAND core calls to write a page without ECC. * raw access is similar to ECC page writes, so all the work is done in the * write_page() function above. */ static int denali_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip, const uint8_t *buf, int oob_required) { /* * for raw page writes, we want to disable ECC and simply write * whatever data is in the buffer. */ return write_page(mtd, chip, buf, true); }
void vmem_write(int address, int data) { if(vmem == NULL) { //Überprüfen ob mit shared Memory verbunden vm_init(); } int page = address/VMEM_PAGESIZE; int offset = address%VMEM_PAGESIZE; vmem->adm.req_pageno = page; sem_wait(&vmem->adm.sema); if((vmem->pt.entries[page].flags & PTF_PRESENT) == PTF_PRESENT) { write_page(page, offset, data); /* Seite schreiben */ } else { kill(vmem->adm.mmanage_pid, SIGUSR1); sem_wait(&vmem->adm.sema); write_page(page, offset, data); /* Seite schreiben */ } sem_post(&vmem->adm.sema); }
/** * Send write command. * * After WR command cpu write bufferd page into flash memory. * */ INLINE void flash_sendWRcmd(uint32_t page) { cpu_flags_t flags; LOG_INFO("Writing page %ld...\n", page); IRQ_SAVE_DISABLE(flags); write_page(page); IRQ_RESTORE(flags); LOG_INFO("Done\n"); }
void shell_server(void) { uint8_t command; uint8_t keepGoing = FALSE; load_state = 0; mcs_comm_open(); i2c_eeprom_init(); /*identify ourselves to the shell*/ mcs_send(MCS_PRESENT); mcs_send(MCS_PRESENT); if(mcs_recv() == SHELL_PRESENT) { keepGoing = TRUE; while(keepGoing) { command = mcs_recv(); switch(command) { case WRITE_PAGE: write_page(); break; case READ_FLASH: #warning "Using 1 for red LED" mos_led_on(1); read_flash(); break; case READ_FUSES: read_fuses(); break; case WRITE_EEPROM: write_eeprom(); break; case READ_EEPROM: read_eeprom(); break; case QUIT: keepGoing = FALSE; break; case START: mcs_send(START); //commit_and_reset(); break; default: ; } } } }
// write in forwarding interrupt vector table void forward_interrupt_vector_table(void) { uint16_t vector_table[SPM_PAGESIZE / 2]; int iter = 0; while (iter < SPM_PAGESIZE / 2) { // rjmp to bootloader_address's interrupt table vector_table[iter] = 0xC000 + (bootloader_address / 2) - 1; iter++; } erase_page(0); write_page(0, vector_table); }
static int close_swap(void) { swp_entry_t entry; int error; error = write_page((unsigned long)&swsusp_info,&entry); if (!error) { printk( "S" ); error = mark_swapfiles(entry); printk( "|\n" ); } return error; }
static int write_pagedir(void) { unsigned long addr = (unsigned long)pagedir_nosave; int error = 0; int n = SUSPEND_PD_PAGES(nr_copy_pages); int i; swsusp_info.pagedir_pages = n; printk( "Writing pagedir (%d pages)\n", n); for (i = 0; i < n && !error; i++, addr += PAGE_SIZE) error = write_page(addr, &swsusp_info.pagedir[i]); return error; }
static int push_virtio_ring(char *buf, uint32_t gpa, uint32_t vr_sz) { uint32_t i; for (i = 0; i < vr_sz; i += VIRTIO_PAGE_SIZE) { if (write_page((uint32_t)gpa + i, buf + i, PAGE_SIZE, 0)) { return (1); } } return (0); }
static int do_write(void *dst, size_t len, void *d) { struct sync_data *data = d; #ifndef NDEBUG // Things need to get more sophisticated if we write out more than // a page at a time if(len != QUANTUM_SIZE) crash(); #endif data->got = write_page(data, dst); return EOK; }
unsigned char receive(volatile unsigned char *buffer, unsigned char size) { if (buffer == 0) { state = START; return 3; } else { switch (state) { case START: if (size == 3) { addr = (uint16_t)buffer[1] << 8 | (uint16_t)buffer[2]; switch (buffer[0]) { case 0x00: state = READ; break; case 0x01: state = WRITE; return SPM_PAGESIZE - page_offset(addr); case 0x02: state = BOOT; break; default: break; } return 0; } break; case WRITE: if(page_address != page_start(addr)) { write_page(); read_page(page_start(addr)); } for (i = 0; i < size; i++) { page_buffer[page_offset(addr)] = buffer[i]; addr++; page_dirty = 1; } return SPM_PAGESIZE - page_offset(addr); default: break; } } return 0; }
static libspectrum_error write_48k_sna( libspectrum_byte **buffer, libspectrum_byte **ptr, size_t *length, libspectrum_snap *snap ) { libspectrum_error error; libspectrum_byte *stack, *sp; /* Must have somewhere in RAM to store PC */ if( libspectrum_snap_sp( snap ) < 0x4002 ) { libspectrum_print_error( LIBSPECTRUM_ERROR_INVALID, "SP is too low (0x%04x) to stack PC", libspectrum_snap_sp( snap ) ); return LIBSPECTRUM_ERROR_INVALID; } libspectrum_make_room( buffer, 0xc000, ptr, length ); error = write_page( &( (*ptr)[ 0x0000 ] ), snap, 5 ); if( error ) return error; error = write_page( &( (*ptr)[ 0x4000 ] ), snap, 2 ); if( error ) return error; error = write_page( &( (*ptr)[ 0x8000 ] ), snap, 0 ); if( error ) return error; /* Place PC on the stack */ stack = &( (*ptr)[ libspectrum_snap_sp( snap ) - 0x4000 - 2 ] ); libspectrum_write_word( &stack, libspectrum_snap_pc( snap ) ); *ptr += 0xc000; /* Store the new value of SP */ sp = *buffer + SNA_OFFSET_SP; libspectrum_write_word( &sp, libspectrum_snap_sp( snap ) - 2 ); return LIBSPECTRUM_ERROR_NONE; }
// erase first page, removing any interrupt table hooks the bootloader added when // upgrade was uploaded void secure_interrupt_vector_table(void) { uint16_t table[SPM_PAGESIZE / 2]; load_table(0, table); // wipe out any interrupt hooks the bootloader rewrote int i = 0; while (i < SPM_PAGESIZE / 2) { table[0] = 0xFFFF; i++; } erase_page(0); write_page(0, table); }
static unsigned take_phys_page(unsigned virt_page) { unsigned page; /* Page to be replaced. */ coremap_entry_t *coremap_entry; page_table_entry_t *swap_entry; page = (*replace)(); /*printf("\t%x\n", page);*/ // I renamed ram_entry to coremap_entry: coremap_entry = &coremap[page]; // "page" is the page in RAM we want to replace, // and coremap_entry->page is the same page but on swap. swap_entry = &page_table[virt_page]; // swap_entry->page is the page we want to get, // now (probably) on swap. We want to write this page to "page". if (coremap_entry->owner != NULL) { if (coremap_entry->owner->modified) { if (!coremap_entry->owner->ondisk) { coremap_entry->page = new_swap_page(); coremap_entry->owner->ondisk = 1; } write_page(page, coremap_entry->page); coremap_entry->owner->modified = 0; } coremap_entry->owner->inmemory = 0; coremap_entry->owner->page = coremap_entry->page; coremap_entry->owner->ondisk = 1; } // after this you can write over page, without loosing the old page. if(swap_entry->ondisk){ read_page(page, swap_entry->page); coremap_entry->page = swap_entry->page; } swap_entry->inmemory = 1; swap_entry->page = page; coremap_entry->owner = swap_entry; return page; }
void ows_spm() { uint8_t cmd = ows_recv(); uint16_t addr = ows_recv() << 8; addr |= ows_recv(); switch(cmd) { case 0x33: /* read program memory page */ ow_crc16_reset(); for(uint8_t i = 0; i < PGM_PAGE_SIZE; ++i) { uint8_t c = pgm_read_byte_near(addr++); ows_send(c); ow_crc16_update(c); } addr = ow_crc16_get(); ows_send(addr >> 8); ows_send(addr & 0xFF); break; case 0x3C: /* fill program memory page write buffer, return crc */ ow_crc16_reset(); for(uint8_t i = 0; i < PGM_PAGE_SIZE; i += 2) { uint16_t w; uint8_t c = ows_recv(); ow_crc16_update(c); w = c << 8; c = ows_recv(); w |= c; boot_page_fill(addr + i, w); } addr = ow_crc16_get(); ows_send(addr >> 8); ows_send(addr & 0xFF); break; case 0x5A: /* write page buffer */ write_page(addr); ows_send(0); ows_send(0); ows_send(0); break; case 0xA5: /* read eeprom page */ break; case 0xAA: /* write eeprom page */ break; case 0xC3: /* jump to address */ break; case 0xCC: /* read device id and page size */ break; } }