s/STORAGE_/USER_CONFIG_/

more address define renames to make an upcoming feature clearer

Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
This commit is contained in:
Brian S. Stephan 2024-01-03 18:25:03 -06:00
parent 8681a18d26
commit 05228b9f62
Signed by: bss
GPG Key ID: 3DE06D3180895FCB
3 changed files with 16 additions and 16 deletions

View File

@ -12,7 +12,7 @@ from google.protobuf.message import Message
from gp2040ce_bintools import core_parser from gp2040ce_bintools import core_parser
from gp2040ce_bintools.rp2040 import get_bootsel_endpoints, read, write from gp2040ce_bintools.rp2040 import get_bootsel_endpoints, read, write
from gp2040ce_bintools.storage import (STORAGE_BINARY_LOCATION, STORAGE_BOOTSEL_ADDRESS, STORAGE_SIZE, from gp2040ce_bintools.storage import (STORAGE_SIZE, USER_CONFIG_BINARY_LOCATION, USER_CONFIG_BOOTSEL_ADDRESS,
get_config_from_json, pad_config_to_storage_size, serialize_config_with_footer) get_config_from_json, pad_config_to_storage_size, serialize_config_with_footer)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -106,13 +106,13 @@ def pad_binary_up_to_user_config(firmware: bytes, or_truncate: bool = False) ->
Raises: Raises:
FirmwareLengthError: if the firmware is larger than the storage location FirmwareLengthError: if the firmware is larger than the storage location
""" """
bytes_to_pad = STORAGE_BINARY_LOCATION - len(firmware) bytes_to_pad = USER_CONFIG_BINARY_LOCATION - len(firmware)
logger.debug("firmware is length %s, padding %s bytes", len(firmware), bytes_to_pad) logger.debug("firmware is length %s, padding %s bytes", len(firmware), bytes_to_pad)
if bytes_to_pad < 0: if bytes_to_pad < 0:
if or_truncate: if or_truncate:
return bytearray(firmware[0:STORAGE_BINARY_LOCATION]) return bytearray(firmware[0:USER_CONFIG_BINARY_LOCATION])
raise FirmwareLengthError(f"provided firmware binary is larger than the start of " raise FirmwareLengthError(f"provided firmware binary is larger than the start of "
f"storage at {STORAGE_BINARY_LOCATION}!") f"storage at {USER_CONFIG_BINARY_LOCATION}!")
return bytearray(firmware) + bytearray(b'\x00' * bytes_to_pad) return bytearray(firmware) + bytearray(b'\x00' * bytes_to_pad)
@ -130,13 +130,13 @@ def replace_config_in_binary(board_binary: bytearray, config_binary: bytearray)
Returns: Returns:
the resulting correctly-offset binary suitable for a GP2040-CE board the resulting correctly-offset binary suitable for a GP2040-CE board
""" """
if len(board_binary) < STORAGE_BINARY_LOCATION + STORAGE_SIZE: if len(board_binary) < USER_CONFIG_BINARY_LOCATION + STORAGE_SIZE:
# this is functionally the same, since this doesn't sanity check the firmware # this is functionally the same, since this doesn't sanity check the firmware
return combine_firmware_and_config(board_binary, config_binary) return combine_firmware_and_config(board_binary, config_binary)
else: else:
new_binary = bytearray(copy.copy(board_binary)) new_binary = bytearray(copy.copy(board_binary))
new_config = pad_config_to_storage_size(config_binary) new_config = pad_config_to_storage_size(config_binary)
new_binary[STORAGE_BINARY_LOCATION:(STORAGE_BINARY_LOCATION + STORAGE_SIZE)] = new_config new_binary[USER_CONFIG_BINARY_LOCATION:(USER_CONFIG_BINARY_LOCATION + STORAGE_SIZE)] = new_config
return new_binary return new_binary
@ -183,7 +183,7 @@ def write_new_config_to_usb(config: Message, endpoint_out: object, endpoint_in:
logger.debug("length: %s with %s bytes of padding", len(serialized), padding) logger.debug("length: %s with %s bytes of padding", len(serialized), padding)
binary = bytearray(b'\x00' * padding) + serialized binary = bytearray(b'\x00' * padding) + serialized
logger.debug("binary for writing: %s", binary) logger.debug("binary for writing: %s", binary)
write(endpoint_out, endpoint_in, STORAGE_BOOTSEL_ADDRESS + (STORAGE_SIZE - len(binary)), bytes(binary)) write(endpoint_out, endpoint_in, USER_CONFIG_BOOTSEL_ADDRESS + (STORAGE_SIZE - len(binary)), bytes(binary))
############ ############

View File

@ -22,7 +22,7 @@ from textual.widgets.tree import TreeNode
from gp2040ce_bintools import core_parser, handler from gp2040ce_bintools import core_parser, handler
from gp2040ce_bintools.builder import write_new_config_to_filename, write_new_config_to_usb from gp2040ce_bintools.builder import write_new_config_to_filename, write_new_config_to_usb
from gp2040ce_bintools.rp2040 import get_bootsel_endpoints, read from gp2040ce_bintools.rp2040 import get_bootsel_endpoints, read
from gp2040ce_bintools.storage import (STORAGE_BOOTSEL_ADDRESS, STORAGE_SIZE, ConfigReadError, get_config, from gp2040ce_bintools.storage import (STORAGE_SIZE, USER_CONFIG_BOOTSEL_ADDRESS, ConfigReadError, get_config,
get_config_from_file, get_new_config) get_config_from_file, get_new_config)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -324,7 +324,7 @@ class ConfigEditor(App):
if self.usb: if self.usb:
try: try:
self.endpoint_out, self.endpoint_in = get_bootsel_endpoints() self.endpoint_out, self.endpoint_in = get_bootsel_endpoints()
config_binary = read(self.endpoint_out, self.endpoint_in, STORAGE_BOOTSEL_ADDRESS, STORAGE_SIZE) config_binary = read(self.endpoint_out, self.endpoint_in, USER_CONFIG_BOOTSEL_ADDRESS, STORAGE_SIZE)
self.config = get_config(bytes(config_binary)) self.config = get_config(bytes(config_binary))
except ConfigReadError: except ConfigReadError:
if self.create_new: if self.create_new:

View File

@ -16,8 +16,8 @@ from gp2040ce_bintools.rp2040 import get_bootsel_endpoints, read
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
STORAGE_BINARY_LOCATION = 0x1FC000 USER_CONFIG_BINARY_LOCATION = 0x1FC000
STORAGE_BOOTSEL_ADDRESS = 0x10000000 + STORAGE_BINARY_LOCATION USER_CONFIG_BOOTSEL_ADDRESS = 0x10000000 + USER_CONFIG_BINARY_LOCATION
STORAGE_SIZE = 16384 STORAGE_SIZE = 16384
FOOTER_SIZE = 12 FOOTER_SIZE = 12
@ -158,7 +158,7 @@ def get_config_from_usb() -> tuple[Message, object, object]:
endpoint_out, endpoint_in = get_bootsel_endpoints() endpoint_out, endpoint_in = get_bootsel_endpoints()
logger.debug("reading DEVICE ID %s:%s, bus %s, address %s", hex(endpoint_out.device.idVendor), logger.debug("reading DEVICE ID %s:%s, bus %s, address %s", hex(endpoint_out.device.idVendor),
hex(endpoint_out.device.idProduct), endpoint_out.device.bus, endpoint_out.device.address) hex(endpoint_out.device.idProduct), endpoint_out.device.bus, endpoint_out.device.address)
storage = read(endpoint_out, endpoint_in, STORAGE_BOOTSEL_ADDRESS, STORAGE_SIZE) storage = read(endpoint_out, endpoint_in, USER_CONFIG_BOOTSEL_ADDRESS, STORAGE_SIZE)
return get_config(bytes(storage)), endpoint_out, endpoint_in return get_config(bytes(storage)), endpoint_out, endpoint_in
@ -174,12 +174,12 @@ def get_storage_section(content: bytes) -> bytes:
""" """
# a whole board must be at least as big as the known fences # a whole board must be at least as big as the known fences
logger.debug("length of content to look for storage in: %s", len(content)) logger.debug("length of content to look for storage in: %s", len(content))
if len(content) < STORAGE_BINARY_LOCATION + STORAGE_SIZE: if len(content) < USER_CONFIG_BINARY_LOCATION + STORAGE_SIZE:
raise ConfigLengthError("provided content is not large enough to have a storage section!") raise ConfigLengthError("provided content is not large enough to have a storage section!")
logger.debug("returning bytes from %s to %s", hex(STORAGE_BINARY_LOCATION), logger.debug("returning bytes from %s to %s", hex(USER_CONFIG_BINARY_LOCATION),
hex(STORAGE_BINARY_LOCATION + STORAGE_SIZE)) hex(USER_CONFIG_BINARY_LOCATION + STORAGE_SIZE))
return content[STORAGE_BINARY_LOCATION:(STORAGE_BINARY_LOCATION + STORAGE_SIZE)] return content[USER_CONFIG_BINARY_LOCATION:(USER_CONFIG_BINARY_LOCATION + STORAGE_SIZE)]
def get_new_config() -> Message: def get_new_config() -> Message: