Skip to content

Commit

Permalink
Simpler build, less dependencies (#827)
Browse files Browse the repository at this point in the history
* Simpler build, less dependencies
* Follow ugly python linter
* Introduce Brewfile & Update Readme
* Make dist.sh target-specific
* Tidy up make output
* Get rid of cat and truncate (I still love cats tho)
* Suppress dd output
* Long live the cat
  • Loading branch information
anna-oake authored Nov 18, 2021
1 parent cc044c5 commit 4303945
Show file tree
Hide file tree
Showing 15 changed files with 261 additions and 186 deletions.
98 changes: 4 additions & 94 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,66 +67,19 @@ jobs:
fi
echo "WORKFLOW_BRANCH_OR_TAG=${BRANCH_OR_TAG}" >> $GITHUB_ENV
echo "DIST_SUFFIX=${SUFFIX}" >> $GITHUB_ENV
echo "::set-output name=artifacts-path::${BRANCH_OR_TAG}"
echo "::set-output name=suffix::${SUFFIX}"
echo "::set-output name=short-hash::${SHA}"
echo "::set-output name=default-target::${DEFAULT_TARGET}"
- name: 'Build bootloader in docker'
- name: 'Build the firmware in docker'
uses: ./.github/actions/docker
with:
run: |
for TARGET in ${TARGETS}
do
make -j$(nproc) -C bootloader TARGET=${TARGET}
done
- name: 'Build firmware in docker'
uses: ./.github/actions/docker
with:
run: |
for TARGET in ${TARGETS}
do
make -j$(nproc) -C firmware TARGET=${TARGET}
done
- name: 'Generate full hex file'
if: ${{ !github.event.pull_request.head.repo.fork }}
uses: ./.github/actions/docker
with:
run: |
for TARGET in ${TARGETS}
do
srec_cat \
bootloader/.obj/${TARGET}/bootloader.hex -Intel \
firmware/.obj/${TARGET}/firmware.hex -Intel \
-o firmware/.obj/${TARGET}/full.hex -Intel
done
- name: 'Generate full dfu file'
if: ${{ !github.event.pull_request.head.repo.fork }}
uses: ./.github/actions/docker
with:
run: |
for TARGET in ${TARGETS}
do
hex2dfu \
-i firmware/.obj/${TARGET}/full.hex \
-o artifacts/flipper-z-${TARGET}-full-${{steps.names.outputs.suffix}}.dfu \
-l "Flipper Zero $(echo $TARGET | tr a-z A-Z)"
done
- name: 'Generate full json file'
if: ${{ !github.event.pull_request.head.repo.fork }}
uses: ./.github/actions/docker
with:
run: |
for TARGET in ${TARGETS}
do
jq -s '.[0] * .[1]' \
bootloader/.obj/${TARGET}/bootloader.json \
firmware/.obj/${TARGET}/firmware.json \
> artifacts/flipper-z-${TARGET}-full-${{steps.names.outputs.suffix}}.json
make TARGET=${TARGET}
done
- name: 'Move upload files'
Expand All @@ -136,52 +89,9 @@ jobs:
run: |
for TARGET in ${TARGETS}
do
mv bootloader/.obj/${TARGET}/bootloader.dfu \
artifacts/flipper-z-${TARGET}-bootloader-${{steps.names.outputs.suffix}}.dfu
mv bootloader/.obj/${TARGET}/bootloader.bin \
artifacts/flipper-z-${TARGET}-bootloader-${{steps.names.outputs.suffix}}.bin
mv bootloader/.obj/${TARGET}/bootloader.elf \
artifacts/flipper-z-${TARGET}-bootloader-${{steps.names.outputs.suffix}}.elf
mv bootloader/.obj/${TARGET}/bootloader.json \
artifacts/flipper-z-${TARGET}-bootloader-${{steps.names.outputs.suffix}}.json
mv firmware/.obj/${TARGET}/firmware.dfu \
artifacts/flipper-z-${TARGET}-firmware-${{steps.names.outputs.suffix}}.dfu
mv firmware/.obj/${TARGET}/firmware.bin \
artifacts/flipper-z-${TARGET}-firmware-${{steps.names.outputs.suffix}}.bin
mv firmware/.obj/${TARGET}/firmware.elf \
artifacts/flipper-z-${TARGET}-firmware-${{steps.names.outputs.suffix}}.elf
mv firmware/.obj/${TARGET}/firmware.json \
artifacts/flipper-z-${TARGET}-firmware-${{steps.names.outputs.suffix}}.json
mv dist/${TARGET}/* artifacts/
done
- name: 'Full flash asssembly: bootloader as base'
if: ${{ !github.event.pull_request.head.repo.fork }}
run: |
for TARGET in ${TARGETS}
do
cp \
artifacts/flipper-z-${TARGET}-bootloader-${{steps.names.outputs.suffix}}.bin \
artifacts/flipper-z-${TARGET}-full-${{steps.names.outputs.suffix}}.bin
done
- name: 'Full flash asssembly: bootloader padding'
if: ${{ !github.event.pull_request.head.repo.fork }}
run: |
for TARGET in ${TARGETS}
do
truncate -s 32768 artifacts/flipper-z-${TARGET}-full-${{steps.names.outputs.suffix}}.bin
done
- name: 'Full flash asssembly: append firmware'
if: ${{ !github.event.pull_request.head.repo.fork }}
run: |
for TARGET in ${TARGETS}
do
cat \
artifacts/flipper-z-${TARGET}-firmware-${{steps.names.outputs.suffix}}.bin \
>> artifacts/flipper-z-${TARGET}-full-${{steps.names.outputs.suffix}}.bin
done
- name: 'Bundle core2 firmware'
if: ${{ !github.event.pull_request.head.repo.fork }}
run: |
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ __pycache__/
bindings/
.DS_Store
.mxproject
Brewfile.lock.json

# Visual Studio Code
.vscode/

# legendary cmake's
build
CMakeLists.txt

# bundle output
dist
6 changes: 6 additions & 0 deletions Brewfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cask "gcc-arm-embedded"
brew "protobuf"
brew "heatshrink"
brew "open-ocd"
brew "clang-format"
brew "dfu-util"
38 changes: 21 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,65 +10,69 @@ else ifeq ($(OS), Darwin)
NPROCS := $(shell sysctl -n hw.ncpu)
endif

include $(PROJECT_ROOT)/make/defaults.mk

.PHONY: all
all: bootloader_all firmware_all
@$(PROJECT_ROOT)/scripts/dist.sh

.PHONY: whole
whole: flash_radio bootloader_flash firmware_flash

.PHONY: clean
clean: bootloader_clean firmware_clean
@rm -rf $(PROJECT_ROOT)/dist/$(TARGET)

.PHONY: flash
flash: bootloader_flash firmware_flash

.PHONY: debug
debug:
$(MAKE) -C firmware -j$(NPROCS) debug
@$(MAKE) -C firmware -j$(NPROCS) debug

.PHONY: blackmagic
blackmagic:
$(MAKE) -C firmware -j$(NPROCS) blackmagic
@$(MAKE) -C firmware -j$(NPROCS) blackmagic

.PHONY: wipe
wipe:
$(PROJECT_ROOT)/scripts/flash.py wipe
$(PROJECT_ROOT)/scripts/ob.py set
@$(PROJECT_ROOT)/scripts/flash.py wipe
@$(PROJECT_ROOT)/scripts/ob.py set

.PHONY: bootloader_all
bootloader_all:
$(MAKE) -C $(PROJECT_ROOT)/bootloader -j$(NPROCS) all
@$(MAKE) -C $(PROJECT_ROOT)/bootloader -j$(NPROCS) all

.PHONY: firmware_all
firmware_all:
$(MAKE) -C $(PROJECT_ROOT)/firmware -j$(NPROCS) all
@$(MAKE) -C $(PROJECT_ROOT)/firmware -j$(NPROCS) all

.PHONY: bootloader_clean
bootloader_clean:
$(MAKE) -C $(PROJECT_ROOT)/bootloader -j$(NPROCS) clean
@$(MAKE) -C $(PROJECT_ROOT)/bootloader -j$(NPROCS) clean

.PHONY: firmware_clean
firmware_clean:
$(MAKE) -C $(PROJECT_ROOT)/firmware -j$(NPROCS) clean
@$(MAKE) -C $(PROJECT_ROOT)/firmware -j$(NPROCS) clean

.PHONY: bootloader_flash
bootloader_flash:
ifeq ($(FORCE), 1)
rm $(PROJECT_ROOT)/bootloader/.obj/f*/flash || true
@rm $(PROJECT_ROOT)/bootloader/.obj/f*/flash || true
endif
$(MAKE) -C $(PROJECT_ROOT)/bootloader -j$(NPROCS) flash
@$(MAKE) -C $(PROJECT_ROOT)/bootloader -j$(NPROCS) flash

.PHONY: firmware_flash
firmware_flash:
ifeq ($(FORCE), 1)
rm $(PROJECT_ROOT)/firmware/.obj/f*/flash || true
@rm $(PROJECT_ROOT)/firmware/.obj/f*/flash || true
endif
$(MAKE) -C $(PROJECT_ROOT)/firmware -j$(NPROCS) flash
@$(MAKE) -C $(PROJECT_ROOT)/firmware -j$(NPROCS) flash

.PHONY: flash_radio
flash_radio:
$(PROJECT_ROOT)/scripts/flash.py core2radio 0x080CA000 $(COPRO_DIR)/stm32wb5x_BLE_Stack_full_fw.bin
$(PROJECT_ROOT)/scripts/ob.py set
@$(PROJECT_ROOT)/scripts/flash.py core2radio 0x080CA000 $(COPRO_DIR)/stm32wb5x_BLE_Stack_full_fw.bin
@$(PROJECT_ROOT)/scripts/ob.py set

.PHONY: flash_radio_fus
flash_radio_fus:
Expand All @@ -83,9 +87,9 @@ flash_radio_fus:

.PHONY: flash_radio_fus_please_i_m_not_going_to_complain
flash_radio_fus_please_i_m_not_going_to_complain:
$(PROJECT_ROOT)/scripts/flash.py core2fus 0x080EC000 --statement=AGREE_TO_LOOSE_FLIPPER_FEATURES_THAT_USES_CRYPTO_ENCLAVE $(COPRO_DIR)/stm32wb5x_FUS_fw_for_fus_0_5_3.bin
$(PROJECT_ROOT)/scripts/flash.py core2fus 0x080EC000 --statement=AGREE_TO_LOOSE_FLIPPER_FEATURES_THAT_USES_CRYPTO_ENCLAVE $(COPRO_DIR)/stm32wb5x_FUS_fw.bin
$(PROJECT_ROOT)/scripts/ob.py set
@$(PROJECT_ROOT)/scripts/flash.py core2fus 0x080EC000 --statement=AGREE_TO_LOOSE_FLIPPER_FEATURES_THAT_USES_CRYPTO_ENCLAVE $(COPRO_DIR)/stm32wb5x_FUS_fw_for_fus_0_5_3.bin
@$(PROJECT_ROOT)/scripts/flash.py core2fus 0x080EC000 --statement=AGREE_TO_LOOSE_FLIPPER_FEATURES_THAT_USES_CRYPTO_ENCLAVE $(COPRO_DIR)/stm32wb5x_FUS_fw.bin
@$(PROJECT_ROOT)/scripts/ob.py set

FORMAT_SOURCES = $(shell find applications bootloader core -iname "*.h" -o -iname "*.c" -o -iname "*.cpp")

Expand Down
90 changes: 47 additions & 43 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,79 +55,83 @@ One liner: `./flash_core1_main.sh`

3. Run `dfu-util -D full.dfu -a 0`

# Build from source
# Build with Docker

## Prerequisites

1. Install [Docker Engine and Docker Compose](https://www.docker.com/get-started)
2. Clone the repo:
```sh
git clone https://github.com/flipperdevices/flipperzero-firmware
cd flipperzero-firmware
```
3. Prepare the container:
2. Prepare the container:
```sh
docker-compose up -d
```

## Compile everything

```sh
docker-compose exec dev make -j$(nproc)
docker-compose exec dev make
```

## Flash everything
Check `dist/` for build outputs.

Use **`flipper-z-{target}-full-{suffix}.dfu`** to flash your device.

# Build on Linux/macOS

## macOS Prerequisites

Make sure you have [brew](https://brew.sh) and install all the dependencies:
```sh
docker-compose exec dev make -j$(nproc) whole
brew bundle --verbose
```

## Compile bootloader
## Linux Prerequisites

### gcc-arm-none-eabi

```sh
docker-compose exec dev make -j$(nproc) -C bootloader
toolchain="gcc-arm-none-eabi-10.3-2021.10"
toolchain_package="$toolchain-$(uname -m)-linux"

wget -P /opt "https://developer.arm.com/-/media/Files/downloads/gnu-rm/10.3-2021.10/$toolchain_package.tar.bz2"

tar xjf /opt/$toolchain_package.tar.bz2 -C /opt
rm /opt/$toolchain_package.tar.bz2

for file in /opt/$toolchain/bin/* ; do ln -s "${file}" "/usr/bin/$(basename ${file})" ; done
```

Bootloader compilation results:
* `bootloader/.obj/f7/bootloader.elf`
* `bootloader/.obj/f7/bootloader.hex`
* `bootloader/.obj/f7/bootloader.bin`
* **`bootloader/.obj/f7/bootloader.dfu`** - should be used to flash
### Optional dependencies

## Compile firmware
- openocd (debugging/flashing over SWD)
- heatshrink (compiling image assets)
- clang-format (code formatting)
- dfu-util (flashing over USB DFU)
- protobuf (compiling proto sources)

For example, to install them on Debian, use:
```sh
docker-compose exec dev make -j$(nproc) -C firmware
apt update
apt install openocd clang-format-13 dfu-util protobuf-compiler
```

Firmware compilation results:
* `firmware/.obj/f7/firmware.elf`
* `firmware/.obj/f7/firmware.hex`
* `firmware/.obj/f7/firmware.bin`
* **`firmware/.obj/f7/firmware.dfu`** - should be used to flash
heatshrink has to be compiled [from sources](https://github.com/atomicobject/heatshrink).

## Concatenate bootloader and firmware
## Compile everything

You might want to do this to distribute the firmware as a single file.
```sh
make
```

That's exactly how we generate our `full` builds.
Check `dist/` for build outputs.

1. Concatenate HEX files:
```sh
docker-compose exec dev srec_cat \
bootloader/.obj/f7/bootloader.hex -Intel \
firmware/.obj/f7/firmware.hex -Intel \
-o firmware/.obj/f7/full.hex -Intel
```
2. Convert HEX to DFU:
```sh
docker-compose exec dev hex2dfu \
-i firmware/.obj/f7/full.hex \
-o firmware/.obj/f7/full.dfu \
-l "Flipper Zero F7"
```
Use **`flipper-z-{target}-full-{suffix}.dfu`** to flash your device.

## Flash everything

Finally, you will have **`firmware/.obj/f7/full.dfu`** file that can be distributed and flashed.
Connect your device via ST-Link and run:
```sh
make whole
```

# Links
* Discord: [flipp.dev/discord](https://flipp.dev/discord)
Expand Down Expand Up @@ -198,4 +202,4 @@ Finally, you will have **`firmware/.obj/f7/full.dfu`** file that can be distribu
* toolbox - toolbox of things that we are using but don't place in core
* u8g2 - graphics library that we use to draw GUI
- make - make helpers
- scripts - supplimentary scripts
- scripts - supplementary scripts
2 changes: 1 addition & 1 deletion bootloader/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ASM_SOURCES += $(wildcard src/*.s)
C_SOURCES += $(wildcard src/*.c)
CPP_SOURCES += $(wildcard src/*.cpp)

TARGET ?= f7
include $(PROJECT_ROOT)/make/defaults.mk
TARGET_DIR = targets/$(TARGET)
include $(TARGET_DIR)/target.mk

Expand Down
Loading

0 comments on commit 4303945

Please sign in to comment.