soc/picorv32/common/boot_load.py
def bootload(bin_buffer, ser_port, baud_rate, byte_offset,
             reset_rts, reset_soft=True):
    '''
    connects to serial bootloader and uploads the byteArray `bin_buffer`
    to the picoRV32 memory at offset `byte_offset` (in bytes).
    Any content of `bin_buffer` before that offset is ignored
    (preserve bootloader code).
    '''
    s = serial.Serial(ser_port, baud_rate, timeout=5, xonxoff=False,
                      rtscts=False, dsrdtr=False)
    bin_buffer = bin_buffer[byte_offset:]
    print('Push reset ... ', end='')
    # Try a remote reset
    s.flush()
    if reset_rts:
        s.setRTS(1)
    if reset_soft:
        s.write(b'\x14')
    s.flushInput()
    if reset_rts:
        s.setRTS(0)
    # Wait for `ok\n` from the bootloader
    blocking_rx(s, b'ok\n')
    # Answer with `g`
    s.write(b'g')
    s.flush()
    print('Wait ... ', end='')
    # Wait for `o` from the bootloader
    blocking_rx(s, b'o\n')
    # Write memory
    nBytes = len(bin_buffer)
    s.write(struct.pack('>I', nBytes))
    s.flush()
    nSent = s.write(bin_buffer)
    s.flush()
    print('Sent 0x{:02x} / 0x{:02x} bytes'.format(nSent, nBytes))
    # Read and verify memory
    print('Verifying ... ', end='')
    readBackData = bytearray(0)
    readBackData += s.read(nBytes)
    while len(readBackData) < nBytes:
        b = s.read(nBytes - len(readBackData))
        if len(b) == 0:
            break
        readBackData += b
    s.close()
    if readBackData == bin_buffer:
        print('passed.')
    else:
        print('!!! Readback Error !!!')
        hex_dump(readBackData, 'rx.hex')
        hex_dump(bin_buffer, 'tx.hex')

    connects to serial bootloader and uploads the byteArray `bin_buffer`
    to the picoRV32 memory at offset `byte_offset` (in bytes).
    Any content of `bin_buffer` before that offset is ignored
    (preserve bootloader code).
    
connects to serial bootloader and uploads the byteArray `bin_buffer`
to the picoRV32 memory at offset `byte_offset` (in bytes).
Any content of `bin_buffer` before that offset is ignored
(preserve bootloader code).
connects to serial bootloader and uploads the byteArray ` bin_buffer ` to the picoRV32 memory at offset ` byte_offset ` ( in bytes ) . Any content of ` bin_buffer ` before that offset is ignored ( preserve bootloader code ) .
def bootload(bin_buffer, ser_port, baud_rate, byte_offset,
             reset_rts, reset_soft=True):
    s = serial.Serial(ser_port, baud_rate, timeout=5, xonxoff=False,
                      rtscts=False, dsrdtr=False)
    bin_buffer = bin_buffer[byte_offset:]
    print('Push reset ... ', end='')
    s.flush()
    if reset_rts:
        s.setRTS(1)
    if reset_soft:
        s.write(b'\x14')
    s.flushInput()
    if reset_rts:
        s.setRTS(0)
    blocking_rx(s, b'ok\n')
    s.write(b'g')
    s.flush()
    print('Wait ... ', end='')
    blocking_rx(s, b'o\n')
    nBytes = len(bin_buffer)
    s.write(struct.pack('>I', nBytes))
    s.flush()
    nSent = s.write(bin_buffer)
    s.flush()
    print('Sent 0x{:02x} / 0x{:02x} bytes'.format(nSent, nBytes))
    print('Verifying ... ', end='')
    readBackData = bytearray(0)
    readBackData += s.read(nBytes)
    while len(readBackData) < nBytes:
        b = s.read(nBytes - len(readBackData))
        if len(b) == 0:
            break
        readBackData += b
    s.close()
    if readBackData == bin_buffer:
        print('passed.')
    else:
        print('!!! Readback Error !!!')
        hex_dump(readBackData, 'rx.hex')
        hex_dump(bin_buffer, 'tx.hex')
def bootload ( bin_buffer , ser_port , baud_rate , byte_offset , reset_rts , reset_soft = True ) : s = serial . Serial ( ser_port , baud_rate , timeout = 5 , xonxoff = False , rtscts = False , dsrdtr = False ) bin_buffer = bin_buffer [ byte_offset : ] print ( 'Push reset ... ' , end = '' ) s . flush ( ) if reset_rts : s . setRTS ( 1 ) if reset_soft : s . write ( b'\x14' ) s . flushInput ( ) if reset_rts : s . setRTS ( 0 ) blocking_rx ( s , b'ok\n' ) s . write ( b'g' ) s . flush ( ) print ( 'Wait ... ' , end = '' ) blocking_rx ( s , b'o\n' ) nBytes = len ( bin_buffer ) s . write ( struct . pack ( '>I' , nBytes ) ) s . flush ( ) nSent = s . write ( bin_buffer ) s . flush ( ) print ( 'Sent 0x{:02x} / 0x{:02x} bytes' . format ( nSent , nBytes ) ) print ( 'Verifying ... ' , end = '' ) readBackData = bytearray ( 0 ) readBackData += s . read ( nBytes ) while len ( readBackData ) < nBytes : b = s . read ( nBytes - len ( readBackData ) ) if len ( b ) == 0 : break readBackData += b s . close ( ) if readBackData == bin_buffer : print ( 'passed.' ) else : print ( '!!! Readback Error !!!' ) hex_dump ( readBackData , 'rx.hex' ) hex_dump ( bin_buffer , 'tx.hex' )
connects to serial bootloader and uploads the byteArray `bin_buffer`
to the picoRV32 memory at offset `byte_offset` (in bytes).
connects to serial bootloader and uploads the byteArray ` bin_buffer ` to the picoRV32 memory at offset ` byte_offset ` ( in bytes ) .
'''
    connects to serial bootloader and uploads the byteArray `bin_buffer`
    to the picoRV32 memory at offset `byte_offset` (in bytes).
    Any content of `bin_buffer` before that offset is ignored
    (preserve bootloader code).
    ''' # Try a remote reset # Wait for `ok\n` from the bootloader # Answer with `g` # Wait for `o` from the bootloader # Write memory # Read and verify memory
bin_buffer
ser_port
baud_rate
byte_offset
reset_rts
reset_soft