aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavid.jc.anderson2007-04-22 04:41:39 +0000
committerdavid.jc.anderson2007-04-22 04:41:39 +0000
commita0f176a2e60b1c1e6d4c026b7dfada0dfeab42a6 (patch)
treeb770e632a5eee0829d6497d0c7df4e2ac2c2e1cb
parentf3cb0aac3dc4370ee977cea337f04d5c9b29fffc (diff)
Rejigger the flash writer to be able to pull a binary flash driver from code.google.com.
-rw-r--r--SConstruct15
-rw-r--r--flash_routine.h.base2
-rw-r--r--flash_write/Makefile16
-rwxr-xr-xmake_flash_header.py120
4 files changed, 106 insertions, 47 deletions
diff --git a/SConstruct b/SConstruct
index 3020c85..48970cc 100644
--- a/SConstruct
+++ b/SConstruct
@@ -15,17 +15,16 @@ if auto_libs:
BuildEnv.ParseConfig('pkg-config --cflags --libs ' + auto_libs)
BuildEnv.Command('flash_routine.h',
- ['flash_routine.h.base',
- 'flash_write/flash.bin'],
- './make_flash_header.py flash_write/flash.bin')
+ 'flash_routine.h.base',
+ './make_flash_header.py')
Default(BuildEnv.Library('nxt',
[x for x in glob('*.c')
if not x.startswith('main_')],
LIBS='usb'))
-Default(BuildEnv.Program('fwflash', glob('main_fwflash.c'),
- LIBS=['usb', 'nxt'], LIBPATH='.fwexec', glob('main_fwexec.c'),
- LIBS=['usb', 'nxt'], LIBPATH='.', 'nxt'], LIBPATH='.'))
-BuildEnv.Program('sambaget', glob('main_sambaget.c'),
- LIBS=['usb', \ No newline at end of file
+Default(BuildEnv.Program('fwflash', 'main_fwflash.c',
+ LIBS=['usb', 'nxt'], LIBPATH='.'))
+
+Default(BuildEnv.Program('fwexec', 'main_fwexec.c',
+ LIBS=['usb', 'nxt'], LIBPATH='.'))
diff --git a/flash_routine.h.base b/flash_routine.h.base
index 0930810..116fa92 100644
--- a/flash_routine.h.base
+++ b/flash_routine.h.base
@@ -26,7 +26,7 @@
/*
* An array containing all the bits of the flash routine bytecode.
*/
-static char flash_bin[] = { ___FLASH_BIN___ };
+static char flash_bin[] = {___FLASH_BIN___};
/*
* The number of bytes in the above array.
diff --git a/flash_write/Makefile b/flash_write/Makefile
index 2bc9417..93bb888 100644
--- a/flash_write/Makefile
+++ b/flash_write/Makefile
@@ -4,14 +4,16 @@
# objdump --disassemble-all -bbinary -marm7tdmi flash.bin > flash.asm
#
-TOOL_PREFIX=arm-elf-
+CC=`which arm-elf-gcc`
+AS=`which arm-elf-as`
+LD=`which arm-elf-ld`
+OBJCOPY=`which arm-elf-objcopy`
all:
- $(TOOL_PREFIX)gcc -W -Wall -O3 -mcpu=arm7tdmi -mapcs -mthumb-interwork -c -o flash.o flash.c
- $(TOOL_PREFIX)as --warn -mcpu=arm7tdmi -mapcs-32 -EL -mthumb-interwork -o crt0.o crt0.s
- $(TOOL_PREFIX)ld -O3 --gc-sections crt0.o flash.o -o flash
- $(TOOL_PREFIX)objcopy -O binary flash flash.bin
- $(TOOL_PREFIX)objdump --disassemble-all -b binary -m arm7tdmi flash.bin > flash.asm
+ $(CC) -W -Wall -O3 -msoft-float -mcpu=arm7tdmi -mapcs -c -o flash.o flash.c
+ $(AS) --warn -mfpu=softfpa -mcpu=arm7tdmi -mapcs-32 -o crt0.o crt0.s
+ $(LD) -O3 --gc-sections crt0.o flash.o -o flash.elf
+ $(OBJCOPY) -O binary flash.elf flash.bin
clean:
- rm -f flash.o flash.bin flash.asm
+ rm -f flash.o crt0.o flash.elf flash.bin
diff --git a/make_flash_header.py b/make_flash_header.py
index 7901891..9734c86 100755
--- a/make_flash_header.py
+++ b/make_flash_header.py
@@ -8,44 +8,102 @@
# firmware flashing routine instead.
#
-from sys import argv
+import sys
+import os
+import os.path
+import urllib2
+import sha
-if len(argv) == 2:
- fname = argv[1]
-else:
- fname = 'flash_write/flash_write.bin'
+FLASH_DIR = 'flash_write'
+FLASH_BIN = 'flash.bin'
+FLASH_PATH = os.path.join(FLASH_DIR, FLASH_BIN)
-fwbin = file(fname)
+DOWNLOAD_FLASH_CHECKSUM = '589501072d76be483f873a787080adcab20841f4'
+DOWNLOAD_FLASH_URL = 'http://libnxt.googlecode.com/files/flash.bin'
-# Build the char representation in memory
+def check_flash_size():
+ statinfo = os.stat(FLASH_PATH)
+ if statinfo.st_size > 1024:
+ print "The flash driver looks too big, refusing to embed."
+ return False
+ return True
-def char_by_char(f):
- while True:
- d = f.read(1)
- if d == '':
- raise StopIteration
- yield d
+def ensure_flash_bin():
+ # If the flash binary does exist, just check its size and return.
+ if os.path.isfile(FLASH_PATH):
+ return check_flash_size()
-data = []
-for c in char_by_char(fwbin):
- data.append("0x%s" % c.encode('hex'))
+ # If the binary doesn't exist, offer to download a binary build
+ # from Google Code.
+ print """
+Embedded flash driver not found. This is required to build LibNXT.
-for i in range(0, len(data), 12):
- data[i] = "\n" + data[i]
+If you have an ARM7 cross-compiler toolchain available, you can build
+the flash driver by interrupting (ctrl-C) this build and running
+'make' in the 'flash_write' subdirectory. Then rerun this build again,
+and everything should work great.
-data_str = ', '.join(data)
-len_data = "0x%X" % len(data)
+If you do not have a cross-compiler, do not despair! I can also
+download a copy of the compiled driver (built by the libnxt developer)
+from the project website and use that.
+"""
+ reply = raw_input("Is that okay? (y/n) ")
+ if reply not in ('y', 'Y', 'yes'):
+ print ("Okay, you're the boss. But that does mean I can't build "
+ "LibNXT. Sorry.")
+ return False
+ f = urllib2.urlopen(DOWNLOAD_FLASH_URL)
+ data = f.read()
+ f.close()
-# Read in the template
-tplfile = file('flash_routine.h.base')
-template = tplfile.read()
-tplfile.close()
+ # Verify the SHA-1 checksum
+ checksum = sha.new(data).hexdigest()
+ if checksum != DOWNLOAD_FLASH_CHECKSUM:
+ print "Oops, the flash binary I downloaded has the wrong checksum!"
+ print "Aborting :("
+ return False
-# Replace the values in the template
-template = template.replace('___FLASH_BIN___', data_str)
-template = template.replace('___FLASH_LEN___', len_data)
+ f = open(FLASH_PATH, 'w')
+ f.write(data)
+ f.close()
+
+ if os.path.isfile(FLASH_PATH):
+ return check_flash_size()
+
+ # Dude, you're really not lucky, are you.
+ return False
+
+
+def main():
+ if not ensure_flash_bin():
+ sys.exit(1)
+
+ f = file(FLASH_PATH)
+ fwbin = f.read()
+ f.close()
+
+ data = ['0x%s' % c.encode('hex') for c in fwbin]
+
+ for i in range(0, len(data), 12):
+ data[i] = "\n " + data[i]
+
+ data_str = ', '.join(data)
+ len_data = "%d" % len(data)
+
+ # Read in the template
+ tplfile = file('flash_routine.h.base')
+ template = tplfile.read()
+ tplfile.close()
+
+ # Replace the values in the template
+ template = template.replace('___FLASH_BIN___', data_str + '\n')
+ template = template.replace('___FLASH_LEN___', len_data)
+
+ # Output the done header
+ out = file('flash_routine.h', 'w')
+ out.write(template)
+ out.close()
+
+if __name__ == '__main__':
+ main()
-# Output the done header
-out = file('flash_routine.h', 'w')
-out.write(template)
-out.close()