Skip to content

Boot and services

OpenCreator doesn't replace FlashForge's init system. Stock's boot runs as usual, and OpenCreator hooks in at two points: an early boot hook stock runs long before its own startup script, and the firmwareExe program stock's startup script runs at the end. Both lead to the same launcher, which starts OpenCreator's services from /usr/data/opencreator/startup. The installer and the code call this startup system LoopScript, after the LoopScript of OpenCreator Legacy it grew out of.

From power-on to the launcher

flowchart TD
  A["rcS (read-only rootfs)"] --> B["S09: mount /usr/prog"]
  B --> C["S11: /usr/prog/module/driver.sh<br/>(early boot hook)"]
  C --> D["mount /usr/data, recovery stick"]
  D --> E["firmwareExe in the background"]
  B --> F["S21..S50: /usr/data, network, SSH"]
  F --> G["S99: app_startup.sh"]
  G --> H["firmwareExe<br/>(already started: stays alive)"]
  E --> I{"tunneled.sh executable?"}
  I -- no --> J["startup.sh"]
  I -- yes --> K["tunneled.sh"]
  J --> L["startup/scripts/*.sh"]
  1. Early boot hook. Stock's rootfs runs /usr/prog/module/driver.sh at S11, if it exists. FlashForge never ships one, and their updates don't overwrite it. OpenCreator's mounts /usr/data, runs a runRecovery.sh from a USB stick if one is plugged in, and starts firmwareExe in the background once /etc is set up. It also shows a boot progress screen. Everything about it is on Early boot and recovery stick.
  2. app_startup.sh. Stock's own startup script (S99) still runs. It loads the Wi-Fi, touch and coprocessor modules and starts /usr/prog/PROGRAM/software/firmwareExe, which is OpenCreator's launcher instead of FlashForge's program. If no process named firmwareExe is running shortly after, it puts FlashForge's binary back, which is why the launcher never exits.
  3. Boot lock. firmwareExe starts with mkdir /tmp/opencreator.boot. Whichever of driver.sh and app_startup.sh gets there first starts OpenCreator; the other copy only stays alive.

firmwareExe, the launcher

OpenCreator's firmwareExe is a shell script. It does only what's needed for the printer to stay reachable, then hands over:

  1. Enables legacy NaN (01-fixnan.sh) and bind-mounts Entware on /opt, so anything that needs Entware's tools works.
  2. Joins Wi-Fi with the networks saved from the touchscreen (/usr/prog/wifi/wpa_supplicant.conf), then checks every 10 s and restarts wpa_supplicant and udhcpc when wlan0 was re-created or they stopped. Nothing waits for the network: Klipper starts with or without it.
  3. Runs /usr/data/opencreator/tunneled/tunneled.sh instead of the rest if that file is executable (tunnel mode, below).
  4. Otherwise runs startup.sh once, then sleeps forever.

It logs to /tmp/opencreator.log. Because it's a script on /usr/data that the installer and updater keep current, a broken startup script still leaves you with Wi-Fi and SSH.

startup.sh

startup.sh does three things, in this order:

  1. If the updater or installer left an MCU flash for this power-on (/usr/data/opencreator/mcu-flash-pending/flash.sh), it runs it first, while the boards still sit in their boot stage. See Firmware, installer and updates.
  2. Starts every startup/scripts/*.sh in name order, each in the background with its output in /tmp/<script>.log. The scripts run side by side, so the numbers only set the order they're launched in; anything that needs another service waits for it itself (the Fluidd scripts wait for Moonraker's API, for example).
  3. Starts the plugins' startup items with oc-plugin boot, after OpenCreator's own scripts (see Plugins).

Startup scripts

Script What it does
01-fixnan.sh Turns on legacy NaN mode, which Entware's programs need, by writing one byte of the running FlashForge kernel with devmem. The address differs per kernel package, so kernel-package.sh recognises the running kernel by its build banner in /proc/version (after a FlashForge update the kernel folder can hold the old package too, and the old address would flip the wrong byte). An unknown kernel stops it with an error. OpenCreator's own kernel has this built in (ieee754=relaxed) and is skipped, recognised by /proc/config.gz.
02-fixtime.sh The printer has no hardware clock, so every boot starts at 1970. Restores the last saved time at once, then sets the clock from the network as soon as one answers: all NTP and rdate time servers at once, and if none answers within 8 s, the Date header of plain HTTP requests to several web servers at once. Retries every 10 s, resyncs hourly and saves the time every 5 minutes.
03-login.sh Links the login banner and prompt into /etc/profile.d (see Login banner).
04-timezone.sh Looks up the local timezone from the printer's public address for the touchscreen's clock, unless you set one in /usr/data/opencreator/timezone, and restarts HelixScreen if it changed and no print is running.
05-entfix.sh Mounts Entware on /opt if it isn't yet and starts Entware's own services (rc.unslung).
06-sftp.sh Enables SFTP. Stock's dropbear looks for an SFTP server on the read-only root, so a copy of it pointing at Entware's sftp-server is bind-mounted over it and the SSH server restarted.
07-usb.sh USB serial and USB Ethernet. On FlashForge's kernels it loads the modules in startup/usb-modules/, after checking them against SHA256SUMS; OpenCreator's kernel has them built in. Any USB Ethernet adapter gets an address by DHCP and is preferred over Wi-Fi while it's connected. See Wired Ethernet.
08-mcu-wake.sh Releases the heaterboard, eBoard and levelboard from their boot stage. Those boards stay in FlashForge's boot stage after power-on and after every reset, and Klipper can't connect until they're released. The script follows printer.log; on mcu '<name>': Timeout on connect it pauses Klippy, does the wake handshake on that board's UART and resumes Klippy, whose next attempt connects. The mainboard has no boot stage.
09-emmc-clock.sh Raises the eMMC clock from FlashForge's 25 MHz to 100 MHz. Their kernels cap it at 25 MHz in the device tree, so the cap is raised in RAM first; a read of the root file system must give the same data before and after, or the clock goes back to 25 MHz. Reads went from about 22 to 41 MB/s on a Creator 5 Pro.
10-klipper.sh Prepares and runs Klippy (below).
20-msmr.sh Prepares and runs nginx and Moonraker (below).
25-fluidd-macros.sh Once Moonraker answers, seeds Fluidd's macro categories in Moonraker's database the first time, and adds macros an update brings to their category later, without moving ones you placed.
26-fluidd-brand.sh Patches Fluidd 1.38 so AFC lane cards show a spool's brand from AFC, not only from Spoolman. Any other Fluidd version is left alone.
30-camera.sh Starts the camera streamer chosen in camera.conf: mjpg_streamer, or ustreamer (experimental, downloaded the first time it's chosen and checked against a pinned SHA-256). Falls back to mjpg_streamer when ustreamer keeps stopping. Sets white balance, saturation, contrast and hue. See Camera streamer.
40-grumpyscreen.sh Runs GrumpyScreen in a loop, if its binary is executable. It finds the touch panel's input device and uses grumpyscreen.cfg from the config folder, so you can edit it from the web UI.
41-helixscreen.sh Runs HelixScreen, if its binary is executable, on the framebuffer, turned for the portrait panel.
99-opencreator-updater.sh Runs the OpenCreator updater (see Firmware, installer and updates).

New or changed startup scripts take effect at the next boot. A running script keeps the copy it started from.

The service loops

Klippy (10-klipper.sh)

Before the first start it:

  • creates AFC/AFC.var.unit as {} if it's missing or empty;
  • writes printer.model.cfg for the model in the stock boot script (see Printer-side layout);
  • links oc-plugin and oc-switchscreen into /opt/bin.

Then it starts Klippy with printer.cfg, logging to printer.log and listening on /tmp/uds, and starts it again 3 s after it exits. Before every start it runs oc-plugin sync --only klipper, so plugin files a Fluidd update added are linked in.

Klippy runs at nice -20, the highest normal priority, pinned to core 0 of the X2600's two cores, so toolchange step generation isn't preempted by the camera, the screen or Moonraker. A real-time class isn't used: Klippy can take a whole core in bursts and would starve SSH, Moonraker and the screen. The camera streamer runs at nice 10.

Restarting Klipper from the web UI (Moonraker's machine provider) stops Klippy, and this loop starts it again.

nginx and Moonraker (20-msmr.sh)

Before Moonraker's first start it:

  • repairs Moonraker's git checkout if the update manager would call it invalid (moonraker-repo.sh);
  • links OpenCreator's Moonraker components (opencreator_3mf, opencreator_machine, opencreator_cancel) into Moonraker and adds their sections to moonraker.conf if they're missing;
  • raises nginx's API timeout from 600 s to 3600 s for large uploads;
  • turns the web UI's /webcamN/ locations into redirects to each camera streamer's own port (8080 to 8083), so nginx doesn't relay every frame;
  • starts nginx from /usr/prog/nginx.

Then it runs Moonraker from /usr/prog/moonraker/moonraker with /usr/data/opencreator/klipper as its data folder, and starts it again 3 s after it exits. Before every start it syncs plugins (--only moonraker), empties Moonraker's temporary folder and points the camera URLs in moonraker.conf at the printer's current address.

Moonraker runs with a writable HOME in /usr/data/opencreator/home, since the root is read-only and its update manager runs pip.

Tunneled printers

In tunnel mode firmwareExe runs tunneled/tunneled.sh instead of startup.sh. It runs only what the printer side needs, in order: a pending MCU flash, Entware, SFTP, USB (07-usb.sh), the eMMC clock, the clock, the camera, the touchscreen and plugins' startup items. It links oc-tunneled, oc-switchscreen and oc-plugin into /opt/bin, then runs the socat bridge (/usr/prog/c5-tunnel-socat/c5_socat.py) in a loop. The bridge forwards the four boards to the SBC over USB and does the boot-stage wake that 08-mcu-wake.sh does on a SoC install. Klipper, Moonraker and the web UI run on the SBC. See OpenCreator for SBC.

Logs

The boot logs are listed in Printer-side layout. /tmp/early.log and /tmp/opencreator.log show how far a boot got.