aboutsummaryrefslogtreecommitdiffstats
path: root/host/utils/usrp2_card_burner.py
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-08-10 11:47:49 -0700
committerJosh Blum <josh@joshknows.com>2010-08-10 11:47:49 -0700
commit97624cfedca581ff34a3f932cccf20a84b2714dd (patch)
treeabef46122f7962b127cf9ca0e3b61fe3ec5929b7 /host/utils/usrp2_card_burner.py
parentf6c3178c7ce7b255c3bcf9ade6d9d61b5de79ae1 (diff)
downloaduhd-97624cfedca581ff34a3f932cccf20a84b2714dd.tar.gz
uhd-97624cfedca581ff34a3f932cccf20a84b2714dd.tar.bz2
uhd-97624cfedca581ff34a3f932cccf20a84b2714dd.zip
usrp2: work on card burner to pad the image file before a write
Diffstat (limited to 'host/utils/usrp2_card_burner.py')
-rwxr-xr-xhost/utils/usrp2_card_burner.py40
1 files changed, 30 insertions, 10 deletions
diff --git a/host/utils/usrp2_card_burner.py b/host/utils/usrp2_card_burner.py
index d47a4f5f4..1db5e59ce 100755
--- a/host/utils/usrp2_card_burner.py
+++ b/host/utils/usrp2_card_burner.py
@@ -21,6 +21,7 @@ import tempfile
import subprocess
import urllib
import optparse
+import math
import os
import re
@@ -59,6 +60,14 @@ def get_dd_path():
return dd_path
return 'dd'
+def int_ceil_div(num, den):
+ return int(math.ceil(float(num)/float(den)))
+
+def get_tmp_file():
+ tmp = tempfile.mkstemp()
+ os.close(tmp[0])
+ return tmp[1]
+
########################################################################
# list possible devices
########################################################################
@@ -136,10 +145,12 @@ def get_raw_device_hints():
# write and verify with dd
########################################################################
def verify_image(image_file, device_file, offset):
- #create a temporary file to store the readback
- tmp = tempfile.mkstemp()
- os.close(tmp[0])
- tmp_file = tmp[1]
+ #create a temporary file to store the readback image
+ tmp_file = get_tmp_file()
+
+ #read the image data
+ img_data = open(image_file, 'rb').read()
+ count = int_ceil_div(len(img_data), SECTOR_SIZE)
#execute a dd subprocess
verbose = command(
@@ -148,24 +159,33 @@ def verify_image(image_file, device_file, offset):
"if=%s"%device_file,
"skip=%d"%(offset/SECTOR_SIZE),
"bs=%d"%SECTOR_SIZE,
- "count=%d"%(MAX_FILE_SIZE/SECTOR_SIZE),
+ "count=%d"%count,
)
- #read in the image and readback
- img_data = open(image_file, 'rb').read()
- tmp_data = open(tmp_file, 'rb').read(len(img_data))
-
#verfy the data
+ tmp_data = open(tmp_file, 'rb').read(len(img_data))
if img_data != tmp_data: return 'Verification Failed:\n%s'%verbose
return 'Verification Passed:\n%s'%verbose
def write_image(image_file, device_file, offset):
+ #create a temporary file to store the padded image
+ tmp_file = get_tmp_file()
+
+ #write the padded image data
+ img_data = open(image_file, 'rb').read()
+ count = int_ceil_div(len(img_data), SECTOR_SIZE)
+ pad_len = SECTOR_SIZE*count - len(img_data)
+ pad_str = ''.join([chr(0)]*pad_len) #zero-padding
+ open(tmp_file, 'wb').write(img_data + pad_str)
+
+ #execute a dd subprocess
verbose = command(
get_dd_path(),
- "if=%s"%image_file,
+ "if=%s"%tmp_file,
"of=%s"%device_file,
"seek=%d"%(offset/SECTOR_SIZE),
"bs=%d"%SECTOR_SIZE,
+ "count=%d"%count,
)
try: #exec the sync command (only works on linux)