Skip to content

Commit

Permalink
scripts: wrap lines to 80 characters
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz-holenko committed Jun 3, 2019
1 parent eaab51f commit c582984
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 30 deletions.
9 changes: 6 additions & 3 deletions scripts/build-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ function configure_tap {

# Check the tap0 device if configure and up
if sudo which ifconfig > /dev/null; then
if ! ifconfig tap0 | grep -q "UP" || ! ifconfig tap0 | grep -q "$TFTP_IPRANGE.100"; then
if ! ifconfig tap0 | grep -q "UP" || \
! ifconfig tap0 | grep -q "$TFTP_IPRANGE.100"; then
sudo true
sudo ifconfig tap0 $TFTP_IPRANGE.100 netmask 255.255.255.0 up
fi
elif sudo which ip > /dev/null; then
if ! ip addr show tap0 | grep -q "UP" || ! ip addr show tap0 | grep -q "$TFTP_IPRANGE.100"; then
if ! ip addr show tap0 | grep -q "UP" || \
! ip addr show tap0 | grep -q "$TFTP_IPRANGE.100"; then
sudo true
sudo ip addr add $TFTP_IPRANGE.100/24 dev tap0
sudo ip link set dev tap0 up
Expand All @@ -71,6 +73,7 @@ function parse_generated_header {
# $1 - filename
# $2 - define name

grep $2 $TARGET_BUILD_DIR/software/include/generated/$1 | tr -s ' ' | cut -d' ' -f3
grep $2 $TARGET_BUILD_DIR/software/include/generated/$1 | tr -s ' ' | \
cut -d' ' -f3
}

16 changes: 11 additions & 5 deletions scripts/build-qemu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ fi
cd $QEMU_SRC_DIR

# Add the remote if it doesn't exist
CURRENT_QEMU_REMOTE_NAME=$(git remote -v | grep fetch | grep "$QEMU_REMOTE_BIT" | sed -e's/\t.*$//')
CURRENT_QEMU_REMOTE_NAME=$(git remote -v | grep fetch | \
grep "$QEMU_REMOTE_BIT" | sed -e's/\t.*$//')
if [ x"$CURRENT_QEMU_REMOTE_NAME" = x ]; then
git remote add $QEMU_REMOTE_NAME $QEMU_REMOTE
CURRENT_QEMU_REMOTE_NAME=$QEMU_REMOTE_NAME
Expand All @@ -43,7 +44,8 @@ fi
# Checkout master branch if not already on it
if [ "$(git rev-parse --abbrev-ref HEAD)" != "$QEMU_BRANCH" ]; then
git checkout $QEMU_BRANCH || \
git checkout "$CURRENT_QEMU_REMOTE_NAME/$QEMU_BRANCH" -b $QEMU_BRANCH
git checkout "$CURRENT_QEMU_REMOTE_NAME/$QEMU_BRANCH" \
-b $QEMU_BRANCH
fi
)

Expand Down Expand Up @@ -101,8 +103,11 @@ if [ ! -d $FIRMWARE_FILEBASE.fbi ]; then
fi

QEMU_IMAGE_FILE=$IMAGE_FILE.4qemu
/usr/bin/env python mkimage.py $MISOC_EXTRA_CMDLINE $LITEX_EXTRA_CMDLINE $MAKE_LITEX_EXTRA_CMDLINE --output-file=$QEMU_IMAGE_FILE --override-gateware=none --force-image-size=true $OVERRIDE_FIRMWARE
$TARGET_QEMU_BUILD_DIR/qemu-img convert -f raw $QEMU_IMAGE_FILE -O qcow2 -S 16M $TARGET_BUILD_DIR/qemu.qcow2
/usr/bin/env python mkimage.py $MISOC_EXTRA_CMDLINE $LITEX_EXTRA_CMDLINE \
$MAKE_LITEX_EXTRA_CMDLINE --output-file=$QEMU_IMAGE_FILE \
--override-gateware=none --force-image-size=true $OVERRIDE_FIRMWARE
$TARGET_QEMU_BUILD_DIR/qemu-img convert -f raw $QEMU_IMAGE_FILE -O qcow2 \
-S 16M $TARGET_BUILD_DIR/qemu.qcow2

# BIOS
ROM_BASE=$(parse_generated_header "mem.h" ROM_BASE)
Expand All @@ -113,7 +118,8 @@ fi

# SPI Flash
SPIFLASH_BASE=$(parse_generated_header "mem.h" SPIFLASH_BASE)
SPIFLASH_MODEL=$(grep spiflash_model platforms/$PLATFORM.py | sed -e's/[^"]*"//' -e's/".*$//')
SPIFLASH_MODEL=$(grep spiflash_model platforms/$PLATFORM.py | \
sed -e's/[^"]*"//' -e's/".*$//')
echo $SPIFLASH_MODEL
if [ ! -z "$SPIFLASH_BASE" ]; then
if [ -z "$SPIFLASH_MODEL" ]; then
Expand Down
70 changes: 48 additions & 22 deletions scripts/generate-renode-scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ def generate_ethmac(peripheral, **kwargs):
result = """
ethmac: Network.LiteX_Ethernet @ {{
sysbus <{}, +0x100>;
sysbus new Bus.BusMultiRegistration {{ address: {}; size: {}; region: "buffer" }}
sysbus new Bus.BusMultiRegistration {{ address: {};
size: {};
region: "buffer" }}
}}
""".format(peripheral['address'], buf['address'], buf['size'])

if 'interrupt' in peripheral['constants']:
result += ' -> cpu@{}\n'.format(peripheral['constants']['interrupt'])
result += ' -> cpu@{}\n'.format(
peripheral['constants']['interrupt'])

return result

Expand All @@ -57,7 +60,9 @@ def generate_memory_region(region_descriptor):
return """
{}: Memory.MappedMemory @ sysbus {}
size: {}
""".format(region_descriptor['name'], region_descriptor['address'], region_descriptor['size'])
""".format(region_descriptor['name'],
region_descriptor['address'],
region_descriptor['size'])

def generate_silencer(peripheral, **kwargs):
""" Silences access to a memory region.
Expand Down Expand Up @@ -100,7 +105,8 @@ def generate_peripheral(peripheral, **kwargs):
Args:
peripheral (dict): peripheral description
kwargs (dict): additional parameters, including 'model' and 'properties'
kwargs (dict): additional parameterss, including
'model' and 'properties'
Returns:
string: repl definition of the peripheral
Expand All @@ -126,7 +132,8 @@ def generate_repl():
""" Generates platform definition.
Returns:
string: platform defition containing all supported peripherals and memory regions
string: platform defition containing all supported
peripherals and memory regions
"""
result = ""

Expand All @@ -140,7 +147,8 @@ def generate_repl():
'handler': generate_peripheral,
'model': 'Timers.LiteX_Timer',
'properties': {
'frequency': lambda: constants['system_clock_frequency']['value']
'frequency':
lambda: constants['system_clock_frequency']['value']
}
},
'ethmac': {
Expand All @@ -166,7 +174,8 @@ def generate_repl():

for name, peripheral in peripherals.items():
if name not in name_to_handler:
print('Skipping unsupported peripheral {} at {}'.format(name, peripheral['address']))
print('Skipping unsupported peripheral {} at {}'
.format(name, peripheral['address']))
continue

h = name_to_handler[name]
Expand All @@ -181,10 +190,13 @@ def parse_csv(data):
data (list): list of CSV file lines
"""

# scan for CSRs first, so it's easier to resolve CSR-related constants in the second pass
# scan for CSRs first, so it's easier to resolve CSR-related constants
# in the second pass
for _type, _name, _address, _, __ in data:
if _type == 'csr_base':
peripherals[_name] = {'name': _name, 'address': _address, 'constants': {}}
peripherals[_name] = {'name': _name,
'address': _address,
'constants': {}}

for _type, _name, _val, _val2, _ in data:
if _type == 'csr_base':
Expand All @@ -197,14 +209,17 @@ def parse_csv(data):
found = False
for _csr_name in peripherals:
if _name.startswith(_csr_name):
peripherals[_csr_name]['constants'][_name[len(_csr_name)+1:]] = _val
local_name = _name[len(_csr_name)+1:]
peripherals[_csr_name]['constants'][local_name] = _val
found = True
break
if not found:
# if it's not a CSR-related constant, it must be a global one
constants[_name] = {'name': _name, 'value': _val}
elif _type == 'memory_region':
mem_regions[_name] = {'name': _name, 'address': _val, 'size': _val2}
mem_regions[_name] = {'name': _name,
'address': _val,
'size': _val2}
else:
print('Skipping unexpected CSV entry: {} {}'.format(_type, _name))

Expand All @@ -213,11 +228,14 @@ def generate_resc(repl_file, host_tap_interface=None, bios_binary=None):
Args:
repl_file (string): path to Renode platform definition file
host_tap_interface (string): name of the tap interface on host machine or None if no network should be configured
bios_binary (string): path to the binary file of LiteX BIOS or None if it should not be loaded into ROM
host_tap_interface (string): name of the tap interface on host machine
or None if no network should be configured
bios_binary (string): path to the binary file of LiteX BIOS or None
if it should not be loaded into ROM
Returns:
string: platform defition containing all supported peripherals and memory regions
string: platform defition containing all supported peripherals
and memory regions
"""
cpu_type = constants['config_cpu_type']['value']

Expand Down Expand Up @@ -254,7 +272,8 @@ def print_or_save(filepath, lines):
""" Prints given string on standard output or to the file.
Args:
filepath (string): path to the file lines should be written to or '-' to write to a standard output
filepath (string): path to the file lines should be written to
or '-' to write to a standard output
lines (string): content to be printed/written
"""
if filepath == '-':
Expand All @@ -265,11 +284,16 @@ def print_or_save(filepath, lines):

if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('conf_file', help='CSV configuration generated by LiteX')
parser.add_argument('--resc', action='store', help='Output script file')
parser.add_argument('--repl', action='store', help='Output platform definition file')
parser.add_argument('--configure-network', action='store', help='Generate virtual network and connect it with host interface')
parser.add_argument('--bios-binary', action='store', help='Path to the BIOS binary')
parser.add_argument('conf_file',
help='CSV configuration generated by LiteX')
parser.add_argument('--resc', action='store',
help='Output script file')
parser.add_argument('--repl', action='store',
help='Output platform definition file')
parser.add_argument('--configure-network', action='store',
help='Generate virtual network and connect it to host')
parser.add_argument('--bios-binary', action='store',
help='Path to the BIOS binary')
args = parser.parse_args()

with open(args.conf_file) as csvfile:
Expand All @@ -280,8 +304,10 @@ def print_or_save(filepath, lines):

if args.resc:
if not args.repl:
print("In order to generate RESC file you need to generated REPL as well!")
print("REPL is needed when generating RESC file")
sys.exit(1)
else:
print_or_save(args.resc, generate_resc(args.repl, args.configure_network, args.bios_binary))
print_or_save(args.resc, generate_resc(args.repl,
args.configure_network,
args.bios_binary))

0 comments on commit c582984

Please sign in to comment.