Ejemplo n.º 1
0
int32_t flash_program2(const uint32_t &addr, const uint32_t &len, const uint8_t *data)
{
	uint32_t i, laddr = addr;

	// add offset
	if (laddr>=FLASH_BEGIN && laddr<=FLASH_END)
		laddr += FLASH_OFFSET;

	// check range
	if (laddr<FLASH_BEGIN_B || laddr>FLASH_END_B || laddr+len>FLASH_END_B)
		return -1;

	// erase all sectors spanned by this segment
	for (i=FLASH_SECTOR_MASK(laddr); i<laddr+len; i+=FLASH_SECTOR_SIZE)
	{
		if (erase(i)<0)
			return -3;
	}
	
	if (flash_program(laddr, data, len)<0)
		return -2;

	// verify
	for (i=0; i<len; i++)
	{
		if (*(uint8_t *)(laddr+i) != data[i])
			return -4;
	}

	return 0;
}
Ejemplo n.º 2
0
int32_t prm_setChirp(const char *id, const uint32_t &valLen, const uint8_t *val)
{
	ParamRecord *rec;
	uint8_t *buf;
	uint32_t offset;
	void *sector;
	int32_t res = 0;

	rec = prm_find(id);

	if (rec==NULL)
	{
		// Good god this is an ugly hack.  But, creating parameters should only be handled from within the firmware, so that the correct
		// description can be inserted.  There may be other parameters like this, such that when these parameters are lost, we want to resave,
		// in which case, we should formalize this hack somehow.
		if (strncmp(id, "Signature label", 15)==0)
		{
			char desc[100];
			sprintf(desc, "@c Signature_Labels Sets the label for objects that match signature%s.", id+15);
			prm_add(id, 0, desc, val[0], val+1, END);
			return 0;
		}
		return -1;
	}

	buf = (uint8_t *)malloc(FLASH_SECTOR_SIZE);
   	
	if (buf==NULL)
		return -2;

	sector = (void *)FLASH_SECTOR_MASK((uint32_t)rec);
	memcpy(buf, sector, FLASH_SECTOR_SIZE);

	rec = prm_find(id, buf);

	if (rec==NULL)
	{
		res = -1;
		goto end;
	}

	offset = prm_getDataOffset(rec);	
	if (memcmp((uint8_t *)rec+offset, val, valLen)==0)
		goto end;
	memcpy((uint8_t *)rec+offset, val, valLen);
	 	
	rec->len = valLen;
	rec->crc = prm_crc(rec);
	
	flash_erase((uint32_t)sector, FLASH_SECTOR_SIZE); 
	flash_program((uint32_t)sector, buf, FLASH_SECTOR_SIZE);


end:
	free(buf); 	
	return res;
}
Ejemplo n.º 3
0
int32_t flash_erase(uint32_t addr, uint32_t len)
{
	SPIFIopers spifi;
	uint32_t i;

	// add offset
	if (addr>=FLASH_BEGIN && addr<=FLASH_END)
		addr += FLASH_OFFSET;

	memset((void *)&spifi, 0, sizeof(spifi));

	for (i=0; i<len; i+=FLASH_SECTOR_SIZE)
	{ 
		addr = FLASH_SECTOR_MASK(addr+i);
		spifi.dest = (char *)addr;
		spifi.length = FLASH_SECTOR_SIZE;
		spifi.scratch = NULL;
		spifi.options = S_VERIFY_ERASE;
		if (spifi_erase(&g_spifi, &spifi)) 
			return -1;
	}
	return 0;
}
Ejemplo n.º 4
0
int32_t prm_setChirp(const char *id, const uint32_t &valLen, const uint8_t *val)
{
	ParamRecord *rec;
	uint8_t *buf;
	uint32_t offset;
	void *sector;

	buf = (uint8_t *)malloc(FLASH_SECTOR_SIZE);

	if (buf==NULL)
		return -2;

	rec = prm_find(id);

	if (rec==NULL)
		return -1;

	sector = (void *)FLASH_SECTOR_MASK((uint32_t)rec);
	memcpy(buf, sector, FLASH_SECTOR_SIZE);

	rec = prm_find(id, buf);

	if (rec==NULL)
		return -1;

	offset = prm_getDataOffset(rec);	
	memcpy((uint8_t *)rec+offset, val, valLen);
	 	
	rec->len = valLen;
	rec->crc = prm_crc(rec);
	
	flash_erase((uint32_t)sector, FLASH_SECTOR_SIZE); 
	flash_program((uint32_t)sector, buf, FLASH_SECTOR_SIZE);

	free(buf); 	
	return 0;
}