| 219 | | This API which is implemented over I2C on address {{{0x5f}}} allows a user to do direct memory reads over the entirety of the accessible memory range ({{{0x0000-0xFFFF}}}). It is used by constructing a 16 bit address with the top byte (a.k.a. page) being set by writing to an undocumented register at address {{{0x20}}} offset {{{0x1f}}}. The bottom byte is then added on via standard I2C protocol. Memory writes are not supported with this API. In order to simplify the usage of this API, a bash script was created that will be posted on the wiki and/or given to FAE's to distribute as they see fit. The name of the script is {{{gsc_direct_mem.sh}}} and the contents are included below. |
| 220 | | |
| 221 | | [[CollapsibleStart(GSC Direct Memory Read Script)]] |
| 222 | | {{{#!bash |
| 223 | | #!/bin/bash |
| 224 | | |
| 225 | | [ "$#" -ne 2 ] && { |
| 226 | | echo "This script acts as a wrapper around I2C commands in order to do direct memory reads of the GSC." |
| 227 | | echo "It will output the i2c response in an i2cdump type format." |
| 228 | | echo |
| 229 | | echo "Usage: $0 <offset> <length>" |
| 230 | | echo |
| 231 | | echo "Example usage to read all 2000(0x7d0) peripheral register values:" |
| 232 | | echo " $0 0x100 0x7d0" |
| 233 | | exit 1 |
| 234 | | } |
| 235 | | |
| 236 | | # Store inputs |
| 237 | | BUS=0 |
| 238 | | ADDR=0x5e |
| 239 | | OFFSET=$1 |
| 240 | | LENGTH=$2 |
| 241 | | |
| 242 | | # Misc variables |
| 243 | | COUNT=0 |
| 244 | | PAGE=0 |
| 245 | | PRINTVAL=0x0000 |
| 246 | | REMAINDER=0 |
| 247 | | HIGH= |
| 248 | | RETURN= |
| 249 | | |
| 250 | | # Calculate initial page number based on passed in offset |
| 251 | | PAGE=$((OFFSET / 0x100)) |
| 252 | | OFFSET=$((OFFSET % 0x100)) |
| 253 | | |
| 254 | | echo " 0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef" |
| 255 | | while [[ $COUNT -ne $LENGTH ]]; do |
| 256 | | # Set the page number accordingly |
| 257 | | i2cset -f -y 0 0x20 0x16 $PAGE |
| 258 | | |
| 259 | | # Do either a full i2cdump or specify a range if bytes aren't a 0x100 aligned block |
| 260 | | if [[ $(($LENGTH - $COUNT)) -lt 0x100 || $OFFSET -ne 0 ]]; then |
| 261 | | HIGH=$(($LENGTH - $COUNT - 1 + $OFFSET)) |
| 262 | | # Record remainder for i2c 0x100 upper range limit |
| 263 | | if [[ $HIGH -gt 0x100 ]]; then |
| 264 | | REMAINDER=$(($HIGH + 1 - 0x100)) |
| 265 | | else |
| 266 | | REMAINDER=0 |
| 267 | | fi |
| 268 | | |
| 269 | | RETURN=$(i2cdump -f -y -r ${OFFSET}-$(($HIGH - $REMAINDER)) 0 $ADDR b | grep ':') |
| 270 | | COUNT=$(($HIGH - $REMAINDER - $OFFSET + 1 + $COUNT)) |
| 271 | | OFFSET=0 |
| 272 | | else |
| 273 | | RETURN=$(i2cdump -f -y 0 $ADDR b | grep ':') |
| 274 | | COUNT=$(($COUNT + 0x100)) |
| 275 | | fi |
| 276 | | |
| 277 | | if [[ "$RETURN" ]]; then # Only print reads |
| 278 | | # Format output to be continuous and account for page increase |
| 279 | | echo "$RETURN" | while read x; do |
| 280 | | printf "%04x" "$((0x$(echo $x | cut -d':' -f1) + $((PAGE * 0x100))))" |
| 281 | | echo ":${x##*:}" |
| 282 | | done |
| 283 | | fi |
| 284 | | |
| 285 | | # Increase the page count |
| 286 | | ((++PAGE)) |
| 287 | | done |
| 288 | | }}} |
| 289 | | [[CollapsibleEnd]] |
| | 219 | This API which is implemented over I2C on address {{{0x5f}}} allows a user to do direct memory reads over the entirety of the accessible memory range ({{{0x0000-0xFFFF}}}). It is used by constructing a 16 bit address with the top byte (a.k.a. page) being set by writing to an undocumented register at address {{{0x20}}} offset {{{0x1f}}}. The bottom byte is then added on via standard I2C protocol. Memory writes are not supported with this API. In order to simplify the usage of this feature, a bash script was created and can be found as an attachment to this wiki page [http://trac.gateworks.com/attachment/wiki/gsc/gsc_direct_mem.sh gsc_direct_mem.sh]. |