Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/misoc
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 745ff1297625
Choose a base ref
...
head repository: m-labs/misoc
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 967f03aeabbd
Choose a head ref
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on Nov 10, 2016

  1. flterm: add --upload-only option.

    whitequark committed Nov 10, 2016
    Copy the full SHA
    50b4dfa View commit details
  2. Copy the full SHA
    967f03a View commit details
Showing with 40 additions and 14 deletions.
  1. +40 −14 misoc/tools/flterm.py
54 changes: 40 additions & 14 deletions misoc/tools/flterm.py
Original file line number Diff line number Diff line change
@@ -122,18 +122,25 @@ def encode(self):


class Flterm:
def __init__(self, port, speed, kernel_image, kernel_address):
def __init__(self, port, speed, kernel_image, kernel_address,
upload_only, output_only):
self.kernel_image = kernel_image
self.kernel_address = kernel_address
self.upload_only = upload_only
self.output_only = output_only

self.port = asyncserial.AsyncSerial(port, baudrate=speed)

self.keyqueue = asyncio.Queue(100)
def getkey_callback(c):
self.keyqueue.put_nowait(c)
init_getkey(getkey_callback)

self.main_task = asyncio.ensure_future(self.main_coro())
if not (upload_only or output_only):
self.keyqueue = asyncio.Queue(100)
def getkey_callback(c):
self.keyqueue.put_nowait(c)
init_getkey(getkey_callback)

if self.upload_only:
self.main_task = asyncio.ensure_future(self.upload_only_coro())
else:
self.main_task = asyncio.ensure_future(self.main_coro())

async def send_frame(self, frame):
while True:
@@ -181,7 +188,7 @@ async def boot(self):
print("[FLTERM] Booting the device.")
frame = SFLFrame()
frame.cmd = sfl_cmd_jump
frame.payload = self.kernel_address.to_bytes(4, "big")
frame.payload = self.kernel_address.to_bytes(4, "big")
await self.send_frame(frame)

async def answer_magic(self):
@@ -198,8 +205,9 @@ async def answer_magic(self):
async def main_coro(self):
magic_detect_buffer = b"\x00"*len(sfl_magic_req)
while True:
fs = [asyncio.ensure_future(self.port.read(1024)),
asyncio.ensure_future(self.keyqueue.get())]
fs = [asyncio.ensure_future(self.port.read(1024))]
if not self.output_only:
fs += [asyncio.ensure_future(self.keyqueue.get())]
try:
done, pending = await asyncio.wait(
fs, return_when=asyncio.FIRST_COMPLETED)
@@ -223,12 +231,25 @@ async def main_coro(self):
await self.answer_magic()
break

if fs[1] in done:
if len(fs) > 1 and fs[1] in done:
await self.port.write(fs[1].result())

async def upload_only_coro(self):
magic_detect_buffer = b"\x00"*len(sfl_magic_req)
while True:
data = await self.port.read(1024)
sys.stdout.buffer.write(data)
sys.stdout.flush()

for c in data:
magic_detect_buffer = magic_detect_buffer[1:] + bytes([c])
if magic_detect_buffer == sfl_magic_req:
await self.answer_magic()
return

async def close(self):
deinit_getkey()
if not (self.upload_only or self.output_only):
deinit_getkey()
self.main_task.cancel()
await asyncio.wait([self.main_task])
self.port.close()
@@ -241,6 +262,10 @@ def _get_args():
parser.add_argument("--kernel", default=None, help="kernel image")
parser.add_argument("--kernel-addr", type=lambda a: int(a, 0),
default=0x40000000, help="kernel address")
parser.add_argument("--upload-only", default=False, action="store_true",
help="only upload kernel")
parser.add_argument("--output-only", default=False, action="store_true",
help="do not receive keyboard input or require a pty")
return parser.parse_args()


@@ -252,9 +277,10 @@ def main():
loop = asyncio.get_event_loop()
try:
args = _get_args()
flterm = Flterm(args.port, args.speed, args.kernel, args.kernel_addr)
flterm = Flterm(args.port, args.speed, args.kernel, args.kernel_addr,
args.upload_only, args.output_only)
try:
loop.run_forever()
loop.run_until_complete(flterm.main_task)
finally:
loop.run_until_complete(flterm.close())
finally: