Skip to content

Commit

Permalink
Use JSON for IFS build configuration, with schema (#2219)
Browse files Browse the repository at this point in the history
Replaces existing .ini file, consistent with Storage config, more structured.
  • Loading branch information
mikee47 authored Feb 16, 2021
1 parent d5a78b0 commit ffa376e
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 36 deletions.
3 changes: 3 additions & 0 deletions Sming/Components/Storage/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Hardware configuration
Each project has an associated ``Hardware configuration``, specified by the :envvar:`HWCONFIG` setting:
this is a JSON file with a ``.hw`` extension.

For user convenience, the configuration file may contain comments however these are stripped before
processing.

The build system locates the file by searching, in order:

- ``{PROJECT_DIR}`` the root project directory
Expand Down
4 changes: 3 additions & 1 deletion Sming/Components/Storage/Tools/hwconfig/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os, partition, storage
from common import *
from builtins import classmethod
from rjsmin import jsmin

def findConfig(name):
dirs = os.environ['HWCONFIG_DIRS'].split(' ')
Expand Down Expand Up @@ -32,7 +33,8 @@ def from_name(cls, name):
def load(self, name):
filename = findConfig(name)
self.depends.append(filename)
data = json.load(open(filename))
din = open(filename).read()
data = json.loads(jsmin(din))
self.parse_dict(data)

def parse_dict(self, data):
Expand Down
1 change: 0 additions & 1 deletion Sming/Components/Storage/Tools/hwconfig/hwconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def main():
# Validate resulting hardware configuration against schema
try:
from jsonschema import Draft7Validator
from jsonschema.exceptions import ValidationError
except ImportError:
critical("hwconfig: `jsonschema` is not installed. Please run `make python-requirements`")
sys.exit(1)
Expand Down
1 change: 1 addition & 0 deletions Sming/Components/Storage/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
jsonschema
rjsmin
1 change: 1 addition & 0 deletions Tools/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pyserial
jsonschema
rjsmin
2 changes: 1 addition & 1 deletion samples/Basic_IFS/basic_ifs.hw
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"filename": "out/fwfs1.bin",
"build": {
"target": "fwfs-build",
"config": "fsimage.ini"
"config": "fsimage.fwfs"
}
}
}
Expand Down
71 changes: 71 additions & 0 deletions samples/Basic_IFS/fsimage.fwfs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Filesystem builder configuration
{
"name": "Sming IFS demo volume",
"id": "0x12345678",
// Where to read files from
"source": {
"/": "files",
"README.rst": "README.rst",
"test.jsonc": "basic_ifs.hw",
"readme.md": "${SMING_HOME}/Components/IFS/README.rst",
"sming.png": "${SMING_HOME}/../docs/api-logo.png",
"Data": "${SMING_HOME}/Core/Data",
"framework": "${SMING_HOME}/../docs/source/framework",
"Sming": "${SMING_HOME}/Core"
},
// Directories to mount other object stores
"mountpoints": {
"config": 1
},
// Rules for file metadata. All rules are evaluated in sequence for every file
"rules": [
{
"mask": "*",
"read": "guest",
"write": "admin"
},
{
"mask": ".*",
"read": "admin"
},
{
"mask": "*.html",
"readonly": true
},
{
"mask": [
"*.js",
"*.png",
"*.ico",
"*.jpg",
"*.jpeg",
"*.html",
"*.css",
"*.txt",
"*.md"
],
"compress": "gzip"
},
{
"mask": [
"/styles.css",
"*.ico",
"*.png"
],
"read": "any"
},
{
"mask": [
"/Data/*",
"/framework/*",
"/Sming/*"
],
"compress": "gzip"
},
//This is a template file so firmware needs to read it
{
"mask": "/error.html",
"compress": "none"
}
]
}
32 changes: 0 additions & 32 deletions samples/Basic_IFS/fsimage.ini

This file was deleted.

6 changes: 6 additions & 0 deletions samples/Basic_Storage/basic_storage.hw
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
"name": "Basic Storage sample",
"base_config": "spiffs",
"devices": {
// Override default (conservative) flash settings for maximum performance
"spiFlash": {
"mode": "qio",
"speed": 80
}
},
"partitions": {
// User-defined partition type
"user0": {
"address": "0x1F0000",
"size": "16K",
Expand All @@ -21,12 +23,15 @@
"type": "user",
"subtype": 1
},
// Override default SPIFFS partition with new address and source content
"spiffs0": {
"address": "0x200000",
"build": {
// target is already defined, just change the folder to pick up files from
"files": "files/spiffs0"
}
},
// Add a second SPIFFS partition
"spiffs1": {
"address": "0x280000",
"size": "256K",
Expand All @@ -38,6 +43,7 @@
"files": "files/spiffs1"
}
},
// And a third
"spiffs2": {
"address": "0x2C0000",
"size": "256K",
Expand Down

0 comments on commit ffa376e

Please sign in to comment.