Exemple #1
0
bool past_write_unit(past_t id, void *data, uint32_t length)
{
	bool success = false;
	if (!past_end_addr)
		past_end_addr = past_find_unit(PAST_UNITID_END);
	if (past_end_addr) {
		do {
			uint32_t old_addr = past_find_unit(id);
			PASTLOG(printf("Writing new unit at 0x%08x\n", (unsigned int) past_end_addr));
			if (SPI_FLASH_RESULT_OK != sdk_spi_flash_write(past_end_addr, (void*) &id, 4))
				break;
			if (SPI_FLASH_RESULT_OK != sdk_spi_flash_write(past_end_addr+4, (void*) &length, 4))
				break;
			if (SPI_FLASH_RESULT_OK != sdk_spi_flash_write(past_end_addr+8, data, length))
				break;
			past_end_addr += 8 + length;
			if (past_end_addr%4) past_end_addr += 4 - (past_end_addr%4); // Word align
			if (old_addr != 0) {
				uint32_t zero = 0;
				PASTLOG(printf("Erasing old unit at 0x%08x\n", (unsigned int) old_addr));
				if (SPI_FLASH_RESULT_OK != sdk_spi_flash_write(old_addr, (void*) &zero, 4))
					break;
			}
			success = true;
		} while(0);

	}
	return success;
}
Exemple #2
0
bool past_erase_unit(past_t id)
{
	uint32_t old_addr = past_find_unit(id);
	bool success = false;
	if (old_addr) {
		uint32_t zero = 0;
		if (SPI_FLASH_RESULT_OK == sdk_spi_flash_write(old_addr, (void*) &zero, 4))
			success = true;
	}
	return success;
}
Exemple #3
0
bool past_format(void)
{
	bool success = false;
	past_end_addr = 0;
	do {
		if (SPI_FLASH_RESULT_OK != sdk_spi_flash_erase_sector(PAST_SECTOR))
			break;
		if (SPI_FLASH_RESULT_OK != sdk_spi_flash_write(PAST_SECTOR*SPI_FLASH_SEC_SIZE, (void*) PAST_MAGIC, 4))
			break;
		past_end_addr = past_find_unit(PAST_UNITID_END);
		if (past_end_addr)
			success = true;
	} while(0);
	return success;
}
Exemple #4
0
void write_saved_phy_info(const sdk_phy_info_t *info)
{
    sdk_spi_flash_write(sdk_flashchip.chip_size - sdk_flashchip.sector_size * 4, (uint32_t *)info, sizeof(sdk_phy_info_t));
}