Pages

Tuesday, June 10, 2014

How to update the drive firmware in Linux



echo "Using firmware file $fwfile for upgrading $product on device $x…"

The process to download in Solid State Drive and Hard Disk Drive is a little different. In case of SDD we can burn the firmware in one command, but in case of HDD we need to write in a loop since there is a limitation of 0x80000 bytes on VFS module system call.



           if [ "$rev" != "$target_fw_ver" ]; then
               echo "Upgrading $disk_type firmware to version $target_fw_ver on $x i.e.$sg_dev..."
               if  [ "$disk_type" = "ssd" ]; then
                   sg_write_buffer --in=${fwfile} --mode=5 --id=0 $sg_dev
                   if [ $? -ne 0 ]; then
                       echo "Failed to upgrade SSD firmware on $x i.e.$sg_dev to version $target_fw_ver!" >&2
                       exit 1
                   fi
               else
                   # hdd firmware upgrade
                   bytes=`ls -l $fwfile | awk '{ print $5; }'`
                   start=0
       #length = 0x80000 Bytes
                   length=524288
                   while [ $start -lt $bytes ]; do
                       if let 'start+length>bytes'; then
                           let 'length=bytes-start'
                       fi
                       sg_write_buffer --in=$fwfile --skip=$start --offset=$start --length=$length --mode=0x7 --id=0 $sg_dev
                       if [ $? -ne 0 ]; then
                           echo "Failed to upgrade HDD firmware $x i.e.$sg_dev to version $target_fw_ver!" >&2
                           exit 1
                       fi
                       let start+=length
                   done
               fi