/* Appends a number of bytes to a page in the internal Flash.  */
int32_t flash_append(struct flash_descriptor *flash, uint32_t dst_addr, uint8_t *buffer, uint32_t length)
/* Appends a number of bytes to a page in the internal Flash.  */
int32_t flash_append(struct flash_descriptor *flash, uint32_t dst_addr, uint8_t *buffer, uint32_t length)
{
	ASSERT(flash && buffer && length);
	uint32_t page_size   = _flash_get_page_size(&flash->dev);
	uint32_t total_pages = _flash_get_total_pages(&flash->dev);
	if ((dst_addr > page_size * total_pages) || (dst_addr + length > page_size * total_pages)) {
		return ERR_BAD_ADDRESS;
	}
	if (_flash_is_locked(&flash->dev, dst_addr)) {
		return ERR_DENIED;
	}
	_flash_append(&flash->dev, dst_addr, buffer, length);
	return ERR_NONE;
}