Skip to content

Commit

Permalink
Buildupdates (#108)
Browse files Browse the repository at this point in the history
* Zip raw firmware files

* Attempt to speed up builds
  • Loading branch information
echo-lalia authored Aug 24, 2024
1 parent f8f2feb commit d1b780d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 deletions.
21 changes: 12 additions & 9 deletions tools/build_device_bin.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#!/bin/bash

# Check if the board name is provided
if [ -z "$1" ]; then
echo "Usage: $0 <board_name>"
# Check if at least one board name is provided
if [ $# -eq 0 ]; then
echo "Usage: $0 <board_name1> <board_name2> ... <board_nameN>"
exit 1
fi

BOARD_NAME=$1

# Navigate to the esp-idf directory
cd esp-idf || { echo "Failed to enter esp-idf directory"; exit 1; }

Expand All @@ -19,8 +17,13 @@ echo "esp-idf setup done."
# Navigate to the MicroPython esp32 port directory
cd ../MicroPython/ports/esp32 || { echo "Failed to enter MicroPython/ports/esp32 directory"; exit 1; }

# Initialize submodules and build MicroPython for the specified board
make BOARD=${BOARD_NAME} submodules || { echo "Failed to initialize submodules"; exit 1; }
make BOARD=${BOARD_NAME} || { echo "Failed to build MicroPython"; exit 1; }
# Loop through all provided board names and build MicroPython for each
for BOARD_NAME in "$@"
do
echo "Building MicroPython for board: ${BOARD_NAME}"
make BOARD=${BOARD_NAME} submodules || { echo "Failed to initialize submodules for ${BOARD_NAME}"; exit 1; }
make BOARD=${BOARD_NAME} || { echo "Failed to build MicroPython for ${BOARD_NAME}"; exit 1; }
echo "Build complete for board: ${BOARD_NAME}"
done

echo "Build complete for board: ${BOARD_NAME}"
echo "All builds completed."
10 changes: 7 additions & 3 deletions tools/compile_firmwares.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
CWD = os.getcwd()
OG_DIRECTORY = CWD

print(CWD)

if SOURCE_PATH is None:
SOURCE_PATH = os.path.join(CWD, 'MicroPython', 'ports', 'esp32')
Expand All @@ -56,12 +57,15 @@ def main():
if filepath != 'default.yml':
devices.append(Device(filepath))

# Run build script, passing each target device name.
print(f"{bcolors.OKBLUE}Running builds for {', '.join([device.name.title() for device in devices])}...{bcolors.ENDC}")
subprocess.call([os.path.join('tools', 'build_device_bin.sh')] + [device.name for device in devices])

# Rename/move firmware bins for each device.
for device in devices:
print(f"{bcolors.OKBLUE}Building for {device.name.title()}...{bcolors.ENDC}")
subprocess.call(["tools/build_device_bin.sh", device.name])
os.chdir(OG_DIRECTORY)


print(f'{bcolors.OKBLUE}Extracting "{device.name}.bin"...{bcolors.ENDC}')
os.rename(
os.path.join(SOURCE_PATH, f'build-{device.name}', 'firmware.bin'),
os.path.join(OG_DIRECTORY, 'MicroHydra', f'{device.name}.bin'),
Expand Down
4 changes: 2 additions & 2 deletions tools/microhydra_build_all.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# Run file parsing script to create device-specific python files
python3 tools/parse_files.py
python3 tools/parse_files.py --zip --verbose

# build mpy-cross so we can compile .mpy files
python3 tools/build_mpy_cross.py
Expand All @@ -18,7 +18,7 @@ python3 tools/setup_esp_idf.py
python3 tools/create_frozen_folders.py

# Run file parsing script for frozen device folders
python3 tools/parse_files.py --frozen
python3 tools/parse_files.py --frozen --verbose

# now run script to build each device
python3 tools/compile_firmwares.py
Expand Down
16 changes: 12 additions & 4 deletions tools/parse_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import yaml
import argparse
import re
# from pathlib import Path
import shutil
import time


Expand All @@ -66,12 +66,14 @@
PARSER.add_argument('-D', '--devices', help='Path to device definition folder.')
PARSER.add_argument('-d', '--dest', help='Destination path for parsed MicroHydra files.')
PARSER.add_argument('-v', '--verbose', action='store_true')
PARSER.add_argument('-z', '--zip', action='store_true', help='Put output device files into zip archives.')
PARSER.add_argument('--frozen', action='store_true')
SCRIPT_ARGS = PARSER.parse_args()

SOURCE_PATH = SCRIPT_ARGS.source
DEVICE_PATH = SCRIPT_ARGS.devices
DEST_PATH = SCRIPT_ARGS.dest
ZIP = SCRIPT_ARGS.zip
FROZEN = SCRIPT_ARGS.frozen
VERBOSE = SCRIPT_ARGS.verbose

Expand Down Expand Up @@ -144,9 +146,6 @@ def main():
# unsupported files should just be copied instead.
vprint(f" {bcolors.OKCYAN}copying directly...{bcolors.ENDC}")
file_parser.save_unparsable_file(DEST_PATH, device)

# TODO: Add ability to copy to additional "frozen" folder.
# this way, a separate script can compile and freeze the device specific code.

# for each device, copy device-specific source files to output folder
for device in devices:
Expand All @@ -158,6 +157,15 @@ def main():
file_parser.save_unparsable_file(DEST_PATH, device)
device.create_device_module(DEST_PATH)

# when --zip is specified, also put device files into a zip archive.
if ZIP:
for device in devices:
shutil.make_archive(
os.path.join('MicroHydra', f"{device.name}_raw"),
'zip',
os.path.join('MicroHydra', device.name),
)


print_completed()

Expand Down

0 comments on commit d1b780d

Please sign in to comment.