diff options
author | 211217613 <rubenavazquez@gmail.com> | 2016-06-23 20:35:46 -0500 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2016-06-27 09:58:04 -0700 |
commit | 23a04bf3ed4c4745492c5316d8921ecba1fb6499 (patch) | |
tree | f186f065ea6a16fe17cbc730b267c65eb4518a5b /firmware/fx2/utils/build_eeprom.py | |
parent | 9caf20c29956be283b032110096a81f99a121da7 (diff) | |
download | uhd-23a04bf3ed4c4745492c5316d8921ecba1fb6499.tar.gz uhd-23a04bf3ed4c4745492c5316d8921ecba1fb6499.tar.bz2 uhd-23a04bf3ed4c4745492c5316d8921ecba1fb6499.zip |
Close file handlers the python way, changed var bytes to out_bytes
Diffstat (limited to 'firmware/fx2/utils/build_eeprom.py')
-rwxr-xr-x | firmware/fx2/utils/build_eeprom.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/firmware/fx2/utils/build_eeprom.py b/firmware/fx2/utils/build_eeprom.py index 76502b923..9180bf1a0 100755 --- a/firmware/fx2/utils/build_eeprom.py +++ b/firmware/fx2/utils/build_eeprom.py @@ -45,8 +45,8 @@ def build_eeprom_image (filename, rev): the EZ-USB FX2 Technical Reference Manual """ # get the code we want to run - f = open(filename, 'rb') - bytes = f.read() + with open(filename, 'rb') as f: + out_bytes = f.read() devid = 4 #for compatibility start_addr = 0 #prove me wrong @@ -72,8 +72,8 @@ def build_eeprom_image (filename, rev): # 4 byte header that indicates where to load # the immediately follow code bytes. code_header = [ - msb (len (bytes)), - lsb (len (bytes)), + msb (len (out_bytes)), + lsb (len (out_bytes)), msb (start_addr), lsb (start_addr) ] @@ -87,7 +87,7 @@ def build_eeprom_image (filename, rev): 0x00 ] - image = rom_header + code_header + [ord(c) for c in bytes] + trailer + image = rom_header + code_header + [ord(c) for c in out_bytes] + trailer assert (len (image) <= 256) return image @@ -111,6 +111,6 @@ if __name__ == '__main__': image = "".join(chr(c) for c in build_eeprom_image(infile, options.rev)) - f = open(outfile, 'wb') - f.write(str(image)) - f.close() + # Opening in binary mode -> why converting image to str + with open(outfile, 'wb') as f: + f.write( str(image) )
\ No newline at end of file |