Skip to content

Commit

Permalink
Add hardware profile 'option' support
Browse files Browse the repository at this point in the history
Allow options to be set using `HWCONFIG_OPTS` or in configuration
Show HWCONFIG setting with options when showing partition map
  • Loading branch information
mikee47 committed Mar 14, 2021
1 parent 50366cf commit 3fd7227
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 25 deletions.
10 changes: 10 additions & 0 deletions Sming/Arch/Esp8266/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"vdd": {
"description": "Modify PHY configuration to support `system_get_vdd33()` function",
"partitions": {
"phy_init": {
"filename": "$(FLASH_INIT_DATA_VCC)"
}
}
}
}
28 changes: 27 additions & 1 deletion Sming/Components/Storage/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,25 @@ or, to show the partition map::

Then either run ``make HWCONFIG=standard-4m`` or ``make config-clean``.

.. _hwconfig_options:

Hardware configuration options
------------------------------

Commonly used settings can be stored in an option library for easier use.
The library files are named ``options.json`` and located in the place as .hw files.

For example, we can do this::

make HWCONFIG=standard HWCONFIG_OPTS=4m,spiffs

This loads the 'standard' profile then merges the fragments found in the option library with the given names.
This is how the ``standard-4m`` profile is constructed.

If using this approach, remember to updated your project's ``component.mk`` with the desired settings,
and verify the layout is correct using ``make map``.



Custom configurations
---------------------
Expand All @@ -77,10 +96,12 @@ To customise the hardware configuration for a project, for example 'my_project':
{
"name": "My project config",
"base_config": "spiffs"
"base_config": "spiffs",
"options": ["vdd"]
}
You can use any available configuration as the base_config.
Option fragments can be pulled in as shown. See :ref:`hwconfig_options`.


2. If required, modify any inherited settings:
Expand Down Expand Up @@ -255,6 +276,11 @@ Configuration
(or ``make config-clean`` to reset everything).


.. envvar:: HWCONFIG_OPTS

Set this to adjust the hardware profile using option fragments. See :ref:`hwconfig_options`.


Binary partition table
----------------------

Expand Down
32 changes: 31 additions & 1 deletion Sming/Components/Storage/Tools/hwconfig/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@
# Configuration object
#

import os, partition, storage
import os, partition, storage, copy
from rjsmin import jsmin
from common import *
from builtins import classmethod

def load_option_library():
library = {}
dirs = os.environ['HWCONFIG_DIRS'].split(' ')
for d in dirs:
filename = fixpath(d) + '/options.json'
if os.path.exists(filename):
with open(filename) as f:
data = json.loads(jsmin(f.read()))
library.update(data)
return library

def findConfig(name):
dirs = os.environ['HWCONFIG_DIRS'].split(' ')
for d in dirs:
Expand All @@ -20,6 +31,8 @@ def __init__(self):
self.partitions = partition.Table()
self.devices = storage.List()
self.depends = []
self.options = []
self.option_library = load_option_library()

def __str__(self):
return "'%s' for %s" % (self.name, self.arch)
Expand All @@ -30,6 +43,9 @@ def from_name(cls, name):
"""
config = Config()
config.load(name)
options = os.environ.get('HWCONFIG_OPTS', '').replace(' ', '')
if options != '':
config.parse_options(options.split(','))
return config

def load(self, name):
Expand All @@ -41,6 +57,20 @@ def load(self, name):
data = json.loads(jsmin(f.read()))
self.parse_dict(data)

def parse_options(self, options):
"""Apply any specified options, each option is applied only once
"""
for option in options:
if not hasattr(self.options, option):
self.options += option
data = self.option_library.get(option)
if data is None:
raise InputError("Option '%s' undefined" % option)
# Don't modify library entries
temp = copy.deepcopy(data)
temp.pop('description', None)
self.parse_dict(temp)

def parse_dict(self, data):
base_config = data.pop('base_config', None)
if base_config is not None:
Expand Down
12 changes: 10 additions & 2 deletions Sming/Components/Storage/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ COMPONENT_INCDIRS := src/include
COMPONENT_SRCDIRS := src
COMPONENT_DOXYGEN_INPUT := src/include

CONFIG_VARS += HWCONFIG
CONFIG_VARS += HWCONFIG HWCONFIG_OPTS
ifndef HWCONFIG
override HWCONFIG := standard
$(info Using configuration '$(HWCONFIG)')
Expand Down Expand Up @@ -31,6 +31,7 @@ PARTITION_PATH := $(COMPONENT_PATH)
PARTITION_TOOLS := $(PARTITION_PATH)/Tools
HWCONFIG_TOOL := \
HWCONFIG_DIRS="$(HWCONFIG_DIRS)" \
HWCONFIG_OPTS="$(HWCONFIG_OPTS)" \
BUILD_BASE=$(BUILD_BASE) \
$(PYTHON) $(PARTITION_TOOLS)/hwconfig/hwconfig.py

Expand Down Expand Up @@ -59,7 +60,7 @@ endef

.PHONY: map
map: $(HWCONFIG_PATH) ##Show partition map
@echo "Partition map:"
@echo "Partition map: $(HWCONFIG), $(if $(HWCONFIG_OPTS),options: $(HWCONFIG_OPTS),no options)"
$(Q) $(HWEXPR) "config.map().to_csv()"
@echo

Expand All @@ -81,6 +82,13 @@ hwconfig-list: ##List available hardware configurations
@echo "Available configurations: $(foreach c,$(ALL_HWCONFIG),\n $(if $(subst $c,,$(HWCONFIG)), ,*) $(shell printf "%-25s" "$c") $(filter %/$c.hw,$(ALL_HWCONFIG_PATHS)))"
@echo

.PHONY: hwconfig-options
hwconfig-options: ##List available hardware configuration options
@echo
@echo "Available options (use with HWCONFIG_OPTS or in custom profile):"
$(Q) $(HWEXPR) "''.join((' %-10s %s\n' % (k, v['description']) for k, v in config.option_library.items()))"
@echo

.PHONY: hwconfig-validate
hwconfig-validate: $(HWCONFIG_PATH) ##Validate current hardware configuration
@echo "Validating hardware config '$(HWCONFIG)'"
Expand Down
10 changes: 8 additions & 2 deletions Sming/Components/Storage/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
"title": "Base configuration",
"description": "Inherit a previously-defined configuration"
},
"options": {
"type": "array",
"title": "List of option fragments",
"description": "Import additional settings from option libraries"
},
"comment": {
"type": "string"
},
Expand All @@ -26,7 +31,7 @@
},
"partition_table_offset": {
"type": "string",
"description": "Location of partition table in spiFlash"
"description": "Location of partition table in spiFlash. Simple address or python expression to be evaluated."
},
"devices": {
"$ref": "#/definitions/Devices"
Expand Down Expand Up @@ -116,7 +121,8 @@
"type": [
"string",
"integer"
]
],
"description": "Starting address for partition. Simple address or python expression to be evaluated."
},
"size": {
"type": [
Expand Down
26 changes: 26 additions & 0 deletions Sming/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"4m": {
"description": "Set Flash size to 4MByte",
"devices": {
"spiFlash": {
"size": "4M"
}
}
},
"spiffs": {
"description": "Add standard SPIFFS partition",
"partitions": {
"spiffs0": {
"address": "0x200000",
"size": "512K",
"type": "data",
"subtype": "spiffs",
"filename": "$(SPIFF_BIN_OUT)",
"build": {
"target": "spiffsgen",
"files": "$(SPIFF_FILES)"
}
}
}
}
}
16 changes: 3 additions & 13 deletions Sming/spiffs.hw
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
{
"name": "Single SPIFFS partition",
"base_config": "standard-4m",
"partitions": {
"spiffs0": {
"address": "0x200000",
"size": "512K",
"type": "data",
"subtype": "spiffs",
"filename": "$(SPIFF_BIN_OUT)",
"build": {
"target": "spiffsgen",
"files": "$(SPIFF_FILES)"
}
}
}
"options": [
"spiffs"
]
}
10 changes: 4 additions & 6 deletions Sming/standard-4m.hw
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
"name": "Standard config with 4M flash",
"base_config": "standard",
"devices": {
"spiFlash": {
"size": "4M"
}
}
}
"options": [
"4m"
]
}
2 changes: 2 additions & 0 deletions docs/source/upgrading/4.2-4.3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ New and updated build targets
Displays the current configuration in JSON format
hwconfig-list
Show available hardware configs
hwconfig-options
Show available hardware configuration options
map
Display the current flash memory map
readmap
Expand Down

0 comments on commit 3fd7227

Please sign in to comment.