FreeBSD/sys/dev/cxgb/common/cxgb_t3_hw.c
/*
 *	t3_load_boot - download boot flash
 *	@adapter: the adapter
 *	@boot_data: the boot image to write
 *	@size: image size
 *
 *	Write the supplied boot image to the card's serial flash.
 *	The boot image has the following sections: a 28-byte header and the
 *	boot image.
 */
download boot flash
@adapter: the adapter
@boot_data: the boot image to write
@size: image size

Write the supplied boot image to the card's serial flash.
The boot image has the following sections: a 28-byte header and the
boot image.
download boot flash @adapter : the adapter @boot_data : the boot image to write @size : image size Write the supplied boot image to the card ' s serial flash . The boot image has the following sections : a 28 - byte header and the boot image .
int t3_load_boot(adapter_t *adapter, u8 *boot_data, unsigned int size)
{
	boot_header_t *header = (boot_header_t *)boot_data;
	int ret;
	unsigned int addr;
	unsigned int boot_sector = BOOT_FLASH_BOOT_ADDR >> 16;
	unsigned int boot_end = (BOOT_FLASH_BOOT_ADDR + size - 1) >> 16;
	if (size < BOOT_MIN_SIZE || size > BOOT_MAX_SIZE) {
		CH_ERR(adapter, "boot image too small/large\n");
		return -EFBIG;
	}
	if (le16_to_cpu(*(u16*)header->signature) != BOOT_SIGNATURE) {
		CH_ERR(adapter, "boot image missing signature\n");
		return -EINVAL;
	}
	if (header->length * BOOT_SIZE_INC != size) {
		CH_ERR(adapter, "boot image header length != image length\n");
		return -EINVAL;
	}
	ret = t3_flash_erase_sectors(adapter, boot_sector, boot_end);
	if (ret)
		goto out;
	for (addr = BOOT_FLASH_BOOT_ADDR; size; ) {
		unsigned int chunk_size = min(size, 256U);
		ret = t3_write_flash(adapter, addr, chunk_size, boot_data, 0);
		if (ret)
			goto out;
		addr += chunk_size;
		boot_data += chunk_size;
		size -= chunk_size;
	}
out:
	if (ret)
		CH_ERR(adapter, "boot image download failed, error %d\n", ret);
	return ret;
}
int t3_load_boot ( adapter_t * adapter , u8 * boot_data , unsigned int size ) { boot_header_t * header = ( boot_header_t * ) boot_data ; int ret ; unsigned int addr ; unsigned int boot_sector = BOOT_FLASH_BOOT_ADDR >> 16 ; unsigned int boot_end = ( BOOT_FLASH_BOOT_ADDR + size - 1 ) >> 16 ; if ( size < BOOT_MIN_SIZE || size > BOOT_MAX_SIZE ) { CH_ERR ( adapter , " \n " ) ; return - EFBIG ; } if ( le16_to_cpu ( * ( u16 * ) header -> signature ) != BOOT_SIGNATURE ) { CH_ERR ( adapter , " \n " ) ; return - EINVAL ; } if ( header -> length * BOOT_SIZE_INC != size ) { CH_ERR ( adapter , " \n " ) ; return - EINVAL ; } ret = t3_flash_erase_sectors ( adapter , boot_sector , boot_end ) ; if ( ret ) goto out ; for ( addr = BOOT_FLASH_BOOT_ADDR ; size ; ) { unsigned int chunk_size = min ( size , 256U ) ; ret = t3_write_flash ( adapter , addr , chunk_size , boot_data , 0 ) ; if ( ret ) goto out ; addr += chunk_size ; boot_data += chunk_size ; size -= chunk_size ; } out : if ( ret ) CH_ERR ( adapter , " \n " , ret ) ; return ret ; }
t3_load_boot - download boot flash
      @adapter: the adapter
      @boot_data: the boot image to write
      @size: image size
t3_load_boot - download boot flash @adapter : the adapter @boot_data : the boot image to write @size : image size
/*
	 * Perform some primitive sanity testing to avoid accidentally
	 * writing garbage over the boot sectors.  We ought to check for
	 * more but it's not worth it for now ...
	 */