Skip to content

Early boot and recovery stick

FlashForge updates overwrite /usr/prog/app_startup.sh and firmwareExe, the two files that normally start OpenCreator. So OpenCreator also boots from a file their updates don't overwrite: /usr/prog/module/driver.sh. Stock's rootfs runs it at every boot, long before app_startup.sh. The same file runs a recovery script from a USB stick, so a printer whose startup is broken can still be fixed without opening it up.

Safer than stock

On a stock printer the only way to recover without opening it up is a FlashForge update on a USB stick. That check lives in app_startup.sh, the same script mods edit and FlashForge updates overwrite. If that script breaks (a bad edit, a mod, a write cut off by a power loss), the USB check goes with it, and the printer needs Ingenic USB boot, which means opening the electronics bay.

What breaks Stock OpenCreator
app_startup.sh (bad edit, mod, half-written) no USB recovery, no Wi-Fi; open the printer driver.sh still boots OpenCreator with Wi-Fi and SSH, and still runs runRecovery.sh from a stick
a FlashForge update replaces app_startup.sh and firmwareExe n/a driver.sh isn't touched; stock boots, as you asked for
OpenCreator's firmwareExe is deleted n/a driver.sh leaves it to app_startup.sh, which puts FlashForge's firmwareExe back (stock screen and Wi-Fi)
driver.sh itself is broken n/a stock's S11 just carries on; app_startup.sh boots OpenCreator the old way

Other details that help:

  • driver.sh is started by stock's rootfs, which is read-only while the printer runs, so mods can't change that. A FlashForge update can ship a new rootfs (squashfs); one that drops the driver.sh call is unlikely, but then OpenCreator boots the old way through app_startup.sh.
  • driver.sh and firmwareExe are written to a temporary file first and renamed into place, so a power loss never leaves half a file.
  • A boot lock makes sure OpenCreator starts once, whichever of driver.sh and app_startup.sh gets there first.
  • Klipper and the rest start straight away, with or without Wi-Fi; only setting the clock from the network waits for it.

Boot order

flowchart TD
    A["rcS (read-only rootfs)"] --> B["S09: mount /usr/prog"]
    B --> C["S11: /usr/prog/module/driver.sh"]
    C --> D["mount /usr/data"]
    D --> E{"USB stick with runRecovery.sh?"}
    E -- yes --> F["run it, log to the stick"]
    E -- no --> G
    F --> G["start OpenCreator in the background"]
    C --> H["S21..S50: /usr/data, network, SSH"]
    H --> I["S99: app_startup.sh"]
    I --> J["firmwareExe: already started, stays alive"]

driver.sh starts OpenCreator once app_startup.sh has set up /etc (or after 60 s if it never does). It loads the Wi-Fi, touch and coprocessor modules first, the same ones app_startup.sh loads. When app_startup.sh later starts firmwareExe, that copy sees OpenCreator is already running and only stays alive. If app_startup.sh is broken, or a FlashForge update replaced it, OpenCreator still boots.

driver.sh leaves the boot to app_startup.sh when:

Condition Why
/usr/data didn't mount OpenCreator lives there
there is no firmwareExe nothing to start
firmwareExe is FlashForge's original program stock was flashed or you rolled back
a FlashForge update (Creator5*.tgz or runFirmwareExe.sh) is on a USB stick stock flashes it first
a control-board update is pending (an Update file in the newest /usr/prog/PROGRAM/control/<version>/ folder) stock updates the boards first
firmwareExe is an older OpenCreator one without the boot lock it would start OpenCreator twice
firmwareExe is already running already started

firmwareExe starts Wi-Fi and then Klipper and the rest straight away; it doesn't wait for a network. The clock is restored from the last saved time at once and set from the network whenever that answers, and Wi-Fi keeps being retried in the background.

Step by step

  1. Logs everything from here on to /tmp/early.log.
  2. Mounts /usr/data with the same command stock's S21 uses (mount_mmc_ext4.sh userdata /usr/data/). S21 then finds it mounted and leaves it alone.
  3. Looks for a USB stick and runs its runRecovery.sh (see Recovery stick). It also notes a FlashForge update on the stick.
  4. In the background, checks the conditions above, then starts the boot progress screen.
  5. Waits for /etc to be mounted, as above.
  6. Loads soc_mcu.ko, 8821cu.ko (Wi-Fi) and gt9xx_touch.ko from /usr/prog/modules/ with the same options app_startup.sh uses. Loading one twice just fails with "File exists", which is harmless.
  7. Sets the same LD_LIBRARY_PATH as app_startup.sh (the libraries under /usr/prog/) and runs firmwareExe.

driver.sh itself returns at once, so stock's boot carries on while OpenCreator starts. What firmwareExe does next is on Boot and services.

Boot progress screen

When driver.sh starts OpenCreator, it also starts bootlogo.sh. Stock has already shown the boot logo (/usr/prog/logo.jpeg). The script draws the same logo with a status line and a bar, and moves on as each stage is reached. It never goes back a stage.

Stage Status on screen Reached when
0 Starting up driver.sh starts OpenCreator
1 Preparing the system /etc is mounted
2 Starting OpenCreator firmwareExe took the boot lock
3 Starting services startup.sh is launching the startup scripts
4 Starting the touchscreen 40-grumpyscreen.sh or 41-helixscreen.sh was launched

It stops when GrumpyScreen, HelixScreen or the boot video runs, when tunneled mode takes the boot, or after 3 minutes. A boot that app_startup.sh takes over shows no progress. If the screen stays on one stage, that's roughly where the boot stopped: check the logs. On a custom kernel the script also turns off the boot messages it would otherwise print over the frames.

The frames are made with tools/gen-bootlogo.py in opencreator-fs.

Writable root folders and swap (OpenCreator kernel)

The printer's root file system is read-only. With OpenCreator's own kernel (not FlashForge's), /bin, /sbin, /lib, /usr/bin, /usr/sbin and /usr/lib get a writable layer: changes are kept in /usr/data/overlay, and deleting that folder puts stock back. A runRecovery.sh can turn the layers off with touch /usr/data/overlay/disable. The same kernel also gets compressed swap in RAM (zram, half the RAM) at every boot.

Recovery stick

Put a runRecovery.sh in the root of a USB stick (FAT32, exFAT or ext4), plug it in and power the printer on. driver.sh runs it as root, with sh, at every boot while the stick is in:

  • before network, SSH and app_startup.sh, and even if /usr/data won't mount;
  • from the stick's folder, with $RECOVERY_DIR set to it, so it can use files next to it;
  • its output is added to runRecovery.log on the stick, and to /tmp/early.log.

How the stick is found:

  • driver.sh waits up to 3 s for a USB drive to appear.
  • It tries /dev/sda1 to /dev/sda4, then /dev/sda (a stick without partitions). Only the first runRecovery.sh it finds runs.
  • The stick is mounted at /tmp/recovery-usb, not /mnt (stock's USB update uses that). It's read-only until a runRecovery.sh is found, then read-write so the script can write to it. It's unmounted again afterwards.

OpenCreator then boots as usual. Take the stick out when you're done, or make the script safe to run twice.

A script that saves the boot logs to the stick:

#!/bin/sh
OUT="$RECOVERY_DIR/recovery-$(date +%Y%m%d-%H%M%S)"
mkdir -p "$OUT"
dmesg > "$OUT/dmesg.txt"
cp /tmp/*.log "$OUT/" 2>/dev/null
cp /usr/prog/app_startup.sh* "$OUT/" 2>/dev/null
tail -n 2000 /usr/data/opencreator/klipper/logs/printer.log > "$OUT/printer.log" 2>/dev/null
sync

Warning

The script runs as root with nothing in its way. Only use scripts you trust, and keep in mind that anyone with physical access can do the same.

FlashForge .tgz updates on a stick still install through stock's app_startup.sh as before.

Troubleshooting

/tmp/early.log says what driver.sh decided at each boot. Each line comes from the script:

Line in /tmp/early.log Meaning
usb: no stick no USB drive appeared within 3 s
usb: FlashForge update on /dev/... a FlashForge update is on the stick; stock installs it and OpenCreator doesn't start early
usb: running runRecovery.sh from /dev/... the recovery script ran; its output follows, ending with === exit <code>
oc: /usr/data not mounted the data partition didn't mount; app_startup.sh boots as it can
oc: no firmwareExe, leaving boot to stock the launcher is missing; stock puts its own back
oc: stock firmwareExe, not starting OpenCreator FlashForge's program is in place (stock or rollback)
oc: firmwareExe has no boot lock, leaving it to app_startup.sh an old OpenCreator launcher; the next update replaces it
oc: FlashForge update on USB, leaving it to app_startup.sh see above
oc: control update pending, leaving it to app_startup.sh stock updates the boards first
oc: app_startup.sh didn't mount /etc, doing its setup app_startup.sh is broken or slow; driver.sh mounted /etc itself after 60 s
oc: already started OpenCreator was already running
oc: starting OpenCreator (...) driver.sh started the launcher

If the printer has no network at all, a recovery stick with the log script above gets you /tmp/early.log and /tmp/opencreator.log without SSH. With SSH, run sh /usr/data/opencreator/startup/commands/support-zip.sh instead: it writes support.zip to the config folder (/usr/data/opencreator/klipper/config/) with the logs in /tmp, the last part of printer.log, moonraker.log and AFC.log, your configs (with URLs, passwords, tokens and keys removed), install.json and system details. Download it from the web UI's config files to send it.

Files

File on the printer What Installed by
/usr/prog/module/driver.sh the early boot hook stock runs at S11 the installer, then the updater from opencreator-fs firmware/driver.sh; removed again by a rollback to stock
/usr/prog/PROGRAM/software/firmwareExe OpenCreator's launcher (Wi-Fi, then the startup scripts) the installer and the updater
/usr/data/opencreator/firmware/ the copies of both they install from the installer and the updater
/usr/data/opencreator/firmware/bootlogo.sh and bootlogo/ the boot progress screen and its frames the updater

Logs

Log What
/tmp/early.log driver.sh: USB stick, and whether it started OpenCreator
/tmp/opencreator.log firmwareExe and the startup scripts
runRecovery.log (on the stick) the recovery script's output

Technical details: CREATOR5_EARLY_BOOT.md in opencreator-fs.