Mykola Kostenok | 4d17df6 | 2017-09-01 09:56:45 +0300 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Script to burn entire 32MB of BMC SPI Flash |
| 4 | # |
| 5 | # Usage: |
| 6 | # a) Local: /run/initramfs/update_all <bmc-image-file> |
| 7 | # b) Remote: sshpass -p "<root-password>" ssh root@<ip> '/run/initramfs/update_all <bmc-image-file>' |
| 8 | # |
| 9 | # Assumptions: |
| 10 | # <bmc-image-file> is a 32MB file representing all partitions in BMC SPI Flash |
| 11 | # <bmc-image-file> exists on local filesystem |
| 12 | # /dev/mtd0 represents entire BMC SPI Flash device |
| 13 | # /dev/mtd5 is a JFFS2 filesystem (rwfs) partition |
| 14 | # /bsp/reset/bmc_upgrade is symlink pointing to proper sticky bit in CPLD |
| 15 | # |
| 16 | |
| 17 | if [ -f $1 ] |
| 18 | then |
| 19 | echo $0: Update BMC SPI Flash with $1 |
| 20 | else |
| 21 | echo $0: File $1 not found on target, exiting |
| 22 | exit |
| 23 | fi |
| 24 | |
| 25 | echo $0: Stopping system services |
| 26 | systemctl stop mlx_ipmid |
| 27 | |
| 28 | echo $0: Remounting rwfs "(/dev/mtd5)" as read-only |
| 29 | mount /dev/mtdblock5 /run/initramfs/rw -t jffs2 -o remount,ro |
| 30 | |
| 31 | echo $0: Unmounting rofs "(/dev/mtd4)" |
| 32 | umount /dev/mtdblock4 |
| 33 | |
| 34 | MAC=`fw_printenv ethaddr | sed -n "s/^ethaddr=//p"` |
| 35 | |
| 36 | echo $0: Burning SPI Flash "(/dev/mtd0)" with image "$1" |
| 37 | /usr/sbin/flashcp -v $1 /dev/mtd0 |
| 38 | |
| 39 | if [ -v $MAC ]; then |
| 40 | echo "MAC env variable not exist. Set eth0 MAC from eeprom." |
| 41 | MAC=`hexdump -n 6 -s 0xf0 -v -e '/1 "%02x:"' /sys/bus/i2c/devices/6-0055/eeprom`;MAC=${MAC::-1}; |
| 42 | else |
| 43 | echo "MAC env variable exist. Set eth0 MAC from env." |
| 44 | fi; |
| 45 | fw_setenv ethaddr $MAC |
| 46 | |
| 47 | echo $0: Setting bmc_upgrade sticky bit in CPLD |
| 48 | echo 1 > /bsp/reset/bmc_upgrade |
| 49 | |
| 50 | echo $0: Rebooting BMC |
| 51 | echo 0 > /bsp/reset/bmc_reset_soft |
| 52 | |
| 53 | |
| 54 | |