Created
December 23, 2016 02:39
-
-
Save summivox/a438694a81078eb08a2d0eef0791fb8e to your computer and use it in GitHub Desktop.
bus pirate spi flash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require! { | |
'get-stdin': input | |
} | |
BYTE_PER_BLOCK = 256 | |
BYTE_PER_LINE = 8 | |
BASE = 0 | |
out = console.~log | |
b3 = -> [ | |
(it.>>.16).&.0xff | |
(it.>>.8).&.0xff | |
(it.>>.0).&.0xff | |
] | |
hex-byte = (x) -> | |
s = x.toString(16).toUpperCase() | |
'0x' + '0'*(2 - s.length) + s | |
WRITE_EN = '[0x06]' | |
WRITE_CMD = '[0x02' | |
ERASE_4K = '[0x20 0 0 0]' | |
ERASE_32K = '[0x52 0 0 0]' | |
ERASE_64K = '[0xD8 0 0 0]' | |
ERASE_ALL = '[0x60]' | |
input.buffer! .then (buf) -> | |
for i from 0 til buf.length by BYTE_PER_BLOCK | |
out do | |
WRITE_EN | |
WRITE_CMD | |
b3 (BASE + i) .map hex-byte .join ' ' | |
block = buf.slice(i, i + BYTE_PER_BLOCK) | |
for j from 0 til block.length by BYTE_PER_LINE | |
line = block.slice(j, j + BYTE_PER_LINE) | |
out ...[hex-byte .. for line] | |
out ']' | |
out '' | |
out '' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment