Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion boot_surgeon.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
import pager
import cbf
import sys
Expand All @@ -14,7 +15,7 @@ def do_surgeon_boot(path):
"""
pager_client = pager.client(conn_iface(mount_connection()))
pager_client.upload(path)
print 'Booting surgeon.'
print ('Booting surgeon.')


if len(sys.argv) != 2:
Expand Down
66 changes: 34 additions & 32 deletions cbf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
##############################################################################
# OpenLFConnect
#
Expand Down Expand Up @@ -31,6 +31,8 @@

#@
# cbf.py Version 0.1.2
# Ported to Python 3 by A.Mccarthy
#

import os
import array
Expand All @@ -45,8 +47,9 @@
##############################

PACKET_SIZE = 16384
MAGIC_NUMBER = '\xf0\xde\xbc\x9a'
COMPRESSION_SIG = '\x1F\x8B\x08\x00' #gunzip
MAGIC_NUMBER = b'\xf0\xde\xbc\x9a'
# MAGIC_NUMBER = struct.pack('IIII', 240, 222, 188, 154)
COMPRESSION_SIG = b'\x1F\x8B\x08\x00' #gunzip
CBF_VERSION = 1
BLOCK_SIZE = 0x20000
KERNEL_LOAD_08 = 0x8000
Expand All @@ -59,7 +62,6 @@
def error(e):
assert False, e


def check(path, ret_bool=False):
try:
if not os.path.exists(path):
Expand All @@ -71,11 +73,12 @@ def check(path, ret_bool=False):
magic = f.read(4)
f.close()

if not str(file_size/PACKET_SIZE).isdigit():
# if not str(file_size/PACKET_SIZE).isdigit():
if (file_size % PACKET_SIZE) != 0:
if ret_bool:
return False
else:
error('File is the wrong size, should be multiple of %s.' % PACKET_SIZE)
error('File is the wrong size, should be multiple of %s.' % str(file_size/PACKET_SIZE))

if magic != MAGIC_NUMBER:
if ret_bool:
Expand All @@ -84,7 +87,7 @@ def check(path, ret_bool=False):
error('File failed CBF Magic Number check.')
else:
return True
except Exception, e:
except Exception as e:
error(e)


Expand All @@ -100,12 +103,12 @@ def extract(path):

kernel_path = os.path.join(os.path.dirname(path), kernel_name)

print 'Unwrapping Kernel from CBF'
print('Unwrapping Kernel from CBF')

fimg = open(kernel_path, 'wb')
fimg.write(image)
fimg.close()
print 'Saved as: %s' % kernel_name
print('Saved as: %s' % kernel_name)


def create(mem, opath, ipath):
Expand All @@ -123,7 +126,7 @@ def create(mem, opath, ipath):
error('No output file selected')

if not os.path.exists(ipath):
error('Path does not exist.')
error('CBF: Path does not exist.')
elif os.path.isdir(ipath):
error('Path is not a file.')
elif 'zImage' not in image_name and 'Image' not in image_name:
Expand All @@ -138,7 +141,7 @@ def create(mem, opath, ipath):
p = packer(mem, opath, ipath)
p.pack()
summary(os.path.join(image_path, opath))
except Exception, e:
except Exception as e:
error(e)


Expand All @@ -147,16 +150,16 @@ def summary(path):
p = parse(path)
p.create_summary()

print 'CBF File Summary:'
print('CBF File Summary:')

for k,v in p.summary.iteritems():
for k,v in p.summary.items():
if len(k) < 7:
tab = '\t\t'
else:
tab = '\t'
print '%s:%s0x%08x' % (k,tab,v)
print('%s:%s0x%08x' % (k,tab,v))

print 'Compressed: \t %s' % p.is_compressed
print('Compressed: \t %s' % p.is_compressed)



Expand Down Expand Up @@ -210,7 +213,7 @@ def get_image(self):

f.close()
return image
except Exception, e:
except Exception as e:
self.error(e)


Expand All @@ -220,15 +223,14 @@ class packer(object):
def __init__(self, mem, opath, ipath):
self._in_path = ipath
self._out_path = opath
self._summary = ''
self._summary_crc = ''
self._buffer = ''
self._buffer_crc = ''
self._summary = b''
self._summary_crc = b''
self._buffer = b''
self._buffer_crc = b''
self._size = 0

if mem.lower() == 'superhigh':
self._kernel_jump = KERNEL_JUMP_28
self._kernel_load = KERNEL_LOAD_28
if mem.lower() == 'superhigh':
self._kernel_jump = KERNEL_JUMP_28
self._kernel_load = KERNEL_LOAD_28
elif mem.lower() == 'high':
self._kernel_jump = KERNEL_JUMP_10
self._kernel_load = KERNEL_LOAD_10
Expand Down Expand Up @@ -266,19 +268,21 @@ def pack(self):

rem = buf_len % BLOCK_SIZE
pad_len = 0
padding = b''

if rem != 0:
pad_len = BLOCK_SIZE - rem

padding = pad_len * '\xFF'
padding = pad_len * b'\xFF'

buf += padding
print 'Writing CBF file.'
print('Writing CBF file.')
f = open(self._out_path, 'wb')
f.write(buf)
f.close()


except Exception, e:
except Exception as e:
error(e)


Expand All @@ -303,9 +307,7 @@ def set_summary(self):
self._summary = MAGIC_NUMBER
self._summary += struct.pack('IIII', CBF_VERSION, self._kernel_load, self._kernel_jump, self._size)
self._summary_crc = self.crc(self._summary)
self._summary += struct.pack('I', self._summary_crc)

if __name__ == '__main__':
print 'No examples yet.'

self._summary += struct.pack('I', self._summary_crc)

if __name__ == '__main__':
print('No examples yet.')
12 changes: 7 additions & 5 deletions interface.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
##############################################################################
# OpenLFConnect
#
Expand Down Expand Up @@ -31,6 +31,8 @@

#@
# services/interface.py Version 0.5
# Ported to Python 3 by A.McCarthy

class config(object):
def __init__(self, connection):
self._connection = connection
Expand All @@ -47,7 +49,7 @@ def get_root_dir(self):
def get_device_id(self):
try:
return self._connection.get_device_id_i()
except Exception, e:
except Exception as e:
self._connection.rerror(e)

device_id = property(get_device_id)
Expand All @@ -57,7 +59,7 @@ def get_device_id(self):
def get_host_id(self):
try:
return self._connection.get_host_id_i()
except Exception, e:
except Exception as e:
self._connection.rerror(e)

host_id = property(get_host_id)
Expand All @@ -66,8 +68,8 @@ def get_host_id(self):
def is_connected(self):
try:
return self._connection.is_connected_i()
except Exception, e:
except Exception as e:
self._connection.rerror(e)

if __name__ == '__main__':
print 'No examples yet.'
print('No examples yet.')
1 change: 1 addition & 0 deletions make_cbf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
import cbf
import sys

Expand Down
22 changes: 12 additions & 10 deletions mount.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
##############################################################################
# OpenLFConnect
#
Expand Down Expand Up @@ -31,6 +31,8 @@

#@
# mount.py Version 0.5.2
# Ported to Python 3 by A.McCarthy

import os
import re
import sys
Expand Down Expand Up @@ -114,13 +116,13 @@ def sg_scan(self):
if not err:
ret = p.stdout.read()

if self._vendor_name in ret.lower():
if self._vendor_name in str(ret.lower(), 'utf-8'):
return ret
else:
return ''
else:
return ''
except Exception, e:
except Exception as e:
self.error(e)


Expand All @@ -131,7 +133,7 @@ def find_device_id(self):

while time_out:
if sys.platform == 'win32':
lines = self.sg_scan().split('\n')
lines = str(self.sg_scan(), 'utf-8').split('\n')
if lines:
for line in lines:
if self._vendor_name in line.lower():
Expand Down Expand Up @@ -168,7 +170,7 @@ def find_device_id(self):
time_out -= 1
sleep(1)
self.error('Device not found.')
except Exception, e:
except Exception as e:
self.error(e)


Expand Down Expand Up @@ -211,7 +213,7 @@ def find_mount_point(self, win_label='didj'):
sleep(1)
timeout -= 1
self.error('Mount not found.')
except Exception, e:
except Exception as e:
self.error(e)


Expand All @@ -228,24 +230,24 @@ def get_root_dir_i(self):
def get_device_id_i(self):
try:
return self._device_id or self.find_device_id()
except Exception, e:
except Exception as e:
self.error(e)



def get_host_id_i(self):
try:
return self._mount_point or self.find_mount_point()
except Exception, e:
except Exception as e:
self.error(e)



def is_connected_i(self):
try:
return os.path.exists(self._mount_point)
except Exception, e:
except Exception as e:
self.error(e)

if __name__ == '__main__':
print 'No examples yet.'
print('No examples yet.')
Loading