Exemplo n.º 1
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;
}
Exemplo n.º 2
0
int prm_add(const char *id, uint32_t flags, const char *desc, ...)
{
	char buf[PRM_MAX_LEN];
	int len;
    uint32_t freeLoc, offset=PRM_HEADER_LEN;
    va_list args;
	ParamRecord *rec = (ParamRecord *)buf;

	// if it already exists, 
	if (prm_find(id))
		return -2;

	memset((void *)rec, 0, PRM_MAX_LEN);

	strcpy((char *)rec+offset, id);
	offset += strlen(id) + 1;
	if (desc!=NULL)
	{
		strcpy((char *)rec+offset, desc);
		offset += strlen(desc) + 1;
	}
	else
	{
		*(char *)(rec+offset) = '\0';
	 	offset++;
	}

	// data section should be aligned to 4 bytes	
	ALIGN(offset, 4);

    va_start(args, desc);
    len = Chirp::vserialize(NULL, (uint8_t *)rec+offset, PRM_MAX_LEN-offset, &args);
    va_end(args);

	if (len<0)
		return -3;

	rec->flags = flags;
	rec->len = len;
	rec->crc = prm_crc(rec); 

	if ((freeLoc=prm_nextFree())==NULL)
		return -4;
	
	return flash_program(freeLoc, (uint8_t *)rec, len+prm_getDataOffset(rec));	
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
0
bool prm_verifyRecord(const ParamRecord *rec)
{	
	return prm_crc(rec)==rec->crc;
}