Merge pull request #3842 from wavexx/readme_updates

README: Document the new build system
This commit is contained in:
Yuri D'Elia 2022-12-29 13:34:45 +01:00 committed by GitHub
commit 54704cb928
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 150 additions and 234 deletions

328
README.md
View File

@ -6,219 +6,191 @@ The latest official builds can be downloaded from [Prusa Drivers](https://www.pr
The firmware for the Original Prusa i3 printers is proudly based on [Marlin 1.0.x](https://github.com/MarlinFirmware/Marlin/) by Scott Lahteine (@thinkyhead) et al. and is distributed under the terms of the [GNU GPL 3 license](LICENSE).
# Table of contents
<!--ts-->
* [Linux build](#linux)
* Windows build
* [Using Arduino](#using-arduino)
* [Using Linux subsystem](#using-linux-subsystem-under-windows-10-64-bit)
* [Using Git-bash](#using-git-bash-under-windows-10-64-bit)
* [Automated tests](#3-automated-tests)
* [Documentation](#4-documentation)
* [FAQ](#5-faq)
<!--te-->
This repository contains _development material only!_
# Build
## Linux
There are two ways to build Prusa-Firmware on Linux: using [CMake](#cmake) (recommended for developers) or with [PF-build](#pf-build) which is more user-friendly for casual users.
1. Clone this repository and checkout the correct branch for your desired release version.
### CMake
#### Quick-start
The workflow should be pretty straightforward for anyone with development experience. After installing git and a recent version of python 3 all you have to do is:
1. Set your printer model.
- For MK3 --> skip to step 3.
- If you have a different printer model, follow step [2.b](#2b) from Windows build
1. Install GNU AWK `sudo apt-get install gawk`
If you use mawk instead of gawk you get strange errors when multi language support is generated like:
`awk: line 2: function strtonum never defined
sed: couldn't write 4 items to stdout: Broken pipe
./lang-build.sh: 121: ./lang-build.sh: arithmetic expression: expecting EOF: "0x"awk: line 2: function strtonum never defined
sed: couldn't write 4 items to stdout: Broken pipe
tr: write error: Broken pipe
./lang-build.sh: 121: ./lang-build.sh: arithmetic expression: expecting EOF: "0x"awk: line 2: function strtonum never defined
sed: couldn't write 4 items to stdout: Broken pipe
tr: write error: Broken pipe
tr: write error
cut: write error: Broken pipeNG! - some texts not found in lang_en.txt! updating binary:
primary language ids...awk: line 2: function strtonum never defined
sed: couldn't flush stdout: Broken pipe`
1. Run `./build.sh`
- Output hex file is at `"PrusaFirmware/lang/firmware.hex"` . In the same folder you can hex files for other languages as well.
# clone the repository
git clone https://github.com/prusa3d/Prusa-Firmware
cd Prusa-Firmware
1. Connect your printer and flash with PrusaSlicer ( Configuration --> Flash printer firmware ) or Slic3r PE.
- If you wish to flash from Arduino, follow step [2.c](#2c) from Windows build first.
# automatically setup dependencies
./utils/bootstrap.py
# configure and build
mkdir build
cd build
cmake .. -G Ninja -DCMAKE_TOOLCHAIN_FILE=../cmake/AvrGcc.cmake
ninja
_Notes:_
#### Detailed CMake guide
Building with cmake requires:
- cmake >= 3.22.5
- ninja >= 1.10.2 (optional, but recommended)
Python >= 3.6 is also required with the following modules:
- pyelftools (package `python3-pyelftools`)
- polib (package `python3-polib`)
- regex (package `python3-regex`)
Additionally `gettext` is required for translators.
Assuming a recent Debian/Ubuntu distribution, install the dependencies globally with:
sudo apt-get install cmake ninja python3-pyelftools python3-polib python3-regex gettext
Prusa-Firmware depends on a pinned version of `avr-gcc` and the external `prusa3dboards` package. These can be setup using `./utils/bootstrap.py`:
# automatically setup dependencies
./utils/bootstrap.py
which will download and unpack them inside the `.dependencies` directory. `./utils/bootstrap.py` will also install `cmake`, `ninja` and the required python packages if missing, although installing those through the system's package manager is usually preferred.
You can then proceed by creating a build directory, configure for AVR and build:
# configure
mkdir build
cd build
cmake .. -G Ninja -DCMAKE_TOOLCHAIN_FILE=../cmake/AvrGcc.cmake
# build
ninja
By default all variants are built. There are several ways to restrict the build for development. During configuration you can set:
- `cmake -DFW_VARIANTS=variant`: comma-separated list of variants to build. This is the file name as present in `Firmware/variants` without the final `.h`.
- `cmake -DMAIN_LANGUAGES=languages`: comma-separated list of ISO language codes to include as main translations.
- `cmake -DCOMMUNITY_LANGUAGES=languages`: comma-separated list of ISO language codes to include as community translations.
When building the following targets are available:
- `ninja ALL_MULTILANG`: build all multi-language targets (default)
- `ninja ALL_ENGLISH`: build all single-language targets
- `ninja ALL_FIRMWARE`: build all single and multi-language targets
- `ninja VARIANT_ENGLISH`: build the single-language version of `VARIANT`
- `ninja VARIANT_MULTILANG`: build the multi-language version of `VARIANT`
- `ninja check_lang`: build and check all language translations
- `ninja check_lang_ISO`: build and check all variants with language `ISO`
- `ninja check_lang_VARIANT`: build and check all languages for `VARIANT`
- `ninja check_lang_VARIANT_ISO`: build and check language `ISO` for `VARIANT`
#### Automated tests
Automated tests are built with cmake by configuring for the current host:
# clone the repository
git clone https://github.com/prusa3d/Prusa-Firmware
cd Prusa-Firmware
# automatically setup dependencies
./utils/bootstrap.py
# configure and build
mkdir build
cd build
cmake .. -G Ninja
ninja
# run the tests
ctest
### PF-build
PF-build is recommended for users without development experience. Download or clone the repository,
then run PF-build and simply follow the instructions:
cd Prusa-Firmware
./PF-build.sh
PF-build currently assumes a Debian/Ubuntu (or derivative) distribution.
The script downloads Arduino with our modifications and Rambo board support installed, unpacks it into folder `PF-build-env-\<version\>` on the same level, as your Prusa-Firmware folder is located, builds firmware for MK3 using that Arduino in Prusa-Firmware-build folder on the same level as Prusa-Firmware, runs secondary language support scripts. Firmware with secondary language support is generated in lang subfolder. Use firmware.hex for MK3 variant. Use `firmware_\<lang\>.hex` for other printers. Don't forget to follow step [2.b](#2b) first for non-MK3 printers.
## Windows
### Using Arduino
_Note: Multi language build is not supported._
### Visual Studio Code (VSCode)
#### Prerequisites
#### 1. Development environment preparation
* [Visual Studio Code](https://code.visualstudio.com/)
* [CMake Tools plugin](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools)
* [Python](https://www.python.org/)
* [Git Bash](https://git-scm.com/downloads)
**a.** Install `"Arduino Software IDE"` from the official website `https://www.arduino.cc -> Software->Downloads`
_It is recommended to use version `"1.8.5"`, as it is used on our build server to produce official builds._
#### First time setup
**b.** Setup Arduino to use Prusa Rambo board definition
Start by cloning the Prusa-Firmware repository
* Open Arduino and navigate to File -> Preferences -> Settings
* To the text field `"Additional Boards Manager URLSs"` add `https://raw.githubusercontent.com/prusa3d/Arduino_Boards/master/IDE_Board_Manager/package_prusa3d_index.json`
* Open Board manager (`Tools->Board->Board manager`), and install `Prusa Research AVR Boards by Prusa Research`
git clone https://github.com/prusa3d/Prusa-Firmware
**c.** Modify compiler flags in `platform.txt` file
* The platform.txt file can be found in Arduino installation directory, or after Arduino has been updated at: `"C:\Users\(user)\AppData\Local\Arduino15\packages\arduino\hardware\avr\(version)"` If you can locate the file in both places, file from user profile is probably used.
* Add `"-Wl,-u,vfprintf -lprintf_flt -lm"` to `"compiler.c.elf.flags="` before existing flag "-Wl,--gc-sections"
Open the `Prusa-Firmware` folder in VScode.
For example: `"compiler.c.elf.flags=-w -Os -Wl,-u,vfprintf -lprintf_flt -lm -Wl,--gc-sections"`
_Notes:_
Open a new terminal in VScode (Terminal→New Terminal) and run
python .\utils\bootstrap.py
This will download all dependencies required to build the firmware. You should see a `.dependencies` folder in the Prusa-Firmware folder.
Reload VScode. If all works correctly you should see the VScode automatically configuring the CMake project for you. If this doesn't happen you likely need to set the CMake kit; This can be done in two ways:
1. Type `Ctrl+Shift+P` and search for `CMake: Select a Kit`. Select `avr-gcc`. If none appear, Scan for kits first.
2. If 1) does not work for some reason, as a last resort you can edit the CMake Tools settings. Search for "Additional Kits" and add `.vscode/cmake-kits.json` to the list.
After updating the kit, you may need to reload VScode.
#### Building
To start building a firmware, click the CMake Tools plugin icon on the far left side. You will get a very large list of targets to build. Find the firmware you'd like to build (like `MK3S-EINSy10a_ENGLISH`) and select the small icon which shows "Build" when hovered over.
The built .hex file can then be found in folder `Prusa-Firmware/build`
_In the case of persistent compilation problems, check the version of the currently used C/C++ compiler (GCC) - should be at leas `4.8.1`;
If you are not sure where the file is placed (depends on how `"Arduino Software IDE"` was installed), you can use the search feature within the file system_
## Arduino IDE (deprecated)
_Name collision for `"LiquidCrystal"` library known from previous versions is now obsolete (so there is no need to delete or rename original file/-s)_
Using Arduino IDE is still possible, but _no longer supported_. Prusa-Firmware requires a complex multi-step build process that cannot be done automatically with just the IDE. For a long time we provided instructions to use Arduino in combination with shell scripts, however starting with 3.13 the build system has been completely switched to `cmake`.
#### 2. Source code compilation
Building with Arduino IDE results in a *limited* firmware:
**a.** Clone this repository`https://github.com/prusa3d/Prusa-Firmware/` to your local drive.
- Arduino IDE can only build a single, english-only variant at a time that you manually have to select
- The build will not be reproducible (meaning you will likely get a different binary every time you build the same sources)
- You need to download, patch and select the correct board definitions by hand
**b.**<a name="2b"></a> In the subdirectory `"Firmware/variants/"` select the configuration file (`.h`) corresponding to your printer model, make copy named `"Configuration_prusa.h"` (or make simple renaming) and copy it into `"Firmware/"` directory.
**c.**<a name="2c"></a> In file `"Firmware/config.h"` set LANG_MODE to 0.
**d.** Run `"Arduino IDE"`; select the file `"Firmware.ino"` from the subdirectory `"Firmware/"` at the location, where you placed the source code `File->Open` Make the desired code customizations; **all changes are on your own risk!**
**e.** Select the target board `"Tools->Board->PrusaResearch Einsy RAMBo"`
**f.** Run the compilation `Sketch->Verify/Compile`
**g.** Upload the result code into the connected printer `Sketch->Upload`
* or you can also save the output code to the file (in so called `HEX`-format) `"Firmware.ino.rambo.hex"`: `Sketch->ExportCompiledBinary` and then upload it to the printer using the program `"FirmwareUpdater"`
_note: this file is created in the directory `"Firmware/"`_
### Using Linux subsystem under Windows 10 64-bit
_notes: Script and instructions contributed by 3d-gussner. Use at your own risk. Script downloads Arduino executables outside of Prusa control. Report problems [there.](https://github.com/3d-gussner/Prusa-Firmware/issues) Multi language build is supported._
- follow the Microsoft guide https://docs.microsoft.com/en-us/windows/wsl/install-win10
You can also use the 'prepare_winbuild.ps1' powershell script with Administrator rights
- Tested versions are at this moment
- Ubuntu and Debian, other may different
- After the installation and reboot please open your Ubuntu bash and do following steps
- run command `sudo apt-get update`
- run command `sudo apt-get upgrade`
- to install zip run `sudo apt-get install zip`
- to install dos2unix run `sudo apt-get install dos2unix`
- run `dos2unix PF-build.sh` to convert the windows line endings to unix line endings
- add a few lines at the top of `~/.bashrc` by running `sudo nano ~/.bashrc`
export OS="Linux"
export JAVA_TOOL_OPTIONS="-Djava.net.preferIPv4Stack=true"
export GPG_TTY=$(tty)
use `CRTL-X` to close nano and confirm to write the new entries
- restart Ubuntu/Debian bash
- Now your Ubuntu/Debian subsystem is ready to use the automatic `PF-build.sh` script and compile your firmware correctly
#### Some Tips for Ubuntu and Debian
- Linux is case sensitive so please don't forget to use capital letters where needed, like changing to a directory
- To change the path to your Prusa-Firmware location you downloaded and unzipped
- Example: You files are under `C:\Users\<your-username>\Downloads\Prusa-Firmware-MK3`
- use under Ubuntu the following command `cd /mnt/c/Users/<your-username>/Downloads/Prusa-Firmware-MK3`
to change to the right folder
- Unix and Windows have different line endings (LF vs CRLF), use dos2unix to convert
- This should fix the `"$'\r': command not found"` error
- to install run `apt-get install dos2unix`
- If your Windows isn't in English the Paths may look different
Example in other languages
- English `/mnt/c/Users/<your-username>/Downloads/Prusa-Firmware-MK3` will be on a German Windows`/mnt/c/Anwender/<your-username>/Downloads/Prusa-Firmware-MK3`
#### Compile Prusa-firmware with Ubuntu/Debian Linux subsystem installed
- open Ubuntu bash shell
- change to your source code folder (case sensitive)
- run `./PF-build.sh`
- follow the instructions
### Using Git-bash under Windows 10 64-bit
_notes: Script and instructions contributed by 3d-gussner. Use at your own risk. Script downloads Arduino executables outside of Prusa control. Report problems [there.](https://github.com/3d-gussner/Prusa-Firmware/issues) Multi language build is supported._
- Download and install the 64bit Git version https://git-scm.com/download/win
- Also follow these instructions https://gist.github.com/evanwill/0207876c3243bbb6863e65ec5dc3f058
- Download and install 7z-zip from its official website https://www.7-zip.org/
By default, it is installed under the directory /c/Program\ Files/7-Zip in Windows 10
- Run `Git-Bash` under Administrator privilege
- navigate to the directory /c/Program\ Files/Git/mingw64/bin
- run `ln -s /c/Program\ Files/7-Zip/7z.exe zip.exe`
- If your Windows isn't in English the Paths may look different
Example in other languages
- English `/mnt/c/Users/<your-username>/Downloads/Prusa-Firmware-MK3` will be on a German Windows`/mnt/c/Anwender/<your-username>/Downloads/Prusa-Firmware-MK3`
- English `ln -s /c/Program\ Files/7-Zip/7z.exe zip.exe` will be on a Spanish Windows `ln -s /c/Archivos\ de\ programa/7-Zip/7z.exe zip.exe`
#### Compile Prusa-firmware with Git-bash installed
- open Git-bash
- change to your source code folder
- run `bash PF-build.sh`
- follow the instructions
For these reasons, you should think twice before reporting issues for a firmware built with Arduino. If you find a bug in the firmware, building and testing using CMake should be your first thought. Issues regarding Arduino builds are answered by the community and are not officially supported.
# 3. Automated tests
## Prerequisites
* c++11 compiler e.g. g++ 6.3.1
* cmake
* build system - ninja or gnu make
### Environment preparation
## Building
Create a folder where you want to build tests.
Install "Arduino Software IDE" from the official website https://www.arduino.cc -> Software -> Downloads. Version 1.8.19 or higher is required.
Example:
Setup Arduino to install and use the Prusa board definitions:
`cd ..`
- Open Arduino and navigate to File -> Preferences -> Settings
- To the text field "Additional Boards Manager URLs" add `https://raw.githubusercontent.com/prusa3d/Arduino_Boards/master/IDE_Board_Manager/package_prusa3d_index.json`
- Open Board manager (Tools -> Board -> Board manager)
- Install "Prusa Research AVR Boards by Prusa Research"
`mkdir Prusa-Firmware-test`
Generate build scripts in target folder.
### Source code preparation
Example:
Clone or download this repository to your local drive.
`cd Prusa-Firmware-test`
In the subdirectory `Firmware/variants/` select the configuration file (.h) corresponding to your printer model and manually copy it to `Firmware/Configuration_prusa.h`
`cmake -G "Eclipse CDT4 - Ninja" ../Prusa-Firmware`
Run "Arduino IDE", then
or for DEBUG build:
- Open the file `Firmware/Firmware.ino`
- Select the target board with Tools -> Board -> "PrusaResearch Einsy RAMBo"
- Open `Firmware/config.h` and change `LANG_MODE` to 0.
`cmake -G "Eclipse CDT4 - Ninja" -DCMAKE_BUILD_TYPE=Debug ../Prusa-Firmware`
Build it.
### Compilation and upload
Example:
`ninja`
## Running
`./tests`
# 4. Documentation
run [doxygen](http://www.doxygen.nl/) in Firmware folder
or visit https://prusa3d.github.io/Prusa-Firmware-Doc for doxygen generated output
# 5. FAQ
Q:I built firmware using Arduino and I see "?" instead of numbers in printer user interface.
A:Step 1.c was omitted or you updated Arduino and now platform.txt located somewhere in your user profile is used.
Q:I built firmware using Arduino and my printer now speaks "Klingon" (nonsense characters and symbols are displayed @^#$&*°;~ÿ)
A:Step 2.c was omitted.
Q:What environment does Prusa use to build its official firmware releases?
A:Our production builds are 99.9% equivalent to https://github.com/prusa3d/Prusa-Firmware#linux this is also easiest way to build as only one step is needed - run a single script, which downloads patched Arduino from GitHub, builds using it, then extracts translated strings and creates language variants (for MK2x) or language hex file for external SPI flash (MK3x). But you need Linux or Linux in a virtual machine. This is also what happens when you open a pull request to our repository - all variants are built by Travis http://travis-ci.org/ (to check for compilation errors). You can see, what is happening in .travis.yml. It would be also possible to get hex built by Travis, only the deploy step is missing in .travis.yml. You can find inspiration on how to deploy hex in Travis and how to setup Travis in https://github.com/prusa3d/MM-control-01/ repository. The final hex is located in ./lang/firmware.hex - community reproduced this for Windows in https://github.com/prusa3d/Prusa-Firmware#using-linux-subsystem-under-windows-10-64-bit or https://github.com/prusa3d/Prusa-Firmware#using-git-bash-under-windows-10-64-bit .
Q:Why are build instructions for Arduino a mess?
Y:We are too lazy to ship a proper board definition for Arduino. We plan to switch to CMake + ninja to be inherently multiplatform, easily integrate build tools, suport more IDEs, get 10 times shorter build times and be able to update compiler whenever we want.
- Run the compilation: Sketch -> Verify/Compile
- Upload the result code into the connected printer: Sketch -> Upload

View File

@ -1,56 +0,0 @@
# 1. Příprava vývojového prostředí
1. nainstalujte vývojové prostředí `"Arduino Software IDE"` pro operační prostředí, které jste zvyklí používat
`https://www.arduino.cc -> Software->Downloads`
doporučujeme použít starší verzi `"1.6.9"`, kterou používáme na našem build serveru pro překlad oficiálních buildů
_pozn.: v případě přetrvávajících potíží s překladem zkontrolujte verzi aktuálně použitého překladače jazyka C/C++ (GCC) - měla by být `4.8.1`; verzi ověříte zadáním příkazu
`avr-gcc --version`
pokud si nejste jisti umístěním souboru (závisí na způsobu, jakým bylo `"Arduino Software IDE"` nainstalováno), použijte funkci vyhledání v rámci systému souborů_
_pozn.: konflikt názvů knihoven / modulů `"LiquidCrystal"` známý v předchozích verzích již není aktuální (původní knihovnu tudíž není nutné mazat ani přejmenovat)_
2. do nabídky podporovaných cílových desek Arduino přidejte desku (`UltiMachine`) `RAMBo`
`File->Preferences->Settings`
do pole `"Additional Boards Manager URLs"`
vložte adresu / text
`"https://raw.githubusercontent.com/ultimachine/ArduinoAddons/master/package_ultimachine_index.json"`
ev. je možno 'ručně upravit' položku
`"boardsmanager.additional.urls=....."`
v souboru `"preferences.txt"` (parametr umožňuje zápis seznamu adres oddělených čárkami)
_pozn.: konkrétní umístění tohoto souboru na Vašem disku lze zjistit následujícím způsobem:
`File->Preferences->Settings` (`"More preferences can be edited in file ..."`)_
následně proveďte
`Tools->Board->BoardsManager`
ze zobrazeného seznamu vyberte položku `"RAMBo"` (pravděpodobně bude označena jako `"RepRap Arduino-compatible Mother Board (RAMBo) by UltiMachine"`
_pozn.: tuto položku zvolte pro všechny varianty desek použitých v tiskárnách `'Prusa i3 MKx'`, tzn. pro `RAMBo-mini x.y` i `EINSy x.y`_
'kliknutím' na položku se zobrazí tlačítko pro instalaci; ve výběrovém seznamu zvolte verzi `"1.0.1"` (poslední známá verze k datu vydání tohoto dokumentu)
_(po provedení instalace je položka označena poznámkou `"INSTALLED"` a lze ji následně použít při výběru cílové desky)_
3. modify platform.txt to enable float printf support:
add "-Wl,-u,vfprintf -lprintf_flt -lm" to "compiler.c.elf.flags=" before existing flag "-Wl,--gc-sections"
example:
`"compiler.c.elf.flags=-w -Os -Wl,-u,vfprintf -lprintf_flt -lm -Wl,--gc-sections"`
# 2. Překlad zdrojoveho kódu
do zvoleného adresáře umístěte zdrojové kódy odpovídající modelu Vaší tiskárny získané z repozitáře
`https://github.com/prusa3d/Prusa-Firmware/`
v podadresáři `"Firmware/variants/"` vyberte konfigurační soubor (`.h`) odpovídající modelu Vaší tiskárny, vytvořte kopii s názvem `"Configuration_prusa.h"` (popř. proveďte prosté přejmenování) a překopírujte do adresáře `"Firmware/"`
spusťte vývojové prostředí `"Arduino IDE"`; v adresáři, kam jste umístili zdrojové kódy, vyberte z podadresáře `"Firmware/"` soubor `"Firmware.ino"`
`File->Open`
proveďte požadované úpravy kódu; **veškeré změny ovšem provádíte na svou vlastní odpovědnost!**
jako cílovou desku pro překlad vyberte `"RAMBo"`
`Tools->Board->RAMBo`
_pozn.: nelze použít žádnou z variant `"Arduino Mega …"`, přestože se jedná o shodný MCU_
spusťte překlad
`Sketch->Verify/Compile`
výsledný kód nahrajte do připojené tiskárny
`Sketch->Upload`
přeložený kód můžete také nechat uložit do souboru (v tzv. `HEX`-formátu) `"Firmware.ino.rambo.hex"`:
`Sketch->ExportCompiledBinary`
a do tiskárny ho následně nahrát pomocí programu `"FirmwareUpdater"`
_pozn.: soubor je vytvořen v adresáři `"Firmware/"`_