[PATCH u-boot-marvell 04/29] tools: kwboot: Refactor and fix writing buffer