Skip to content

Commit

Permalink
Merge pull request #82 from jakkra/flash_loader_boot_selection
Browse files Browse the repository at this point in the history
Support placing LVGL resourses in the external SPI Flash. Uploading u…
  • Loading branch information
jakkra authored Oct 17, 2023
2 parents f23a4b3 + 077da9b commit a17b763
Show file tree
Hide file tree
Showing 32 changed files with 1,478 additions and 89 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ build*
# Built Visual Studio Code Extensions
*.vsix

*.bin

# Zephyr workspace
/.west
/bootloader
Expand Down
17 changes: 17 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Upload Raw FS",
"type": "shell",
"command": "west upload_fs --type raw"
},
{
"label": "Upload LittleFS",
"type": "shell",
"command": "west upload_fs --type lfs"
}
]
}
4 changes: 3 additions & 1 deletion app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ target_sources(app PRIVATE src/ui/notification/zsw_popup_notifcation.c)
target_sources(app PRIVATE src/ui/popup/zsw_popup_window.c)
target_sources(app PRIVATE src/ui/utils/zsw_ui_utils.c)

target_sources(app PRIVATE src/zsw_flash.c)
target_sources_ifdef(CONFIG_SPI_FLASH_LOADER app PRIVATE src/zsw_rtt_flash_loader.c)
target_sources_ifdef(CONFIG_FILE_SYSTEM_LITTLEFS app PRIVATE src/zsw_filesystem.c)
target_sources_ifdef(CONFIG_FILE_SYSTEM_LITTLEFS app PRIVATE src/zsw_lvgl_spi_decoder.c)

if (DFU_BUILD)
target_sources(app PRIVATE src/dfu.c)
Expand Down
32 changes: 30 additions & 2 deletions app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ menu "ZSWatch"
config APPLICATIONS_USE_QR_CODE
bool
prompt "Activate the application 'QR-Code'"
default n
default y if LV_Z_USE_FILESYSTEM

config APPLICATIONS_USE_X_RAY
bool
prompt "Activate the application 'X-Ray'"
default n
default y if LV_Z_USE_FILESYSTEM

config APPLICATIONS_USE_ZDS
bool
Expand Down Expand Up @@ -94,6 +94,34 @@ menu "ZSWatch"

endmenu

menu "SPI RTT Flash Loader"
config SPI_FLASH_LOADER
bool
prompt "Enable SPI flash loader"
default y
select USE_SEGGER_RTT
#select SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
help
"Enable SPI flash loader"
if SPI_FLASH_LOADER
config ERASE_PROGRESSIVELY
bool
depends on SPI_FLASH_LOADER
prompt "Erase sectors one by one when writing instead of full partition before starting."
default y
help
"If not writing to the full partition this will be faster"

config RTT_TRANSFER_CHANNEL
int
depends on SPI_FLASH_LOADER
prompt "The RTT channel to use for transfer of data to and form flash"
default 2
help
"If RTT logging is enabled, channel 0 is used for this, hence avoid 1 in this scenario."
endif
endmenu

rsource "drivers/Kconfig"

module = APP
Expand Down
53 changes: 43 additions & 10 deletions app/boards/arm/zswatch_nrf5340/zswatch_nrf5340_common.dts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
zephyr,bt-hci-rpmsg-ipc = &ipc0;
zephyr,ieee802154 = &ieee802154;
zephyr,display = &gc9a01;
//zephyr,keyboard-scan = &cst816s;
};

vbatt {
Expand All @@ -38,11 +37,11 @@
};

lvgl_pointer {
compatible = "zephyr,lvgl-pointer-input";
input = <&cst816s>;
compatible = "zephyr,lvgl-pointer-input";
input = <&cst816s>;
swap-xy;
invert-x;
};
invert-x;
};

aliases {
display-blk = &display_blk;
Expand Down Expand Up @@ -133,11 +132,11 @@
pinctrl-names = "default", "sleep";

cst816s: cst816s@15 {
compatible = "hynitron,cst816s";
reg = <0x15>;
irq-gpios = <&gpio1 0 GPIO_ACTIVE_LOW>;
rst-gpios = <&gpio0 20 GPIO_ACTIVE_LOW>;
};
compatible = "hynitron,cst816s";
reg = <0x15>;
irq-gpios = <&gpio1 0 GPIO_ACTIVE_LOW>;
rst-gpios = <&gpio0 20 GPIO_ACTIVE_LOW>;
};
};

/* UART0 GPIOs can be configured for other use-cases */
Expand Down Expand Up @@ -220,5 +219,39 @@ zephyr_udc0: &usbd {
};
};

/ {
sram@2007FFFF {
compatible = "zephyr,memory-region", "mmio-sram";
reg = <0x2007FFFF 0x1>;
zephyr,memory-region = "RetainedMem";
status = "okay";

retainedmem {
compatible = "zephyr,retained-ram";
status = "okay";
#address-cells = <1>;
#size-cells = <1>;

retention0: retention@0 {
compatible = "zephyr,retention";
status = "okay";
reg = <0x0 0x1>;
};
};
};

chosen {
zephyr,boot-mode = &retention0;
};
};

/* Reduce SRAM0 usage by 4 byte to account for non-init area
* Even though boot mode is only one byte, nrfjprog only allows
* 4 byte writes, hence reserve 4.
*/
&sram0 {
reg = <0x20000000 0x7FFFC>;
};

/* Include partition configuration file */
#include "zswatch_nrf5340_partition_conf.dts"
13 changes: 11 additions & 2 deletions app/boards/arm/zswatch_nrf5340/zswatch_nrf5340_cpuapp_3.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,14 @@ CONFIG_SPI_NOR_SFDP_RUNTIME=y
CONFIG_SPI_NOR_IDLE_IN_DPD=y
CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096

# DIsplay RST is connected to NFC GPIO
CONFIG_NFCT_PINS_AS_GPIOS=y
# Display RST is connected to NFC GPIO
CONFIG_NFCT_PINS_AS_GPIOS=y

CONFIG_MPU_ALLOW_FLASH_WRITE=y

CONFIG_FILE_SYSTEM=y
CONFIG_FILE_SYSTEM_LITTLEFS=y
CONFIG_LV_Z_USE_FILESYSTEM=y
CONFIG_LV_IMG_CACHE_DEF_SIZE=10

CONFIG_FS_LITTLEFS_FC_HEAP_SIZE=16384
39 changes: 39 additions & 0 deletions app/boards/arm/zswatch_nrf5340/zswatch_nrf5340_cpuapp_3.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
/ {
chosen {
nordic,pm-ext-flash = &at25sl128a;
zephyr,settings-partition = &settings_partition;
};

aliases {
Expand Down Expand Up @@ -144,4 +145,42 @@
t-exit-dpd = <3000>;
};

};

/ {
fstab {
compatible = "zephyr,fstab";
lvgl_lfs: lvgl_lfs {
compatible = "zephyr,fstab,littlefs";
mount-point = "/lvgl_lfs";
partition = <&lvgl_lfs_partition>;
automount;
read-size = <1024>;
prog-size = <512>;
cache-size = <4096>;
lookahead-size = <4096>;
block-cycles = <512>;
};
};
};

&at25sl128a {
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;

lvgl_lfs_partition: partition@0 {
label = "lvgl_lfs_partition";
reg = <0x00000000 0x00200000>;
};
lvgl_raw_partition: partition@200000 {
label = "lvgl_raw_partition";
reg = <0x00200000 0x00200000>;
};
settings_partition: partition@400000 {
label = "settings_partition";
reg = <0x400000 0x100000 >;
};
};
};
2 changes: 2 additions & 0 deletions app/boards/native_posix.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ CONFIG_MAX30101=n
CONFIG_APDS9306=n
CONFIG_APDS9306_IS_APDS9306_065=n
CONFIG_MAX30101_MULTI_LED_MODE=n
CONFIG_APDS9306=n
CONFIG_PINCTRL=n

CONFIG_SPI=n
Expand All @@ -42,3 +43,4 @@ CONFIG_LOG_PRINTK=y
CONFIG_LOG=y
CONFIG_DEBUG_OPTIMIZATIONS=y

CONFIG_SPI_FLASH_LOADER=n
7 changes: 6 additions & 1 deletion app/prj.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CONFIG_LV_Z_MEM_POOL_NUMBER_BLOCKS=8
CONFIG_MAIN_STACK_SIZE=1024
CONFIG_MAIN_STACK_SIZE=2048
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096
CONFIG_HEAP_MEM_POOL_SIZE=25000
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
Expand All @@ -10,6 +10,10 @@ CONFIG_REBOOT=y
CONFIG_DISPLAY=y
CONFIG_BASE64=y

CONFIG_RETAINED_MEM=y
CONFIG_RETENTION=y
CONFIG_RETENTION_BOOT_MODE=y

CONFIG_I2C=y
CONFIG_SENSOR=y
CONFIG_ADC=y
Expand Down Expand Up @@ -110,6 +114,7 @@ CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP_LABELS=y

# Filesystem
#CONFIG_FILE_SYSTEM=y
Expand Down
90 changes: 90 additions & 0 deletions app/scripts/create_custom_resource_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import os
import argparse
from struct import *

MAX_FILE_NAME = 16
FILE_TABLE_MAX_LEN = 1024
"""
magic_number:uint32
header_len:uint32
total_length:uint32
num_files:uint32
filename[MAX_FILE_NAME + 1]
offset:uint32
len:uint32
filename[MAX_FILE_NAME + 1]
offset:uint32
len:uint32
...
"""


def create_custom_raw_fs_image(img_filename, source_dir, block_size=4096):
table = {}
offset = 0
files_image = bytearray()
header_images = bytearray()
for root, dirs, files in os.walk(source_dir):
print(f"root {root} dirs {dirs} files {files}")
for filename in files:
path = os.path.join(root, filename)
relpath = os.path.relpath(path, start=source_dir)
print(f"Adding {path}")
with open(path, "rb") as infile:
files_image.extend(infile.read())
table[filename] = {"offset": offset, "len": infile.tell()}
offset = offset + infile.tell()
print(table)
for name, data in table.items():
if len(name) <= MAX_FILE_NAME:
header_images = header_images + pack(
f"<{MAX_FILE_NAME}sII",
bytes(name, "utf-8"),
data["offset"],
data["len"],
)
else:
print("Filename to long, skipping", name, len(name))

# Insert dummy values as header length and total length so we can get the size of the header
fake_header = header_image = (
pack("<IIII", 0x0A0A0A0A, len(table), 0, 0) + header_images
)
print("header len", len(fake_header))
real_header = (
pack(
"<IIII",
0x0A0A0A0A,
len(fake_header),
len(fake_header) + len(files_image),
len(table),
)
+ header_images
)

if len(header_images) > FILE_TABLE_MAX_LEN:
print(
"File table is to big, increase the size on target size",
FILE_TABLE_MAX_LEN,
"<",
len(header_images),
)
exit(1)
# Add header length
with open(img_filename, "wb") as f:
f.write(real_header)
f.write(files_image)


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--img-filename", default="littlefs.img")
parser.add_argument("--block-size", type=int, default=4096)
parser.add_argument("source")
args = parser.parse_args()

img_filename = args.img_filename
block_size = args.block_size
source_dir = args.source

create_custom_raw_fs_image(img_filename, source_dir, block_size)
Loading

0 comments on commit a17b763

Please sign in to comment.