/* This function copies a new version of the bootloader into flash.  */
uint8_t hal_copy_bootloader(uint32_t addr_new_bootloader, uint32_t addr_old_bootloader)
/* This function copies a new version of the bootloader into flash.  */
uint8_t hal_copy_bootloader(uint32_t addr_new_bootloader, uint32_t addr_old_bootloader)
{
	uint8_t i = 0;
	uint8_t ul_result;
	uint32_t ul_page_offset = 0;
	uint8_t uc_page[BOOT_FLASH_PAGE_SIZE];
	hal_erase_Bootloader(addr_old_bootloader);
	for (i = 0; i < (BOOT_FIRMWARE_MAX_SIZE / BOOT_FLASH_PAGE_SIZE); i++) {
		ul_page_offset = i * BOOT_FLASH_PAGE_SIZE;
		memcpy(uc_page, (uint8_t *)(addr_new_bootloader + ul_page_offset),
				BOOT_FLASH_PAGE_SIZE);
		ul_result = flash_write(addr_old_bootloader + ul_page_offset,
				uc_page, BOOT_FLASH_PAGE_SIZE, 0);
	}
	return ul_result;
}