Esempio n. 1
0
uint8_t flashrom_erase(uint8_t *addr) {
    uint8_t sec = iap_get_sector((uint32_t) addr);
    unsigned intstate;
    
    if (sec == INVALID_ADDRESS) {
        DEBUG("Invalid address\n");
        return 0;
    }

    /* check sector */
	if (!blank_check_sector(sec, sec)) {
		DEBUG("Sector already blank!\n");
		return 1;
	}
	/* prepare sector */
    if (prepare_sectors(sec, sec)) {
		DEBUG("-- ERROR: PREPARE_SECTOR_FOR_WRITE_OPERATION --\n");
		return 0;
	}
    intstate = disableIRQ();
    /* erase sector */
	if (erase_sectors(sec, sec)) {
		DEBUG("-- ERROR: ERASE SECTOR --\n");
        restoreIRQ(intstate);
		return 0;
	}
    restoreIRQ(intstate);
    /* check again */
	if (blank_check_sector(sec, sec)) {
		DEBUG("-- ERROR: BLANK_CHECK_SECTOR\n");
		return 0;
	}
	DEBUG("Sector successfully erased.\n");
	return 1;
}
Esempio n. 2
0
/******************************************************************************
 * P U B L I C   F U N C T I O N S
 *****************************************************************************/
uint8_t	flashrom_write(uint8_t *dst, char *src, size_t size) {
	char err;
	unsigned intstate;
	uint8_t sec;
	
	//buffer_vic  = VICIntEnable;		// save interrupt enable
	//VICIntEnClr = 0xFFFFFFFF;		// clear vic
	
	sec = iap_get_sector((uint32_t) dst);
    if (sec == INVALID_ADDRESS) {
        DEBUG("Invalid address\n");
        return 0;
    }

    /* check sector */
	if(blank_check_sector(sec, sec) == SECTOR_NOT_BLANK) {
		DEBUG("Warning: Sector %i not blank\n", sec);	
	}

    /* prepare sector */
	err = prepare_sectors(sec, sec);
    if (err) {
		DEBUG("\n-- ERROR: PREPARE_SECTOR_FOR_WRITE_OPERATION: %u\n", err);
        /* set interrupts back and return */
//        VICIntEnable = buffer_vic;	
		return 0;
	}
    /* write flash */
	else {
        intstate = disableIRQ();
		err = copy_ram_to_flash((uint32_t) dst, (uint32_t) src, 256);
        restoreIRQ(intstate);
		if(err) {
			DEBUG("ERROR: COPY_RAM_TO_FLASH: %u\n", err);
            /* set interrupts back and return */
            restoreIRQ(intstate);
//            VICIntEnable = buffer_vic;	
			return 0;
		}
        /* check result */
		else {
			err = compare((uint32_t) dst, (uint32_t) src, 256);
            if (err) {
				DEBUG("ERROR: COMPARE: %i (at position %u)\n", err, iap_result[1]);
                /* set interrupts back and return */
//	            VICIntEnable = buffer_vic;
				return 0;
			}
			else
			{
				DEBUG("Data successfully written!\n");
                /* set interrupts back and return */
//	            VICIntEnable = buffer_vic;
				return 1;			
			}
		}
	}
}
Esempio n. 3
0
/******************************************************************************
 * P U B L I C   F U N C T I O N S
 *****************************************************************************/
uint8_t flashrom_write(uint8_t *dst, const uint8_t *src, size_t size)
{
    (void) size; /* unused */

    char err;
    uint8_t sec;

    sec = iap_get_sector((uint32_t) dst);

    if (sec == INVALID_ADDRESS) {
        DEBUG("Invalid address\n");
        return 0;
    }

    /* check sector */
    if (blank_check_sector(sec, sec) == SECTOR_NOT_BLANK) {
        DEBUG("Warning: Sector %i not blank\n", sec);
    }

    /* prepare sector */
    err = prepare_sectors(sec, sec);
    if (err) {
        DEBUG("\n-- ERROR: PREPARE_SECTOR_FOR_WRITE_OPERATION: %u\n", err);
        return 0;
    }

    /*  write flash */
    unsigned intstate = irq_disable();
    err = copy_ram_to_flash((uint32_t) dst, (uint32_t) src, 256);
    irq_restore(intstate);

    if (err) {
        DEBUG("ERROR: COPY_RAM_TO_FLASH: %u\n", err);
        /* set interrupts back and return */
        irq_restore(intstate);
        return 0;
    }
    /* check result */
    err = compare((uint32_t) dst, (uint32_t) src, 256);

    if (err) {
        DEBUG("ERROR: COMPARE: %i (at position %u)\n", err, iap_result[1]);
        return 0;
    }

    DEBUG("Data successfully written!\n");
    return 1;
}