1. #!/bin/bash
  2.  
  3. ###################################################################
  4. # version of me
  5. __VERSION__="2011-07-15"
  6.  
  7. WORKING_DIR=".."
  8.  
  9. STANDBY="standby.fpg"
  10. SOC_RESCUE="soc-rescue.fpg"
  11. SPLASH_RESCUE="splash-rescue.raw"
  12. SOC="soc.fpg"
  13. BIOS="bios.bin"
  14. SPLASH="splash.raw"
  15. FLICKERNOISE="flickernoise.fbi"
  16. DATA="data.flash5.bin"
  17.  
  18. FJMEM="fjmem.bit"
  19.  
  20. MAC_DIR="BIOSMAC"
  21. BIOS_RESCUE="bios-rescue-without-CRC.bin"
  22. HEAD_TMP="head.tmp"
  23. MAC_TMP="mac.tmp"
  24. REMAIN_TMP="remain.tmp"
  25. BIOS_RESCUE_MAC="bios.$1$2.bin"
  26.  
  27. ###################################################################
  28. if [ $# != 2 ]; then
  29. echo "Usage:"
  30. echo " $0" "00" "17"
  31. echo " \$1 \$2 is the last two mac address with Hexadecimal"
  32. exit 1
  33. fi
  34.  
  35. ###################################################################
  36. mkdir -p ${MAC_DIR}
  37.  
  38. dd if=${BIOS_RESCUE} of=${MAC_DIR}/${HEAD_TMP} bs=8 count=28
  39. dd if=${BIOS_RESCUE} of=${MAC_DIR}/${REMAIN_TMP} bs=8 skip=29
  40.  
  41. printf "\\x$(printf "%x" 0x10)" > ${MAC_DIR}/${MAC_TMP}
  42. printf "\\x$(printf "%x" 0xe2)" >> ${MAC_DIR}/${MAC_TMP}
  43. printf "\\x$(printf "%x" 0xd5)" >> ${MAC_DIR}/${MAC_TMP}
  44. printf "\\x$(printf "%x" 0x00)" >> ${MAC_DIR}/${MAC_TMP}
  45.  
  46. printf "\\x$(printf "%x" 0x$1)" >> ${MAC_DIR}/${MAC_TMP}
  47. printf "\\x$(printf "%x" 0x$2)" >> ${MAC_DIR}/${MAC_TMP}
  48.  
  49. printf "\\x$(printf "%x" 0x00)" >> ${MAC_DIR}/${MAC_TMP}
  50. printf "\\x$(printf "%x" 0x00)" >> ${MAC_DIR}/${MAC_TMP}
  51.  
  52. cat ${MAC_DIR}/${HEAD_TMP} \
  53. ${MAC_DIR}/${MAC_TMP} \
  54. ${MAC_DIR}/${REMAIN_TMP} \
  55. > ${MAC_DIR}/${BIOS_RESCUE_MAC}
  56.  
  57. mkmmimg ${MAC_DIR}/${BIOS_RESCUE_MAC} write
  58.  
  59. ###################################################################
  60. #UrJtag option, if you don't want verify, enable the next line
  61. #NOVERIFY="noverify"
  62.  
  63. #UrJtag batch file
  64. BATCH_FILE=`mktemp`
  65. cat > ${BATCH_FILE}<<EOF
  66. cable milkymist
  67. detect
  68. instruction CFG_OUT 000100 BYPASS
  69. instruction CFG_IN 000101 BYPASS
  70. pld load ${FJMEM}
  71. initbus fjmem opcode=000010
  72. frequency 6000000
  73. detectflash 0
  74. endian big
  75.  
  76. flashmem 0x000000 ${WORKING_DIR}/${STANDBY} ${NOVERIFY}
  77.  
  78. flashmem 0x0A0000 ${WORKING_DIR}/${SOC_RESCUE} ${NOVERIFY}
  79. flashmem 0x240000 ${WORKING_DIR}/${SPLASH_RESCUE} ${NOVERIFY}
  80. flashmem 0x2E0000 ${WORKING_DIR}/${FLICKERNOISE} ${NOVERIFY}
  81.  
  82. flashmem 0x6E0000 ${WORKING_DIR}/${SOC} ${NOVERIFY}
  83. flashmem 0x860000 ${WORKING_DIR}/${BIOS} ${NOVERIFY}
  84. flashmem 0x880000 ${WORKING_DIR}/${SPLASH} ${NOVERIFY}
  85. flashmem 0x920000 ${WORKING_DIR}/${FLICKERNOISE} ${NOVERIFY}
  86.  
  87. flashmem 0x220000 ${MAC_DIR}/${BIOS_RESCUE_MAC} ${NOVERIFY}
  88.  
  89. eraseflash 0xD20000 151
  90. flashmem 0xD20000 ${DATA} ${NOVERIFY}
  91.  
  92. pld reconfigure
  93. EOF
  94.  
  95. jtag ${BATCH_FILE}
  96. if [ "$?" == "0" ]; then
  97. rm -f ${BATCH_FILE}
  98.  
  99. echo "-------------------------------------------------------------"
  100. echo "Your m1 was successfully reflashed. To boot the new software,"
  101. echo "Please now press the middle button of your Milkymist One."
  102. echo "-------------------------------------------------------------"
  103. else
  104. echo "there are errors when running jtag."
  105. fi