fpgaflash: Ensure PEP 8 Compliance
The stadard python tools, autopep8 and pep8, were used
to format and verify the code meets PEP 8 compliance.
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
-import argparse, struct, sys, tempfile, os, subprocess, fcntl, filecmp, stat
+import argparse
+import struct
+import sys
+import tempfile
+import os
+import subprocess
+import fcntl
+import filecmp
+import stat
from array import *
+
def check_rpd(ifile):
data = ifile.read(0x20)
pof_hdr = struct.unpack('IIIIIIII', data)
@@ -42,12 +51,15 @@ def check_rpd(ifile):
return pof_hdr[4]
+
def reverse_bits(x, n):
result = 0
for i in xrange(n):
- if (x >> i) & 1: result |= 1 << (n - 1 - i)
+ if (x >> i) & 1:
+ result |= 1 << (n - 1 - i)
return result
+
def reverse_bits_in_file(ifile, ofile):
bit_rev = array('B')
for i in range(0, 256):
@@ -63,6 +75,7 @@ def reverse_bits_in_file(ifile, ofile):
ochunk += chr(bit_rev[ord(b)])
ofile.write(ochunk)
+
def get_flash_size(dev):
MEMGETINFO = 0x80204d01
@@ -87,6 +100,7 @@ def get_flash_size(dev):
return ioctl_odata[2]
+
def flash_erase(dev, start, nbytes):
MEMERASE = 0x40084d02
@@ -106,6 +120,7 @@ def flash_erase(dev, start, nbytes):
os.close(fd)
+
def flash_write(dev, start, nbytes, ifile):
try:
@@ -133,6 +148,7 @@ def flash_write(dev, start, nbytes, ifile):
os.close(fd)
+
def flash_read(dev, start, nbytes, ofile):
try:
fd = os.open(dev, os.O_SYNC | os.O_RDONLY)
@@ -159,6 +175,7 @@ def flash_read(dev, start, nbytes, ofile):
os.close(fd)
+
def parse_args():
descr = 'A tool to help update the flash used to configure an '
descr += 'Intel FPGA at power up.'
@@ -168,8 +185,9 @@ def parse_args():
epi += 'Use the output of \'ls -l /sys/class/mtd\' to help determine\n'
epi += 'which device, /dev/mtd*.\n\n'
+ fc = argparse.RawDescriptionHelpFormatter
parser = argparse.ArgumentParser(description=descr, epilog=epi,
- formatter_class=argparse.RawDescriptionHelpFormatter)
+ formatter_class=fc)
parser.add_argument('type', help='type of flash programming',
choices=['user', 'factory_that_can_brick_board'])
