-
-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from jakkra/flash_loader_boot_selection
Support placing LVGL resourses in the external SPI Flash. Uploading u…
- Loading branch information
Showing
32 changed files
with
1,478 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,8 +16,6 @@ build* | |
# Built Visual Studio Code Extensions | ||
*.vsix | ||
|
||
*.bin | ||
|
||
# Zephyr workspace | ||
/.west | ||
/bootloader | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.