36 #include <sys/types.h>
44 #include <sys/times.h>
45 #include <sys/ioctl.h>
58 #define FW_UPDATE_RESTRICTED -14
59 #define UNSUPPORTED_FW_IMAGE -13
82 if (buf_p [0] ==
'S' ) {
95 dw2 = *(uint32_t *) &buf_p[4];
102 if ((dw2 == 0xFEAA0001) || (
SWAP_4BYTES(dw2) == 0xFEAA0001) ||
103 (dw2 == 0xFEAA0002) || (
SWAP_4BYTES(dw2) == 0xFEAA0002) ||
104 (dw2 == 0xFEAA0003) || (
SWAP_4BYTES(dw2) == 0xFEAA0003) )
107 }
else if ((dw2 == 0xFEAA0005) || (
SWAP_4BYTES(dw2) == 0xFEAA0005)) {
130 off_t ufi_dir_offset;
136 rc = stat(filename_p, &(fdesc_p->
st));
139 if (errno == ENOENT) {
140 printf(
"File %s not found\n", filename_p);
142 printf(
"File %s stat returns %s\n", filename_p, strerror(errno));
147 str_p = strrchr (filename_p,
'/');
158 if(strlen(str_p) < 127 ) {
159 strncpy (fdesc_p->
file_name, str_p, strlen(str_p));
161 printf (
"file name more than 128 chars\n");
168 if ((fdesc_p->
fd = open(filename_p, O_RDONLY)) < 0)
170 printf (
"open file failure, (%s)\n", strerror(errno));
185 printf(
"Malloc failure - (%s)\n", strerror(errno));
194 printf(
"Read failure %d, (%s)\n", rd, strerror(errno));
211 if (ufi_dir_offset < 0) {
212 printf(
"Unable to find UFI directory in UFI file.\n");
217 if(lseek(fdesc_p->
fd, ufi_dir_offset, SEEK_SET)) {
237 printf (
"Unsupported file type.\n");
246 lseek(fdesc_p->
fd, 0, SEEK_SET);
265 printf(
"\nUFI File Header:\n");
266 printf(
"Signature:\n");
267 for (i = 0; i < 52; i++)
274 printf(
"\nUFI Version: %08x\n", ufi_hdr_p->
ufi_version);
276 printf(
"Checksum : %08X\n", ufi_hdr_p->
checksum);
277 printf(
"Antidote: %08X\n", ufi_hdr_p->
antidote);
278 printf(
"Number of Images: %d\n", ufi_hdr_p->
numOfImgs);
280 printf(
"Target platform: ");
291 printf(
" (Skyhawk B0 only)\n");
293 printf(
" (Skyhawk B0 or B1 only)\n");
298 printf(
"End of UFI File Header dump\n");
317 printf(
"\nFlash Directory Header:\n");
319 printf(
"Number of Directory Entries: %d\n", flash_dir->
numImages);
321 printf(
"Flash Directory Entries:\n");
323 entry = &(flash_dir->
entries[i]);
327 if (entry->
opType == 0xffff) {
330 printf(
" Op Type: 0x%04x\n", entry->
opType);
332 printf(
" Offset: 0x%08x\n", entry->
offset);
333 printf(
" Image Size: 0x%08x\n", entry->
imageSize);
334 printf(
" Max Image Size: 0x%08x\n", entry->
maxSize);
335 printf(
" Checksum: 0x%08x\n", entry->
checkSum);
339 if (lseek(fdesc->
fd, offset , SEEK_SET) != offset) {
340 fprintf(stderr,
"couldn't seek to %ld\n", offset);
344 if (read(fdesc->
fd, &crc, 4) != 4) {
345 fprintf(stderr,
"Didn't get %d bytes on read\n", 4);
348 printf(
" CRC: 0x%08x\n", crc);
351 printf(
"\nEnd of Flash Directory Listing dump\n");
365 printf(
"\nFirmware Image Header:\n");
366 printf(
"Image ID: %08X\n", img_hdr_p->
imageId);
367 printf(
"Image Offset: %08X\n", img_hdr_p->
imageOffset);
368 printf(
"Image Length: %08X\n", img_hdr_p->
imageLength);
371 printf(
"End of Firmware Image Header dump\n");
405 if (device_p->
asic_id == 0x0410) {
411 if ((device_p->
asic_id == 0x0410) ||
412 (device_p->
asic_id == 0x0411)) {
422 if (asic_support_ok == 0) {
423 printf(
"Provided UFI is not supported on this device.\n");
424 printf(
"UFI version is 0x%02x, device version is 0x%04x\n",
439 for (entry_index=0; entry_index < ufi_dir->
numImages; entry_index++) {
444 buffer = malloc(largest_entry);
445 if (buffer == NULL) {
446 printf(
"Unable to allocate memory to hold FW image\n");
450 for (entry_index=0; entry_index < ufi_dir->
numImages; entry_index++) {
459 entry = &(ufi_dir->
entries[entry_index]);
462 if (op_type == 0xffff) {
467 if (op_type == 0xffff) {
468 printf(
"Invalid op_type for section %d\n", entry_index);
477 chip_crc = (buffer[3] << 24) | (buffer[2] << 16) | (buffer[1] << 8) | buffer[0];
481 if (lseek(fdsc_p->
fd, seek_offset , SEEK_SET) != seek_offset) {
482 fprintf(stderr,
"couldn't seek to %ld\n", seek_offset);
484 if (read(fdsc_p->
fd, &file_crc, 4) != 4) {
485 fprintf(stderr,
"Didn't get %d bytes on read\n", 4);
493 if (chip_crc == file_crc) {
503 printf(
"Seek failed to offset 0x%x\n", entry->
offset);
508 lval = read(fdsc_p->
fd, buffer, entry->
maxSize);
510 printf(
"Read failed in segment %d\n", entry_index);
511 printf(
"Expected %d bytes, got %ld\n", entry->
maxSize, lval);
520 if (entry->
opType == 0xffff) {
521 if ((entry_type == 0x30) ||
522 (entry_type == 0xc0) ||
523 (entry_type == 0xd0) ||
524 (entry_type == 0xd1) ||
525 (entry_type == 0xd2)) {
526 if ((rval == -2) || (rval == -3)) {
534 if ((rval == -2) || (rval == -3)) {
540 printf(
"This special firmware release requires the firmware download process\n");
541 printf(
"to be performed twice. You must reboot the system and download the same\n");
542 printf(
"firmware file again to complete the download process.\n");
549 printf(
"Firmware download failed, status is 0x%02x\n", -rval);
558 printf(
"Firmware download successful.\n");
559 printf(
"Reboot the system to activate the new firmware.\n");
579 struct stat stat_buf;
583 char change_status_text[20];
586 if (fstat(fdsc_p->
fd, &stat_buf) == -1) {
591 filesize = stat_buf.st_size;
593 buf = malloc(filesize);
599 if (read(fdsc_p->
fd, buf, filesize) != filesize) {
600 fprintf(stderr,
"Didn't get %ld bytes on read\n", filesize);
605 rval =
elxu_device_exec(device_p,
"/ocs/firmware_write", buf, filesize, change_status_text, 20);
607 printf(
"Firmware download successful.\n");
608 change_status = strtoul(change_status_text, NULL, 0);
609 switch (change_status) {
611 printf(
"No reset needed, new firmware is active.\n");
614 printf(
"A physical device reset (host reboot) is needed to activate the new firmware\n");
618 printf(
"Use the firmware-reset option to activate the new firmware.\n");
621 printf(
"Use port-migration or firmware-reset option to activate new firmware.\n");
622 printf(
"Note: With port-migration option, Only particular port will run with new FW\n");
625 printf(
"Unexected value for change_status: %d\n", change_status);
629 printf(
"This firmware version is not supported on this HBA model.\n");
631 printf(
"Download failed. Firmware does not meet minimum version requirement.\n");
658 if (strstr (fdsc_p->
file_name,
".grp") != NULL)
668 printf (
"The file %s has to be a .grp file type \n", fdsc_p->
file_name);
692 printf(
"Download starting\n");
695 printf(
"Firmware is Skyhawk UFI but device is not Skyhawk\n");
702 printf(
"Download starting\n");
705 printf(
"Firmware is Lancer FW file but device is not Lancer\n");
710 printf (
"Unknown HBA file type %d \n", fdsc_p->
hba_file_type);
715 printf (
"Download Failed\n");
718 printf(
"Download Success\n");
720 printf(
"NOTE: The interface just updated is a dual controller interface.\n");
721 printf(
" You may need to update the firmware on the second controller\n");
722 printf(
" to prevent issues on next boot.\n");
741 int failure_detected = 0;
742 uint8_t *file_sect_buf_p;
743 uint8_t *flash_sect_buf_p;
749 if (device_p == NULL || fdsc_p == NULL)
751 printf(
"Null pointer \n");
762 printf(
"FW file is not a UFI file\n");
766 printf (
"Verify firmware sections ... \n\n");
772 for (entry_index=0; entry_index < ufi_dir->
numImages; entry_index++) {
781 if ((file_sect_buf_p = malloc(largest_entry)) == NULL)
783 printf(
"Malloc failure (%s)\n", strerror(errno));
791 if ((flash_sect_buf_p = malloc(largest_entry)) == NULL)
793 printf(
"Malloc failure (%s)\n", strerror(errno));
795 free(file_sect_buf_p);
800 for (entry_index=0; entry_index < ufi_dir->
numImages; entry_index++) {
805 printf(
"%d: ", entry_index);
807 entry = &(ufi_dir->
entries[entry_index]);
810 if (op_type == 0xffff) {
814 if (op_type == 0xffff) {
815 printf(
"ERROR: Invalid op_type\n");
823 printf(
"ERROR: File seek failed\n");
828 lval = read(fdsc_p->
fd, file_sect_buf_p, entry->
maxSize);
830 printf(
"ERROR: File read failed\n");
838 printf (
"ERROR: Firmware read failed\n");;
846 if (memcmp(flash_sect_buf_p, file_sect_buf_p, entry->
maxSize) != 0)
848 printf(
"MISMATCH: Sections do not match\n");
860 if (failure_detected)
862 printf(
"Firmware verification failed - %d mismatched sections \n",
867 printf(
"Firmware verification was successful! \n");
869 zfree(file_sect_buf_p);
870 zfree(flash_sect_buf_p);
895 static int table[][2] = {
913 for (i=0; i<
sizeof(table) /
sizeof(table[0][0]) / 2; i++) {
914 if (table[i][0] == entry_type) {
922 #define PATTERN_SIZE 16
928 '*',
'*',
'*',
' ',
'S',
'E',
' ',
'F',
929 'L',
'A',
'S',
'\0',
'\0',
'\0',
'\0',
'\0'};
931 'H',
' ',
'D',
'I',
'R',
'E',
'C',
'T',
932 'O',
'R',
'Y',
' ',
'*',
'*',
'*',
' '};
935 lseek(fd, 0, SEEK_SET);
940 fprintf(stderr ,
"couldn't read %d bytes" ,
PATTERN_SIZE);
970 memset(&fileDesc, 0,
sizeof(fileDesc));
981 printf(
"Error Downloading FW\n");
994 printf (
"file-format command is only supported for UFI files.\n");
1003 printf(
"Firmware compare is not supported for Lancer/Prism Family Products.\n");
1010 printf(
"Error Verifying Firmware\n");
1015 printf(
"Firmware compare is only supported for UFI files.\n");
1019 printf (
"Invalid Action %d \n", action);
char * trimmed_string(uint8_t *string)
Trim trailing non-printable characters from a string.
int elxu_device_exec(elxu_device_t *device, char *name, void *arg_in, int arg_in_len, void *arg_out, int arg_out_len)
Execute a management function on a device.
static fFormat_t retrieve_file_format(uint8_t *buf_p, int len)
Returns the file type.
static void display_ufi_header(ufi_file_header_t *ufi_hdr_p)
Displays content of UFI file header structure.
#define UFI_FILE_HEADER_LENGTH
static int download_lancer_image(elxu_device_t *device_p, dwnld_file_desc_t *fdsc_p)
Lancer firmware download.
static void display_ufi_image_hdr(ufi_image_header_t *img_hdr_p)
Displays content of UFI image header structure.
void * zmalloc(uint32_t len)
Allocates and zeroes memory to be used.
int ufi_image_upload(elxu_device_t *device, uint32_t op_type, uint8_t *buffer, uint32_t bufferLength)
Upload UFI flash image component.
void zfree(void *p)
Frees memory that has been allocated.
int is_lancer(elxu_device_t *device_p)
Return true IFF the HBA is a Lancer.
static int file_handler_init(const char *filename_p, dwnld_file_desc_t *fdesc_p)
Initializes files descriptor structure.
#define UNSUPPORTED_FW_IMAGE
static int download_skyhawk_image(elxu_device_t *device_p, dwnld_file_desc_t *fdsc_p)
Skyhawk firmware download.
#define MGMT_FLASHROM_OPCODE_IMAGE_CRC
flash_directory_entry_t entries[NUM_FLASHDIR_ENTRIES]
uint8_t version[FLASH_DIRECTORY_ENTRY_VERSION_SIZE]
void display_ufi_flash_directory(dwnld_file_desc_t *fdesc)
Displays content of UFI flash directory header.
static int download_lancer_object_file(elxu_device_t *device_p, const char *object_p, dwnld_file_desc_t *fdsc_p)
Lancer file object.
int mbox_read_flashrom(elxu_device_t *device, uint32_t opcode, uint32_t optype, uint32_t offset, void *outbuf, uint32_t outbufLength)
Issue read flashrom mailbox command.
#define FW_UPDATE_RESTRICTED
char * decode_entry_type(uint32_t entry_type)
Return the name of a UFI entry type.
static uint16_t get_op_type(uint8_t entry_type)
Determine mailbox op_type from UFI entry_type.
int is_skyhawk(elxu_device_t *device_p)
Return true IFF the HBA is a Skyhawk.
flash_directory_t * ufi_flash_hdr
int ufi_image_download(elxu_device_t *device, uint32_t op_type, uint8_t *buffer, uint32_t bufferLength)
Download UFI flash image component.
static int hba_image_section_fw_verify(elxu_device_t *device_p, dwnld_file_desc_t *fdsc_p)
flash and file data comparison functionality.
int file_handler(elxu_device_t *device_p, char const *file_name_p, int action)
File manipulating functionality.
int is_prism(elxu_device_t *device_p)
Return true IFF the HBA is a Prism.
ufi_image_header_t img_hdr
static off_t find_ufi_dir(int fd)
static int download_handler(elxu_device_t *device_p, dwnld_file_desc_t *fdsc_p)
Firmware download.
int is_calypso(elxu_device_t *device_p)
Return true IFF the HBA is a Calypso.
ufi_file_header_t ufi_hdr