BigW Consortium Gitlab

Commit 5749f9f9 by David Frey

Add tool for generating IoT card eeprom binaries

Also add sample input files for various existing IoT cards.
parent 7ebbff9e
---
#-------------------------------------------------------------------------------
# CAN bus IoT card EEPROM content
#-------------------------------------------------------------------------------
size: 4096
content:
# iot card descriptor
-
size: 192
content:
# header
- 0xAA
- 0xA5
# major version
- 0x01
# minor version
- 0x00
# vendor name
-
size: 32
fill: 0x00
content:
- Sierra Wireless
# product name
-
size: 32
fill: 0x00
content:
- CAN Bus IoT Card
# hardware major revision
- 0x01
# hardware minor revision
- 0x00
# serial number
-
size: 32
fill: 0x00
content:
- "CAN-000000"
# environmental class
- 0x41 # 'A' TODO: is this correct?
# power category
- 1 # TODO: is this correct?
# height category
- 1
# eeprom write protect
- 1
# gpio interface descriptor
-
size: 64
content:
# type - gpio
- 0
# GPIO 0 (INT_n) - input with pull-up
- 0x03
# GPIO 1 (RESET_n) - output high
- 0x05
# GPIO 2 (RX0BF_n) - input floating
- 0x00
# GPIO 3 (RX1BF_n) - input floating
- 0x00
# spi interface descriptor
-
size: 64
content:
# type - spi
- 2
# interrupt gpio - use GPIO0 as interrupt
- 0x00
# kernel module alias
-
size: 32
fill: 0x00
content:
- mcp251x
\ No newline at end of file
---
#-------------------------------------------------------------------------------
# Ethernet IoT card EEPROM content
#-------------------------------------------------------------------------------
size: 4096
content:
# iot card descriptor
-
size: 192
content:
# header
- 0xAA
- 0xA5
# major version
- 0x01
# minor version
- 0x00
# vendor name
-
size: 32
fill: 0x00
content:
- Sierra Wireless
# product name
-
size: 32
fill: 0x00
content:
- Ethernet IoT Card
# hardware major revision
- 0x01
# hardware minor revision
- 0x00
# serial number
-
size: 32
fill: 0x00
content:
- "ENET-000000"
# environmental class
- 0x41 # 'A' TODO: is this correct?
# power category
- 1 # TODO: is this correct?
# height category
- 1
# eeprom write protect
- 1
# usb interface descriptor
-
size: 64
content:
# type - usb
- 3
---
#-------------------------------------------------------------------------------
# USB hub IoT card EEPROM content
#-------------------------------------------------------------------------------
size: 4096
content:
# iot card descriptor
-
size: 192
content:
# header
- 0xAA
- 0xA5
# major version
- 0x01
# minor version
- 0x00
# vendor name
-
size: 32
fill: 0x00
content:
- Sierra Wireless
# product name
-
size: 32
fill: 0x00
content:
- USB Hub IoT Card
# hardware major revision
- 0x01
# hardware minor revision
- 0x00
# serial number
-
size: 32
fill: 0x00
content:
- "ENET-000000"
# environmental class
- 0x41 # 'A' TODO: is this correct?
# power category
- 2 # TODO: is this correct?
# height category
- 1
# eeprom write protect
- 1
# gpio interface descriptor
-
size: 64
content:
# type - gpio
- 0
# GPIO 0 (I2C_HUB_PROG_EN) - output low
- 0x04
# GPIO 1 (UNUSED) - input floating
- 0x00
# GPIO 2 (UNUSED) - input floating
- 0x00
# GPIO 3 (UNUSED) - input floating
- 0x00
# usb interface descriptor
-
size: 64
content:
# type - usb
- 3
---
#-------------------------------------------------------------------------------
# WiFi/Bluetooth IoT card EEPROM content
#-------------------------------------------------------------------------------
size: 4096
content:
# iot card descriptor
-
size: 192
content:
# header
- 0xAA
- 0xA5
# major version
- 0x01
# minor version
- 0x00
# vendor name
-
size: 32
fill: 0x00
content:
- Sierra Wireless
# product name
-
size: 32
fill: 0x00
content:
- WiFi Bluetooth IoT Card
# hardware major revision
- 0x01
# hardware minor revision
- 0x00
# serial number
-
size: 32
fill: 0x00
content:
- "WIFIBT-000000"
# environmental class
- 0x41 # 'A' TODO: is this correct?
# power category
- 2 # TODO: is this correct?
# height category
- 1
# eeprom write protect
- 1
# gpio interface descriptor
-
size: 64
content:
# type - gpio
- 0
# GPIO 0 (WL_n) - input floating
- 0x00
# GPIO 1 (UNUSED) - input floating
- 0x00
# GPIO 2 (BT_EN) - output low
- 0x04
# GPIO 3 (WLAN_EN) - output low
- 0x04
# sdio interface descriptor
-
size: 64
content:
# type - sdio
- 4
# uart interface descriptor
-
size: 64
content:
# type - uart
- 8
#!/usr/bin/env python3
# This program converts an input file representing the layout of an eeprom into
# a binary output suitable for writing into the eeprom. The input is a YAML
# (http://yaml.org) file with a number of extra restrictions.
#
# Elements which can appear in the input file:
# * integers: These represent a byte value which should appear in the output.
# Since they are representing a byte, only values from 0-255 are accepted.
# Both hexadecimal (eg. 0x1F) and decimal (eg. 31) formatted values are
# acceptable.
# * strings: A string which appears in the input will be put as a utf-8 encoded
# value in the output. A null terminator will be appended to the string.
# * blocks: blocks do not appear in the output directly. Instead they are
# containers for other values. A block is a YAML dictionary that has a size
# key with an integer value, a content key with a list value, and optionally a
# fill key with an integer value in the byte range. Size is the number of
# bytes in the block. Content is the list of items that will be encoded into
# this block starting at the first byte. Fill is the value that will be put
# into any unused space at the end of the block. It is illegal for the encoded
# content to occupy more space than the size of the block.
#
# This program is written in Python 3 and depends on the PyYAML library
# (http://pyyaml.org)
import sys
import yaml
import struct
def write_block(size, content, fill):
used = write_bin_from_yaml(content)
if used > size:
print("Block content is too large for block", file=sys.stderr)
sys.exit(1)
sys.stdout.buffer.write(struct.pack('B', fill) * (size - used))
return size
def write_bin_from_yaml(yaml):
bytes_written = 0
if type(yaml) is str:
encoded = yaml.encode('utf-8')
sys.stdout.buffer.write(encoded)
sys.stdout.buffer.write(b'\0')
bytes_written = len(encoded) + 1
elif type(yaml) is int:
if yaml > 255 or yaml < 0:
print("integer value ({}) is outside of byte range".format(yaml), file=sys.stderr)
sys.exit(1)
else:
sys.stdout.buffer.write(struct.pack('B', yaml))
bytes_written = 1
elif type(yaml) is list:
for e in yaml:
bytes_written += write_bin_from_yaml(e)
elif type(yaml) is dict:
size = None
content = None
fill = 0xFF
for (k, v) in yaml.items():
if k == 'size':
if type(v) is not int:
print("Block size parameter is not an integer", file=sys.stderr)
sys.exit(1)
size = v
elif k == 'content':
content = v
elif k == 'fill':
if type(v) is not int:
print("Block fill parameter is not an integer", file=sys.stderr)
sys.exit(1)
if v < 0 or v > 255:
print("Fill value is not a byte", file=sys.stderr)
sys.exit(1)
fill = v
else:
print("Dict has unexpected key {}".format(k), file=sys.stderr)
exit(1)
bytes_written = write_block(size, content, fill)
else:
print("Element is not an expected type: {}".format(type(yaml)), file=sys.stderr)
sys.exit(1)
return bytes_written
if __name__ == '__main__':
if len(sys.argv) != 2:
print("Expected a filename parameter")
sys.exit(1)
with open(sys.argv[1], 'r') as yaml_fh:
yaml_obj = yaml.safe_load(yaml_fh)
total_bytes_written = write_bin_from_yaml(yaml_obj)
print("Success - {} bytes written".format(total_bytes_written), file=sys.stderr)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment