On write error, re-try writing into next block.

- if block write fails, try right away to wrote into next block
- before dumping log, flush log buffer to flash
- moved pre-write block preparation logic into flash_log_block_commit()
- minor changes