Exemplo n.º 1
0
static void advance_write_pointer(file_handle_t *handle)
{
    //first, read size and move ahead
    uint8_t size = 0;
    flash_read(handle->start + handle->write_offset, &size, 1);
    handle->write_offset += size + 2;
    handle->free_space -= size + 2;

    if (handle->write_offset >= FILE_SIZE)
        handle->write_offset = 0;

    //now, we need to check if we just moved onto a new page.
    if (!(handle->write_offset % FLASH_PAGE_SIZE))
    {
        //we did move into a new page. see if this page is free, and if so mark it and move forward
        //otherwise hang around and wait for page to erase
        uint8_t counter;
        flash_read(handle->start + handle->write_offset, &counter, 1);
        if (counter == 0xFF) //we can move in
        {
            counter = (0xFF << handle->write_count);
            ++handle->write_count;
            if (handle->write_count == 9) handle->write_count = 1;
            flash_write(handle->start + handle->write_offset, &counter, PAGE_COUNTER_SIZE);
            handle->write_offset += PAGE_COUNTER_SIZE; //skip the counter bytes
        }
    }
}
Exemplo n.º 2
0
void usart_dostuff() {
  if (flag_command_ready)
    handle_command();

  if (flag_read_flash) {
    bool_t verified = false;
    while (!verified) {
      flash_read(flash_addr);
      verified = flash_verify(flash_addr);
    }

    while (!verified) {
      _delay_ms(25);
      flash_read(flash_addr);
      verified = flash_verify(flash_addr);
    }

    flash_addr++;
    flag_read_flash = false;
  }

  if (flag_xmodem_next_packet) {
    prepare_packet();
    usart_send();
  }
}
Exemplo n.º 3
0
static uae_u32 REGPARAM2 blizzardf0_bget(uaecptr addr)
{
#ifdef JIT
	special_mem |= S_READ;
#endif
	uae_u8 v;

	regs.memory_waitstate_cycles += F0_WAITSTATES * 1;

	if (is_csmk3() || is_blizzardppc()) {
		if (flash_unlocked) {
			return flash_read(flashrom, addr);
		}
	} else if (is_csmk2()) {
		addr &= 65535;
		addr += 65536;
		return flash_read(flashrom, addr);
	} else if (is_csmk1()) {
		addr &= 65535;
		addr += 65536;
		return flash_read(flashrom, addr);
	}
	addr &= blizzardf0_bank.mask;
	v = blizzardf0_bank.baseaddr[addr];
	return v;
}
Exemplo n.º 4
0
static inline void move_to_next_cluster(fat_fs_t *fat, fat_fs_entry_t *f)
{
    unsigned req_sec;
    if (fat->fsif.fs_type == FS_TYPE_FAT16) {
        req_sec = fat->first_fat_sec + f->cur_clus * 2 / fat->bytes_per_sec;
        if (req_sec != fat->cached_sector) {
            if (flash_read(fat->flashif, req_sec,
                &fat->fat_cache, fat->bytes_per_sec) != FLASH_ERR_OK) {
                    fat->fsif.last_error = FS_ERR_IO;
                    return;
            }
            fat->cached_sector = req_sec;
        }
        memcpy(&f->cur_clus, &fat->fat_cache[f->cur_clus * 2 % fat->bytes_per_sec], 2);
    } else {
        req_sec = fat->first_fat_sec + f->cur_clus * 4 / fat->bytes_per_sec;
        if (req_sec != fat->cached_sector) {
            if (flash_read(fat->flashif, req_sec,
                &fat->fat_cache, fat->bytes_per_sec) != FLASH_ERR_OK) {
                    fat->fsif.last_error = FS_ERR_IO;
                    return;
            }
            fat->cached_sector = req_sec;
        }
        memcpy(&f->cur_clus, &fat->fat_cache[f->cur_clus * 4 % fat->bytes_per_sec], 4);
    }
    f->cur_sec = 0;
}
Exemplo n.º 5
0
Arquivo: main.c Projeto: eerimoq/simba
static int test_read_write(struct harness_t *harness_p)
{
    struct flash_driver_t drv;
    char name[] = "Kalle kula";
    char buf[16];
    uint32_t address;

    BTASSERT(flash_init(&drv, &flash_0_dev) == 0);

    /* Write and read over a page boundary. */
    address = (FLASH1_BEGIN + FLASH1_PAGE_SIZE - 2);

    BTASSERT(flash_write(&drv, address, name, sizeof(name)) == sizeof(name));

    memset(buf, 0, sizeof(buf));
    BTASSERT(flash_read(&drv, buf, address, sizeof(buf)) == sizeof(buf));

    BTASSERT(strcmp(name, buf) == 0);

    /* Write and read over a bank boundary. */
    address = (FLASH1_BEGIN - 2);

    BTASSERT(flash_write(&drv, address, name, sizeof(name)) == sizeof(name));

    memset(buf, 0, sizeof(buf));
    BTASSERT(flash_read(&drv, buf, address, sizeof(buf)) == sizeof(buf));

    BTASSERT(strcmp(name, buf) == 0);

    return (0);
}
Exemplo n.º 6
0
void  main(void)
{
	uint32	data32;
	uint16	data16;
	uint8	data8;
	
	flash_init();										//初始化flash
	
	flash_erase_sector(SECTOR_NUM);						//擦除扇区
														//写入flash数据前,需要先擦除对应的扇区(不然数据会乱)
											
	if( 0==flash_write(SECTOR_NUM,0,0x12345678) )		//写入数据到扇区,偏移地址为0,必须一次写入4字节
														//if是用来检测是否写入成功,写入成功了就读取
	{
		data32 = 	flash_read(SECTOR_NUM,0,uint32);	//读取4字节
		printf("一次读取32位的数据为:0x%08x\n",data32);
		
		data16 =	flash_read(SECTOR_NUM,0,uint16);	//读取2字节
		printf("一次读取16位的数据为:0x%04x\n",data16);
		
		data8  =	flash_read(SECTOR_NUM,0,uint8);		//读取1字节
		printf("一次读取8位的数据为:0x%02x\n",data8);
	}
	
    while(1);
}
void flash_ulm_read(int start, int cnt){
	
	int *pLUN_int;
	int *pUBN_int;
	int LUN_int;
	int UBN_int;
	int i;
	
	pLUN_int = &LUN_int;
	pUBN_int = &UBN_int;



	if((PAGE_per_UNIT - start%PAGE_per_UNIT) < cnt){

		flash_read(start, PAGE_per_UNIT - start%PAGE_per_UNIT);
		flash_read(start + PAGE_per_UNIT - start%PAGE_per_UNIT,
			cnt - PAGE_per_UNIT - start%PAGE_per_UNIT);
	}
	else{
		//LUN_CMT_function(start/PAGE_per_UNIT, pLUN_int);
		for(i=0; i<cnt; i++){
			UBN_CMT_function(start+i, pUBN_int);
			readcnt++;
			IO.read++;
		}
	}
}
Exemplo n.º 8
0
int boot_linux_from_flash(void)
{
    boot_img_hdr *hdr = (void*) raw_header;
    unsigned n;
    ptentry *p;
    unsigned offset = 0;
    const char *cmdline;

    if((p = flash_find_ptn("boot")) == 0) {
        cprintf("NO BOOT PARTITION\n");
        return -1;
    }

    if(flash_read(p, offset, raw_header, 2048)) {
        cprintf("CANNOT READ BOOT IMAGE HEADER\n");
        return -1;
    }
    offset += 2048;
    
    if(memcmp(hdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) {
        cprintf("INVALID BOOT IMAGE HEADER\n");
        return -1;
    }

    n = (hdr->kernel_size + (FLASH_PAGE_SIZE - 1)) & (~(FLASH_PAGE_SIZE - 1));
    if(flash_read(p, offset, (void*) hdr->kernel_addr, n)) {
        cprintf("CANNOT READ KERNEL IMAGE\n");
        return -1;
    }
    offset += n;

    n = (hdr->ramdisk_size + (FLASH_PAGE_SIZE - 1)) & (~(FLASH_PAGE_SIZE - 1));
    if(flash_read(p, offset, (void*) hdr->ramdisk_addr, n)) {
        cprintf("CANNOT READ RAMDISK IMAGE\n");
        return -1;
    }
    offset += n;
    
    dprintf("\nkernel  @ %x (%d bytes)\n", hdr->kernel_addr, hdr->kernel_size);
    dprintf("ramdisk @ %x (%d bytes)\n\n\n", hdr->ramdisk_addr, hdr->ramdisk_size);

    if(hdr->cmdline[0]) {
        cmdline = (char*) hdr->cmdline;
    } else {
        cmdline = board_cmdline();
        if(cmdline == 0) {
            cmdline = "mem=50M console=null";
        }
    }
    cprintf("cmdline = '%s'\n", cmdline);
    
    cprintf("\nBooting Linux\n");

    create_atags(ADDR_TAGS, cmdline,
                 hdr->ramdisk_addr, hdr->ramdisk_size);
    
    boot_linux(hdr->kernel_addr);
    return 0;
}
Exemplo n.º 9
0
// Find the first unused area of flash which is long enough
static bool
fis_find_free(CYG_ADDRESS *addr, unsigned long length)
{
#ifndef CYGDAT_REDBOOT_FIS_MAX_FREE_CHUNKS
    unsigned long *fis_ptr, *fis_end, flash_data;
    unsigned long *area_start;
    void *err_addr;

    // Do not search the area reserved for pre-RedBoot systems:
    fis_ptr = (unsigned long *)((CYG_ADDRESS)flash_start + 
                                CYGNUM_REDBOOT_FLASH_RESERVED_BASE + 
                                CYGBLD_REDBOOT_MIN_IMAGE_SIZE);
    fis_end = (unsigned long *)(CYG_ADDRESS)flash_end;
    area_start = fis_ptr;
    while (fis_ptr < fis_end) {
        flash_read(fis_ptr, &flash_data, sizeof(unsigned long), (void **)&err_addr);
        if (flash_data != (unsigned long)0xFFFFFFFF) {
            if (area_start != fis_ptr) {
                // Assume that this is something
                if ((fis_ptr-area_start) >= (length/sizeof(unsigned))) {
                    *addr = (CYG_ADDRESS)area_start;
                    return true;
                }
            }
            // Find next blank block
            area_start = fis_ptr;
            while (area_start < fis_end) {
                flash_read(area_start, &flash_data, sizeof(unsigned long), (void **)&err_addr);
                if (flash_data == (unsigned long)0xFFFFFFFF) {
                    break;
                }
                area_start += flash_block_size / sizeof(CYG_ADDRESS);
            }
            fis_ptr = area_start;
        } else {
            fis_ptr += flash_block_size / sizeof(CYG_ADDRESS);
        }
    }
    if (area_start != fis_ptr) {
        if ((fis_ptr-area_start) >= (length/sizeof(unsigned))) {
            *addr = (CYG_ADDRESS)area_start;
            return true;
        }
    }
    return false;
#else
    struct free_chunk chunks[CYGDAT_REDBOOT_FIS_MAX_FREE_CHUNKS];
    int idx, num_chunks;

    num_chunks = find_free(chunks);
    for (idx = 0;  idx < num_chunks;  idx++) {
        if ((chunks[idx].end - chunks[idx].start) >= length) {
            *addr = (CYG_ADDRESS)chunks[idx].start;
            return true;
        }
    }
    return false;
#endif
}
Exemplo n.º 10
0
Arquivo: main.c Projeto: eerimoq/simba
static int test_read_write(struct harness_t *harness_p)
{
    struct flash_driver_t drv;
    char buf[32];
    uintptr_t flash_address;
    uintptr_t ram_address;

    /* Aligned start address*/
    flash_address = ((uintptr_t)&__rom_size - 0x10000);
    ram_address = (uintptr_t)&buf[0];
    ram_address &= 0xfffffffc;

    BTASSERT(flash_init(&drv, &flash_0_dev) == 0);
    BTASSERT(flash_erase(&drv, flash_address, 0x10000) == 0);

    /* Read and write aligned in ROM and RAM. */
    strcpy((void *)ram_address, "1234");
    BTASSERT(flash_write(&drv, flash_address, (void *)ram_address, 5) == 5);
    memset(buf, 0, sizeof(buf));
    BTASSERT(flash_read(&drv, buf, flash_address, 5) == 5);
    BTASSERT(strcmp(buf, "1234") == 0);

    /* Read and write non-aligned in ROM and aligned RAM. One is added
       to the ram address to align the chunk reads. */
    strcpy((void *)ram_address, "67890123");
    flash_address += 5;
    BTASSERT(flash_write(&drv, flash_address, (void *)ram_address, 9) == 9);
    memset(buf, 0, sizeof(buf));
    BTASSERT(flash_read(&drv,
                        (uint32_t *)(ram_address + 1),
                        flash_address, 9) == 9);
    BTASSERT(strcmp((void *)(ram_address + 1), "67890123") == 0);

    /* Read and write aligned in ROM and non-aligned RAM. */
    ram_address++;
    strcpy((void *)ram_address, "abcdefghij");
    flash_address += 19; /* 5 + 19 = 24. */
    BTASSERT(flash_write(&drv, flash_address, (void *)ram_address, 11) == 11);
    memset(buf, 0, sizeof(buf));
    BTASSERT(flash_read(&drv,
                        (uint32_t *)ram_address,
                        flash_address, 11) == 11);
    BTASSERT(strcmp((void *)ram_address, "abcdefghij") == 0);

    /* Read and write 1 byte at non-aligned ROM address. */
    ram_address = (uintptr_t)&buf[0];
    strcpy((void *)ram_address, "");
    flash_address++;
    BTASSERT(flash_write(&drv, flash_address, (void *)ram_address, 1) == 1);
    memset(buf, 0, sizeof(buf));
    BTASSERT(flash_read(&drv,
                        (uint32_t *)ram_address,
                        flash_address, 1) == 1);
    BTASSERT(strcmp((void *)ram_address, "") == 0);

    return (0);
}
Exemplo n.º 11
0
/*
  load all data from a flash sector into mem_buffer
 */
bool AP_FlashStorage::load_sector(uint8_t sector)
{
    uint32_t ofs = sizeof(sector_header);
    while (ofs < flash_sector_size - sizeof(struct block_header)) {
        struct block_header header;
        if (!flash_read(sector, ofs, (uint8_t *)&header, sizeof(header))) {
            return false;
        }
        enum BlockState state = (enum BlockState)header.state;

        switch (state) {
        case BLOCK_STATE_AVAILABLE:
            // we've reached the end
            write_offset = ofs;
            return true;

        case BLOCK_STATE_WRITING: {
            /*
              we were interrupted while writing a block. We can't
              re-use the data in this block as it may have some bits
              that are not set to 1, so by flash rules can't be set to
              an arbitrary value. So we skip over this block, leaving
              a gap. The gap size is limited to (7+1)*8=64 bytes. That
              gap won't be recovered until we next do an erase of this
              sector
             */
            uint16_t block_nbytes = (header.num_blocks_minus_one+1)*block_size;
            ofs += block_nbytes + sizeof(header);
            break;
        }
            
        case BLOCK_STATE_VALID: {
            uint16_t block_nbytes = (header.num_blocks_minus_one+1)*block_size;
            uint16_t block_ofs = header.block_num*block_size;
            if (block_ofs + block_nbytes > storage_size) {
                // the data is invalid (out of range)
                return false;
            }
            if (!flash_read(sector, ofs+sizeof(header), &mem_buffer[block_ofs], block_nbytes)) {
                return false;
            }
            //debug("read at %u for %u\n", block_ofs, block_nbytes);
            ofs += block_nbytes + sizeof(header);
            break;
        }
        default:
            // invalid state
            return false;
        }
    }
    write_offset = ofs;
    return true;
}
Exemplo n.º 12
0
uint8_t flash_store(void *data, uint8_t size, uint16_t pos)
{
	__disable_interrupt();
	uint8_t *Flash_ptr = (uint8_t *)FLASH_ADR_START;
	uint8_t seg_store[FLASH_SEG_SIZE];
	register uint8_t i = 0;

	Flash_ptr = (uint8_t *)pos;

	pos -= FLASH_ADR_START;

	switch(pos / FLASH_SEG_SIZE) {
		case 0:
			flash_read(seg_store, (uint8_t)FLASH_SEG_SIZE, FLASH_ADR_START);
			break;
		case 1:
			flash_read(seg_store, (uint8_t)FLASH_SEG_SIZE, FLASH_ADR_START + FLASH_SEG_SIZE);
			break;
		case 2:
			flash_read(seg_store, (uint8_t)FLASH_SEG_SIZE, FLASH_ADR_START + 2 * FLASH_SEG_SIZE);
			break;
		default:
			return 0xFE;
	}

	pos %= FLASH_SEG_SIZE;
	if(size + pos > FLASH_SEG_SIZE) {
		return 0xFF;
	}

	memcpy(seg_store + pos, data, size);

	FCTL1 = FWKEY + ERASE; // Set Erase bit
	FCTL3 = FWKEY; // Clear Lock bit
	*Flash_ptr = 0; // Dummy write to erase Flash segment
	Flash_ptr -= pos;

	FCTL1 = FWKEY + WRT;            	// Set WRT bit for write operation
	//FCTL3 = FWKEY;                           	// Clear Lock bit

	for(i = 0; i < (uint8_t)FLASH_SEG_SIZE; i++) {
		Flash_ptr[i] = seg_store[i];		// Write value to flash
	}

	FCTL1 = FWKEY;					// Clear WRT bit
	FCTL3 = FWKEY + LOCK;                    	// Set LOCK bit

	__enable_interrupt();

	return 0;
}
Exemplo n.º 13
0
static void
fis_free(int argc, char *argv[])
{
#ifndef CYGDAT_REDBOOT_FIS_MAX_FREE_CHUNKS
    unsigned long *fis_ptr, *fis_end, flash_data;
    unsigned long *area_start;
    void *err_addr;

    // Do not search the area reserved for pre-RedBoot systems:
    fis_ptr = (unsigned long *)((CYG_ADDRESS)flash_start + 
                                CYGNUM_REDBOOT_FLASH_RESERVED_BASE + 
                                CYGBLD_REDBOOT_MIN_IMAGE_SIZE);
    fis_end = (unsigned long *)(CYG_ADDRESS)flash_end;
    area_start = fis_ptr;
    while (fis_ptr < fis_end) {
        flash_read(fis_ptr, &flash_data, sizeof(unsigned long), (void **)&err_addr);
        if (flash_data != (unsigned long)0xFFFFFFFF) {
            if (area_start != fis_ptr) {
                // Assume that this is something
                diag_printf("  0x%08lX .. 0x%08lX\n",
                            (CYG_ADDRESS)area_start, (CYG_ADDRESS)fis_ptr);
            }
            // Find next blank block
            area_start = fis_ptr;
            while (area_start < fis_end) {
                flash_read(area_start, &flash_data, sizeof(unsigned long), (void **)&err_addr);
                if (flash_data == (unsigned long)0xFFFFFFFF) {
                    break;
                }
                area_start += flash_block_size / sizeof(CYG_ADDRESS);
            }
            fis_ptr = area_start;
        } else {
            fis_ptr += flash_block_size / sizeof(CYG_ADDRESS);
        }
    }
    if (area_start != fis_ptr) {
        diag_printf("  0x%08lX .. 0x%08lX\n", 
                    (CYG_ADDRESS)area_start, (CYG_ADDRESS)fis_ptr);
    }
#else
    struct free_chunk chunks[CYGDAT_REDBOOT_FIS_MAX_FREE_CHUNKS];
    int idx, num_chunks;

    num_chunks = find_free(chunks);
    for (idx = 0;  idx < num_chunks;  idx++) {
        diag_printf("  0x%08lX .. 0x%08lX\n", chunks[idx].start, chunks[idx].end);
    }
#endif
}
Exemplo n.º 14
0
const SectionIndex *index_from_fmap(const FmapArea *area)
{
	if (area->size < sizeof(uint32_t)) {
		printf("FMAP section too small.\n");
		return NULL;
	}
	SectionIndex *index = flash_read(area->offset, sizeof(uint32_t));

	uint32_t index_size = (index->count * 2 + 1) * sizeof(uint32_t);
	if (area->size < index_size) {
		printf("FMAP section too small.\n");
		return NULL;
	}
	return flash_read(area->offset, index_size);
}
Exemplo n.º 15
0
/**
 * Copy backup area bootloader to bootloader entry.
 *
 * @param bl_addr bootloader entry address
 * @param bl_size bootloader size
 *
 * @return result
 */
FlashErrCode flash_copy_bl_from_bak(uint32_t bl_addr, size_t bl_size) {
    size_t cur_size;
    uint32_t bl_cur_addr, bak_cur_addr;
    FlashErrCode result = FLASH_NO_ERR;
    /* 32 words buffer */
    uint32_t buff[32];

    /* cycle copy data by 32bytes buffer */
    for (cur_size = 0; cur_size < bl_size; cur_size += sizeof(buff)) {
        bl_cur_addr = bl_addr + cur_size;
        bak_cur_addr = get_bak_app_start_addr() + cur_size;
        flash_read(bak_cur_addr, buff, sizeof(buff));
        result = flash_write(bl_cur_addr, buff, sizeof(buff));
        if (result != FLASH_NO_ERR) {
            break;
        }
    }

    switch (result) {
    case FLASH_NO_ERR: {
        FLASH_INFO("Write data to bootloader entry OK.\n");
        break;
    }
    case FLASH_WRITE_ERR: {
        FLASH_INFO("Warning: Write data to bootloader entry fault!\n");
        break;
    }
    }

    return result;
}
Exemplo n.º 16
0
/**
 * Copy backup area application to application entry.
 *
 * @param user_app_addr application entry address
 * @param app_size application size
 *
 * @return result
 */
FlashErrCode flash_copy_app_from_bak(uint32_t user_app_addr, size_t app_size) {
    size_t cur_size;
    uint32_t app_cur_addr, bak_cur_addr;
    FlashErrCode result = FLASH_NO_ERR;
    /* 32 words size buffer */
    uint32_t buff[32];

    /* cycle copy data */
    for (cur_size = 0; cur_size < app_size; cur_size += sizeof(buff)) {
        app_cur_addr = user_app_addr + cur_size;
        bak_cur_addr = get_bak_app_start_addr() + cur_size;
        flash_read(bak_cur_addr, buff, sizeof(buff));
        result = flash_write(app_cur_addr, buff, sizeof(buff));
        if (result != FLASH_NO_ERR) {
            break;
        }
    }

    switch (result) {
    case FLASH_NO_ERR: {
        FLASH_INFO("Write data to application entry OK.\n");
        break;
    }
    case FLASH_WRITE_ERR: {
        FLASH_INFO("Warning: Write data to application entry fault!\n");
        break;
    }
    }

    return result;
}
Exemplo n.º 17
0
uint8_t radio_store_settings(uint8_t freq, uint8_t volume)
{
	uint16_t tmp_frequency = 0;
	uint8_t tmp_volume = 0;
	RADIO_SETTINGS tmp_settings;
	flash_read(&tmp_settings, sizeof(tmp_settings), RADIO_SETTINGS_STORE_ADR);
	if(freq != RADIO_STORE_VALUE) {
		tmp_frequency = radio.settings.frequency;
		radio.settings.frequency = tmp_settings.frequency;
	}
	if(volume != RADIO_STORE_VALUE) {
		tmp_volume = radio.settings.volume;
		radio.settings.volume = tmp_settings.volume;
	}

	flash_store(&(radio.settings), sizeof(radio.settings), RADIO_SETTINGS_STORE_ADR);

	if(freq != RADIO_STORE_VALUE) {
		radio.settings.frequency = tmp_frequency;
	}

	if(volume != RADIO_STORE_VALUE) {
		radio.settings.volume = tmp_volume;
	}
	return 0;
}
Exemplo n.º 18
0
//-----------------------------------------------------------------------------
// rom_loaded()
//-----------------------------------------------------------------------------
void rom_loaded(void)
{
	int i;

	ngpc_rom.orig_data = (uint8 *)malloc(ngpc_rom.length);
	memcpy(ngpc_rom.orig_data, ngpc_rom.data, ngpc_rom.length);

	//Extract the header
	rom_header = (RomHeader*)(ngpc_rom.data);

	//Rom Name
	for(i = 0; i < 12; i++)
	{
		if (rom_header->name[i] >= 32 && rom_header->name[i] < 128)
			ngpc_rom.name[i] = rom_header->name[i];
		else
			ngpc_rom.name[i] = ' ';
	}
	ngpc_rom.name[i] = 0;

	rom_hack();	//Apply a hack if required!

	rom_display_header();

	flash_read();
}
Exemplo n.º 19
0
void board_seq_update(u32_t seq)
{
	u32_t loc, seq_map;
	int err;

	if (seq % SEQ_PER_BIT) {
		return;
	}

	loc = (SEQ_PAGE + ((seq / SEQ_PER_BIT) / 32));

	err = flash_read(nvm, loc, &seq_map, sizeof(seq_map));
	if (err) {
		printk("flash_read err %d\n", err);
		return;
	}

	seq_map >>= 1;

	flash_write_protection_set(nvm, false);
	err = flash_write(nvm, loc, &seq_map, sizeof(seq_map));
	flash_write_protection_set(nvm, true);
	if (err) {
		printk("flash_write err %d\n", err);
	}
}
Exemplo n.º 20
0
/*
 * copy some buffer inside the flash to another palce inside the flash
 *
 */
 static FS_STATUS CopyDataInsideFlash(uint16_t srcAddr,uint16_t srcSize,uint16_t destAddr)
 {
     uint16_t bytesToRead;
     uint8_t data[FLASH_BYTES_PER_TRANSACTION];
     FS_STATUS status = FS_SUCCESS;

     //sinec the flash can read/write in FLASH_BYTES_PER_TRANSACTION chuncks, do it this size
     while (srcSize > 0)
     {
         bytesToRead = (srcSize > FLASH_BYTES_PER_TRANSACTION)?FLASH_BYTES_PER_TRANSACTION:srcSize;

         if (flash_read(srcAddr,bytesToRead,data) != FS_SUCCESS)
         {
             status = FAILURE_ACCESSING_FLASH;
             break;
         }

         if (flash_write(destAddr,bytesToRead,data) != FS_SUCCESS)
         {
             status = FAILURE_ACCESSING_FLASH;
             break;
         }

         srcAddr+=bytesToRead;
         destAddr+=bytesToRead;
         srcSize-=bytesToRead;
     }

     return status;
 }
Exemplo n.º 21
0
/* Load Flash contents into DDR. 
   
   Input:
      start    Image start address on flash.
      size     Image size.
 */
void load(uint start, uint size) {

   uint step;           // Progress bar step size.
   uint cval;           // Current progress value.
   
   cls();

   // User Upload Menu.
   drawWindow(&wDDRUpload);

   // Upload Initialization.
   pbUpload.val = 0;   
   drawProgressBar(&wDDRUpload, &pbUpload);
   
   step = size / 64;
   cval = step;
   
   // Copy flash data to DDR2 memory.
   // NOTE: Missing bytes, if binary file is not 4 bytes aligned.
   for(uint i=0; i < (size / 4); i++) {
   
      DDR_ADDRESS[i] = flash_read(i + start);
      
      // Update status bar.
      if(i == cval) {
         pbUpload.val++;
         drawProgressBar(&wUpload, &pbUpload);
         cval += step;
      }
   }    
}
Exemplo n.º 22
0
int main (int argc, char const* argv[])
{
   std::cout << "******************************\n";
   std::cout << "*                            *\n";
   std::cout << "*  Quantracker Air OSD       *\n";
   std::cout << "*  Params setup v1.1         *\n";
   std::cout << "*  Copyright (C) Andy Little *\n";
   std::cout << "*  www.zoomworks.org         *\n";
   std::cout << "*  Jul 2015                  *\n";
   std::cout << "*                            *\n";
   std::cout << "******************************\n\n";
   
   if (argc != 5) {
      std::cout << "usage " << argv[0] << " -read|-write <filename> -port <portname>\n";
      return EXIT_FAILURE;
   }

   if (!strncmp (argv[1], "-read", 6)) {
      
      return flash_read(argv[2],argv[4]);
   }

   if ( (!strncmp (argv[1], "-write", 7)) && ( !strncmp (argv[3], "-port",6) ) ){

      return flash_write (argv[2],argv[4]);
   } 
}
Exemplo n.º 23
0
void DataDownload(DownloadAction action) {
	if ((DeviceState == downloading)) {

		uint8_t packetSize;
		uint32_t offset;
		uint32_t partoffset;
		SendBuffer[0] = 0x01;
		SendBuffer[1] = Download;
		SendBuffer[2] = downPacketCurrent >> 24;
		SendBuffer[3] = downPacketCurrent >> 16;
		SendBuffer[4] = downPacketCurrent >> 8;
		SendBuffer[5] = downPacketCurrent;
		if (downPacketCurrent == downPacketTotal - 1) {
			packetSize = downSizeOfLastPacket;
		} else {
			packetSize = 14;
		}
		for (uint8_t x = 0; x < packetSize; ++x) {
			partoffset = (downPacketCurrent * 14 * 4) + (x * 4);
			offset = baseOfAdressType(downType) + partoffset;
			if (!flash_read(SendBuffer + (6 + x * 4), offset,
					currentProgrammingDestination)) {
				DeviceState = Last_operation_failed;
			}
		}
		downPacketCurrent = downPacketCurrent + 1;
		if (downPacketCurrent > downPacketTotal - 1) {
			DeviceState = Last_operation_Success;
			Aditionals = (uint32_t) Download;
		}
		sendData(SendBuffer + 1, 63);
	}
Exemplo n.º 24
0
//
// Little endian mode requires some trickery due to the way the IXP4xx
// AHB and expansion busses work.
//
int
hal_flash_read(void *addr, void *data, int len, void **err)
{
    int retval;

    retval = flash_read(addr, data, len, err);

    if (0
#if (CYG_BYTEORDER == CYG_LSBFIRST) && defined(CYGOPT_REDBOOT_FLASH_BYTEORDER_MSBFIRST)
#ifdef CYGOPT_REDBOOT_FIS
	|| addr == fis_addr
#endif
#ifdef CYGSEM_REDBOOT_FLASH_CONFIG
	|| addr == cfg_base
#endif
#endif
	) {
	cyg_uint32 *p;
	int i;

	for (i = 0, p = data; i < len; i += 4, ++p)
	    *p = CYG_SWAP32(*p);
    }
    return retval;
}
Exemplo n.º 25
0
/*
 * get the next valid sector descriptor inside a given EraseUnit
 * pPrevActualSectorIndex - when calling the function this holds the last actual SectorDescriptor index we processed or 0 if we want the
 *							first SectorDescriptor. when returning this holds the actual SectorDescriptor index of the next vaild sector 
 *							descriptor
 * assumptions: the given erase unit has more SectorDescriptors (i.e. pPrevActualSectorIndex < the last actual sector descriptor index)
 */
static FS_STATUS getNextValidSectorDescriptor(uint8_t euIndex,uint16_t* pNextActualSectorIndex,SectorDescriptor* pSecDesc)
{

   uint16_t baseAddress = FLASH_BLOCK_SIZE*euIndex,secDescOffset = sizeof(EraseUnitHeader) ,sectorIndexInc = 0;
   
   //advance the index if we got relevant value value
   if (pNextActualSectorIndex != NULL && *pNextActualSectorIndex > 0)
   {
      secDescOffset += sizeof(SectorDescriptor)*(*pNextActualSectorIndex);
       //++sectorIndexInc;
   }

   do
   {
      flash_read(baseAddress + secDescOffset,sizeof(SectorDescriptor),(uint8_t*)pSecDesc);
      secDescOffset+=sizeof(SectorDescriptor);
      ++sectorIndexInc;
   }while(pSecDesc->metadata.bits.validDesc != 0 || pSecDesc->metadata.bits.obsoleteDes == 0 && secDescOffset + sizeof(SectorDescriptor) < FLASH_BLOCK_SIZE);

   //cancle last increment, since we want the actual index of the current file and not the next
   --sectorIndexInc;


   //updtae the actual index if such been provided
   if (pNextActualSectorIndex != NULL)
   {
      *pNextActualSectorIndex+=(sectorIndexInc + 1);
   }

   return FS_SUCCESS;
}
Exemplo n.º 26
0
int read_update_header_for_bootloader(struct update_header *header)
{
	struct ptentry *ptn;
	struct ptable *ptable;
	unsigned offset = 0;
	unsigned pagesize = flash_page_size();

	ptable = flash_get_ptable();
	if (ptable == NULL) {
		dprintf(CRITICAL, "ERROR: Partition table not found\n");
		return -1;
	}
	ptn = ptable_find(ptable, "cache");

	if (ptn == NULL) {
		dprintf(CRITICAL, "ERROR: No cache partition found\n");
		return -1;
	}
	if (flash_read(ptn, offset, buf, pagesize)) {
		dprintf(CRITICAL, "ERROR: Cannot read recovery_header\n");
		return -1;
	}
	memcpy(header, buf, sizeof(*header));

	if (strncmp((char *) header->MAGIC, UPDATE_MAGIC, UPDATE_MAGIC_SIZE))
	{
		return -1;
	}
	return 0;
}
Exemplo n.º 27
0
int get_recovery_message(struct recovery_message *out)
{
	struct ptentry *ptn;
	struct ptable *ptable;
	unsigned offset = 0;
	unsigned pagesize = flash_page_size();

	ptable = flash_get_ptable();

	if (ptable == NULL) {
		dprintf(CRITICAL, "ERROR: Partition table not found\n");
		return -1;
	}
	ptn = ptable_find(ptable, "misc");

	if (ptn == NULL) {
		dprintf(CRITICAL, "ERROR: No misc partition found\n");
		return -1;
	}

	offset += (pagesize * MISC_COMMAND_PAGE);
	if (flash_read(ptn, offset, (void *) buf, pagesize)) {
		dprintf(CRITICAL, "ERROR: Cannot read recovery_header\n");
		return -1;
	}
	memcpy(out, buf, sizeof(*out));
	return 0;
}
Exemplo n.º 28
0
/* TODO: Cleaner generic version.
   Quick and dirty implementation of an memory matrix view. Shows the next
   'NUM_OF_WORDS' starting at location 'adr' of the Flash and the DDR memory
   device. */
void show_memory_contents(uint adr) {

   uchar b;
   uchar t;

   b = 0; t = 0;
   for(uint i=adr; i < adr + NUM_OF_WORDS; i++) {

      if(b == 0) {
         gotoxy(6, 4 + t++);
         printf("$y%x:$w ", FLASH_MEMORY + (i << 2));
      }
      printf("%x ", flash_read(i));
      if(b++ == 6) b = 0;
   }

   b = 0; t = 0;
   for(uint i=adr; i < adr + NUM_OF_WORDS; i++) {

      if(b == 0) {
         gotoxy(6, 20 + t++);
         printf("$y%x:$w ", DDR_ADDRESS + i);
      }
      printf("%x ", DDR_ADDRESS[i]);
      if(b++ == 6) b = 0;
   }
}
Exemplo n.º 29
0
static Cyg_ErrNo
flashiodev_bread( cyg_io_handle_t handle, void *buf, cyg_uint32 *len,
                  cyg_uint32 pos)
{
	struct cyg_devtab_entry *tab = (struct cyg_devtab_entry *)handle;
	struct flashiodev_priv_t *dev = (struct flashiodev_priv_t *)tab->priv;

	char *startpos = dev->start + pos;
        void *erraddr;
        Cyg_ErrNo err = ENOERR;
        

#ifdef CYGPKG_INFRA_DEBUG // don't bother checking this all the time
    char *endpos = startpos + *len - 1;
    char *flashend = MIN( (char *)flash_info.end - 1, dev->end - 1);
    if ( startpos < dev->start )
        return -EINVAL;
    if ( endpos > flashend )
        return -EINVAL;
#endif
    
    err = flash_read( startpos,
                      (void *)buf, *len, &erraddr );

    if ( err )
        err = -EIO; // just something sane
    return err;
} // flashiodev_bread()
Exemplo n.º 30
0
void doFlash(){
	uint32_t addr = 0;
	uint16_t len   = (uintptr_t)&_bin_size;
	uint8_t * data = (uint8_t *)&_reloc_ep;
	lcdPrintln("Flashing");
	lcdPrint(IntToStr(len,6,0));
	lcdPrintln(" bytes");
	lcdDisplay();
	flash_random_write(addr, len, data);
	lcdPrintln("done.");
	lcdDisplay();
	flash_read(addr, len, &_app_start);
	uint16_t idx;
	int err=0;
	for (idx=0;idx<len;idx++){
		if ((&_app_start)[idx] != data[idx]){
			lcdPrint(IntToStr(idx,4,F_HEX));
			lcdPrint(": ");
			lcdPrint(IntToStr((&_app_start)[idx],2,F_HEX));
			lcdPrint("!=");
			lcdPrint(IntToStr(data[idx],2,F_HEX));
			lcdNl();
			err++;
			lcdDisplay();
		};
		if(err%4==1){
			getInputWait();
		};
	};

	getInputWait();
};