Werner's Miscellanea
Sign in or create your account | Project List | Help
Werner's Miscellanea Git Source Tree
Root/
| 1 | #!/bin/sh |
| 2 | # |
| 3 | # m1nor - Flash a file to M1 NOR partition selected by the file name |
| 4 | # |
| 5 | # Written 2011 by Werner Almesberger |
| 6 | # Copyright 2011 by Werner Almesberger |
| 7 | # |
| 8 | # This program is free software; you can redistribute it and/or modify |
| 9 | # it under the terms of the GNU General Public License as published by |
| 10 | # the Free Software Foundation; either version 2 of the License, or |
| 11 | # (at your option) any later version. |
| 12 | # |
| 13 | |
| 14 | # |
| 15 | # According to |
| 16 | # http://www.milkymist.org/wiki/index.php?title=Flashing_the_Milkymist_One#Flash_Memory_Distribution |
| 17 | # |
| 18 | # standby.fpg 0x0000 0000 640k |
| 19 | # soc-rescue.fpg 0x000A 0000 1536k |
| 20 | # bios-rescue.bin 0x0022 0000 128k |
| 21 | # splash-rescue.raw 0x0024 0000 640k |
| 22 | # flickernoise.fbi(res) 0x002E 0000 4096k |
| 23 | # soc.fpg 0x006E 0000 1536k alias: system.fpg |
| 24 | # bios.bin 0x0086 0000 128k |
| 25 | # splash.raw 0x0088 0000 640k |
| 26 | # flickernoise.fbi 0x0092 0000 4096k |
| 27 | # (data) 0x00D2 0000 19328k |
| 28 | # |
| 29 | |
| 30 | classify() |
| 31 | { |
| 32 | if [ ! -r "$1" ]; then |
| 33 | echo "$1: cannot read" 1>&2 |
| 34 | exit 1 |
| 35 | fi |
| 36 | |
| 37 | b=${1##*/} |
| 38 | if [ "${b#standby}" != "$b" ]; then off=0x0; ext=.fpg |
| 39 | elif [ "${b#soc-rescue}" != "$b" ]; then off=0xa0000; ext=.fpg |
| 40 | elif [ "${b#bios-rescue}" != "$b" ]; then off=0x220000; ext=.bin |
| 41 | elif [ "${b#splash-rescue}" != "$b" ]; then off=0x240000; ext=.raw |
| 42 | elif [ "${b#flickernoise-rescue}" != "$b" ]; then off=0x2e0000; ext=.fbi |
| 43 | elif [ "${b#soc}" != "$b" ]; then off=0x6e0000; ext=.fpg |
| 44 | elif [ "${b#system}" != "$b" ]; then off=0x6e0000; ext=.fpg |
| 45 | elif [ "${b#bios}" != "$b" ]; then off=0x860000; ext=.bin |
| 46 | elif [ "${b#splash}" != "$b" ]; then off=0x880000; ext=.raw |
| 47 | elif [ "${b#flickernoise}" != "$b" ]; then off=0x920000; ext=.fbi |
| 48 | elif [ "${b#data}" != "$b" ]; then off=0xd20000; ext= |
| 49 | else |
| 50 | echo "$1: unrecognized file name" 1>&2 |
| 51 | exit 1 |
| 52 | fi |
| 53 | |
| 54 | if [ "$ext" -a "${1%$ext}" = "$1" ]; then |
| 55 | echo "$1: extension mismatch (expected $ext)" 1>&2 |
| 56 | exit 1 |
| 57 | fi |
| 58 | } |
| 59 | |
| 60 | |
| 61 | if [ -z "$1" ]; then |
| 62 | echo "usage: $0 filename ..." 1>&2 |
| 63 | exit 1 |
| 64 | fi |
| 65 | |
| 66 | if [ "$FJMEM_BIT" ]; then |
| 67 | fjmem=$FJMEM_BIT |
| 68 | else |
| 69 | fjmem= |
| 70 | for n in $HOME/.qi/milkymist/*/fjmem.bit \ |
| 71 | $HOME/.qi/milkymist/*/*/fjmem.bit \ |
| 72 | /usr/local/share/milkymist/fjmem.bit \ |
| 73 | /usr/share/milkymist/fjmem.bit; do |
| 74 | if [ -r "$n" ]; then |
| 75 | fjmem="$n" |
| 76 | break |
| 77 | fi |
| 78 | done |
| 79 | if [ -z "$fjmem" ]; then |
| 80 | echo "cannot find fjmem.bit (consider setting FJMEM_BIT)" 1>&2 |
| 81 | exit 1 |
| 82 | fi |
| 83 | fi |
| 84 | |
| 85 | for n in "$@"; do |
| 86 | classify "$n" |
| 87 | done |
| 88 | |
| 89 | ( |
| 90 | cat <<EOF |
| 91 | cable milkymist |
| 92 | detect |
| 93 | instruction CFG_OUT 000100 BYPASS |
| 94 | instruction CFG_IN 000101 BYPASS |
| 95 | pld load "$fjmem" |
| 96 | initbus fjmem opcode=000010 |
| 97 | frequency 6000000 |
| 98 | detectflash 0 |
| 99 | endian big |
| 100 | EOF |
| 101 | for n in "$@"; do |
| 102 | classify "$n" |
| 103 | if [ "$off" == "0xd20000" ]; then |
| 104 | echo eraseflash 0xd20000 151 |
| 105 | fi |
| 106 | echo flashmem "$off" "$n" noverify |
| 107 | done |
| 108 | echo lockflash 0 55 |
| 109 | echo detectflash 0 |
| 110 | echo pld reconfigure |
| 111 | ) | jtag -q || exit |
| 112 | |
| 113 | # |
| 114 | # Fun fact: a direct flashmem-lockflash-pld reconfigure sequence leaves |
| 115 | # the FPGA in a weird state from which it can't boot out of standby, neither |
| 116 | # via JTAG (pld load ...) or by pressing the middle button. |
| 117 | # |
| 118 | # The only thing that seems to help is to run "detectflash" after the locking. |
| 119 | # (Tried "peek", "usleep", "pld readreg", ... without success.) |
| 120 | # |
| 121 | |
| 122 | # |
| 123 | # FIXME: the exit code of "jtag" doesn't indicate whether the session was |
| 124 | # successful. |
| 125 | # |
| 126 | |
| 127 | first=true |
| 128 | for n in "$@"; do |
| 129 | classify "$n" |
| 130 | echo -n "Flashed $n at offset $off" 1>&2 |
| 131 | if $first; then |
| 132 | echo " using $fjmem" 1>&2 |
| 133 | else |
| 134 | echo 1>&2 |
| 135 | fi |
| 136 | first=false |
| 137 | done |
| 138 |
Branches:
master
