/* Write a page of flash. Data block should not cross page boundary.  */
static bool IRAM spi_write_page(sdk_flashchip_t *flashchip, uint32_t dest_addr, uint8_t *buf, uint32_t size)
/* Write a page of flash. Data block should not cross page boundary.  */
static bool IRAM spi_write_page(sdk_flashchip_t *flashchip, uint32_t dest_addr, uint8_t *buf, uint32_t size)
{
    if (flashchip->page_size < size + (dest_addr % flashchip->page_size)) {
        return false;
    }
    if (size < 1) {
        return true;
    }
    while (size >= SPI_WRITE_MAX_SIZE) {
        spi_write_data(flashchip, dest_addr, buf, SPI_WRITE_MAX_SIZE);
        size -= SPI_WRITE_MAX_SIZE;
        dest_addr += SPI_WRITE_MAX_SIZE;
        buf += SPI_WRITE_MAX_SIZE;
        if (size < 1) {
            return true;
        }
    }
    spi_write_data(flashchip, dest_addr, buf, size);
    return true;
}