Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

12. Toolchain Reference

Everything is done with one command, gogo: prebuilt in each release (gogo-<os>-<arch>, chapter 2), or built with go build -o build/gogo ./cmd/gogo. gogo run also needs the host VM, gogovm (released as gogovm-<os>-<arch> for macOS and Linux, or built with make vm). It runs on macOS and Linux; on Windows, setup flashes the firmware and programs, but the serial console commands (monitor, config on a board, and the Wi-Fi and first-program steps of setup) are not supported.

gogo build [-path dirs] [-o out.ggb] <dir|file.gg>
gogo run [--key c=pin]... [--fs-root DIR] [VM parameter flags] [-path dirs] <dir|file.gg|file.ggb>
gogo env [-path dirs]
gogo dis <file.ggb>
gogo info [-path dirs] <file.ggb|dir|file.gg>
gogo flash [-port P] [-esptool path] [-path dirs] [-no-usb-reset] <app.ggb|dir|file.gg>
gogo push [-port P] [-timeout seconds] [-no-usb-reset] <file.ggb> [/flash/path]
gogo monitor [-port P] [-timeout seconds] [-until text] [-reset] [-no-usb-reset]
gogo firmware (-board sticks3|cardputer | -port P [-esptool path] [-no-usb-reset]) [-o dir] [-build] [-with list] [-without list] [-component dir]... files...
gogo config [-port P | -local] [-no-usb-reset] set <key> <value|-> | get <key> | list | rm <key> | import [-n] <file|-> | export | keys | scan | stats
gogo device [-port P] [-yes] [-no-usb-reset] info | scan | stats | format-flash | usb-reset
gogo setup [-port P] [-board sticks3|cardputer] [-version vX.Y.Z] [-release-url URL|DIR] [-esptool path] [-offline] [-skip-wifi] [-new-layout] [-reflash] [-yes] [-dry-run] [-no-usb-reset]
gogo version

Flags work the same in every command:

  • A flag is spelt with one dash or two (-port P, --port P), and its value follows as the next argument or after = (-o=app.ggb).
  • Flags may come before or after the other arguments: gogo build app -o app.ggb and gogo build -o app.ggb app are the same. -- ends the flags, so an argument after it that starts with - is not one; a lone - is an ordinary argument. gogo run is the exception, as go run is: its flags come before the program, and what follows the program belongs to the program (refused for now).
  • The names are the same everywhere: -port (the board’s serial port), -board, -o (where the output goes), -timeout (seconds), -esptool, -path, -yes, -no-usb-reset (below).
  • -h (or -help) prints the command’s usage and exits 0. A mistake (an unknown flag, a missing value or argument) prints what is wrong and the usage, and exits 1.

A board that stops answering over USB. The boards’ USB serial link sometimes goes silent while the program keeps running (docs/known-issues.md, “ESP32-S3 boards”). The commands that talk to a board (flash, push, monitor, config on a board, device, setup, and firmware -port) then recover it themselves on macOS and Linux. When the board does not answer, or esptool fails (for gogo monitor: when nothing at all arrived), they ask the board’s USB device for its string descriptor 0. Only when that request times out or comes back empty, the signature of the silent link, do they bus-reset the device once (the chip keeps running), wait for the port to come back, retry once, and print

gogo: the board's USB link was silent; reset it (USB bus reset)

A device that answers the request (a board without gogo firmware, one restarting, a quiet program) is never reset, and the original error is reported as it is. If the retry fails too, the error says so and to replug the board. esptool keeps the terminal as before (its progress bar redraws in place). A retried flash is the same command again, which rewrites every region from its start, so nothing is left half-written by the first try; if the retry fails too, the firmware refuses the half-written program as after any failed flash. Only an Espressif USB device (vendor id 0x303a) is reset, never while another of your programs has the port open (gogo cannot see programs of root or other users; if it cannot tell, it does not reset). -no-usb-reset (or GOGO_NO_USB_RESET=1 in the environment) turns this off; gogo device usb-reset resets by hand. On Linux the reset needs a udev rule (gogo prints it; known issues has it too); on Windows gogo cannot reset a USB device, so replug the board. Where no reset can happen (turned off, or Windows), an esptool failure is reported alone, and a board that did not answer gets a line on what to do about a silent link.

gogo build

gogo build [-path dirs] [-o out.ggb] <dir|file.gg>

Compiles the package main in <dir> (all its .gg files), the gogo libraries and the packages of your own it imports into one image file. Without -o the image is named after the directory, <dir>.ggb, in the current directory. Given a .gg file instead (or a file starting with #!), it compiles that file alone as package main, into <name>.ggb. The image contains bytecode and constants and runs unchanged on the host VM and on any board.

Errors are printed as file:line:col: message and the exit status is 1 (every gogo command exits 1 on an error; gogo run has its own statuses, below). Messages from Go’s type checker look like Go’s (declared and not used: x); messages about the subset start with gogo::

main.gg:9:7: gogo: interior pointer &s[0] not supported: gogo has no pointers into a slice element or a struct field; use a []*T or a *T field, or s[i].F = v

Type errors are reported first; subset errors appear once the program type-checks. Chapter 3 lists the subset errors.

Packages and the search path

An import that does not start with gogo/ names a package of your own (section 3.1.1). <dir> (or the directory of the single file) is the build root, and the import is looked up, first match wins:

  1. in the build root, when its first element is the root directory’s name: import "app/util" while building app/ is app/util/;
  2. in each directory of the search path, in order: import "lib/ring" is <dir>/lib/ring/.

A match is a directory holding .gg files. The search path is -path dirs if given, else $GOGOPATH (directories separated by :, or ; on Windows; empty elements are skipped, relative ones are taken from the current directory), else $HOME/gogo when GOGOPATH is unset. A build root inside a search path directory counts once (the same directory is one place). A path found in more than one place is a warning naming every location; a path found nowhere is an error listing them:

main.gg:3:8: gogo: import "app/nope": package not found; searched:
	app/nope (build root: no such directory)
	/home/you/gogo/app/nope (search path: no such directory)

A package’s name must be its directory’s name (so a Go identifier), only the build root may be package main, an import path must match the directory names on disk letter case included, and import cycles are errors that show the chain. Functions of your packages are named by their import path (app/util.Sum) in crash reports and gogo dis. A module built for hot loading resolves its packages in the same way, from its own directory.

Only .gg files are read: .go files in the directory are ignored, and a directory with .go files but no .gg file is an error that says to rename them (no .gg files, only .go files: ...). gogo sources were .go files before; .gg is Go syntax, so map it to Go in your editor for highlighting (chapter 2, Editor support); gopls does not apply.

Requirements and //gogo:optional

The image also records, by name, what it needs from the board (its requirements, appendix F): the driver of every port.Open with a constant driver name ("kbd", "tcp", a host port’s "ui"), and the mount /sd for constant /sd paths, in package main and in every library compiled in. An image that can make a float (a float constant, a conversion of an integer to a float, math.Inf, math.NaN, strconv.ParseFloat) also requires float, the firmware option GOGO_FLOAT; code that only handles floats it is given (gogo/fmt’s formatting, a float case of a type switch) requires nothing, since without a source no float can reach it. An import by itself requires nothing. A firmware that lacks a required driver or mount refuses the image at boot, naming it:

gogo: image requires kbd, which this VM lacks

and code.Load returns Unsupported with code.Missing naming it (chapter 14). A driver name the compiler cannot see (a variable, a function call) is a loophole: it requires nothing, so it escapes this check, and the open simply fails at run time on a board without the driver. The build warns at each such call, with its position:

gogo: warning: main.gg:12:9: port.Open with a non-constant driver name: the image does not require it and the load does not check it; name the driver and mark it //gogo:optional if the program handles its absence

To open a driver that may be absent, name it and mark it soft with //gogo:optional (below), which works in package main too.

The image format itself has a version, major.minor (major 15; gogo version prints the full one). A firmware runs images of its major whose minor is at most its own, and the compiler stamps each image with the lowest minor its program needs, so after a firmware update every module already on /flash keeps loading. An image of another major, or of a newer minor than the firmware’s, is refused (unsupported image format 15.4 (this VM runs 15.0 to 15.3); code.Load returns BadVersion). The minors so far: 15.1 added screen.Config, 15.2 floating point, 15.3 sized integers (only a program that divides, compares or shifts uint32/uint64 values, uses int8/int16/uint16 arithmetic or prints an unsigned value needs it), 15.4 panic, interfaces and == on structs and interfaces, 15.5 the node port’s types (gogo/node), 15.6 pointers, maps, read-only package-level variables and gogo/fmt, 15.7 the errors of actor.Call and actor.Register (new builtins: a program that calls either, directly or through a library call that does, such as any gogo/node call, dns.Lookup, http.Get or supervisor.SuperviseModule, needs 15.7 firmware; supervisor.Supervise, http.Serve or sound.Play alone do not).

A package, a library or package main, can declare that it uses some drivers only softly: it opens them only when a call asks for that at run time, and handles their absence (port.Open returns an error) as an ordinary failure. It says so with a directive line in any of its files, conventionally the last line of the package doc comment, after an empty // line (where gofmt puts directives):

// Package http is a small HTTP/1.x client and server...
//
//gogo:optional tls
package http
  • The listed drivers add no requirement for that package’s own port.Open calls. The same driver opened by another package still counts: a program that calls port.Open("tls", ...) itself requires tls, unless package main names it in its own directive. A program that runs on several boards can so probe for a driver one of them lacks:

    // Program keys uses the keyboard when the board has one.
    //
    //gogo:optional kbd
    package main
    
  • Any driver name is accepted, a board’s or a host port’s. An empty list or a misspelt //gogo: directive is a compile error, for example a.gg:3:1: gogo: unknown directive //gogo:optinal (want //gogo:optional, //gogo:builtin or //gogo:reserved). The other two mark declarations of the standard library’s system packages (a function the VM implements, a struct type with a fixed type index; lib/README.md); a program cannot use them.

  • gogo/http declares tls (an http-only program runs on a firmware without TLS, where an https request fails), and gogo/sound declares mic speaker (Record returns false without a microphone, Play without a speaker).

  • The directive is a promise the compiler does not check. A library can still hand main a function that opens the driver; that open then fails cleanly at run time (an error) on a firmware without the driver.

  • gogo firmware (below) chooses features from the requirements, so it does not turn a soft driver on by itself; tls, mic and speaker are on by default, and -without makes those calls fail at run time instead.

gogo run

gogo run [--key c=pin]... [--fs-root DIR] [--actor-memory SIZE] [--memory SIZE] [--max-actors N]
         [--max-ports N] [--max-links N] [--bytes-handles N[/M]] [-path dirs] <dir|file.gg|file.ggb> [args...]

Runs a program on the host VM. Given a directory it builds it first (to a temporary image), all of its .gg files together; given a .gg file, or any file starting with #!, it builds that file alone, with its directory as the build root for packages (an executable script with the first line #!/usr/bin/env -S gogo run runs this way, chapter 2); given a .ggb file it runs that image. -path dirs is the search path of the build, as for gogo build.

Program arguments. Everything after the program is the program’s, as for go run: flags come before the program, and what follows it is passed on untouched (gogo run tool.gg -v "a b" gives tool.gg the two arguments -v and a b; -- and empty words are passed too). The program reads them with sys.Args(), a []string of the arguments only: unlike Go’s os.Args there is no element 0 for the program’s own name, so with no arguments the slice is empty (and not nil). A #! script gets the arguments of its own command line the same way (./tool.gg -v runs gogo run ./tool.gg -v). gogovm takes them after the image, gogovm [flags] prog.ggb [args...]. Every call to sys.Args() copies the arguments into the actor’s heap, so call it once and keep the result; a very large command line (hundreds of KB) can run the actor out of memory (a crash, oom, not an empty slice). On a board nothing starts a program with arguments, so sys.Args() is empty there; a host that embeds the VM can provide them (chapter 18).

Exit status. gogo run exits with the VM’s status, which says how the main actor ended:

StatusMeaning
0main exited Normal (or Shutdown)
1a usage, toolchain or build error, or the VM was not found
2the image could not be loaded: not an image, damaged, or a format this VM does not run
3the image requires a driver or mount the VM lacks (for example tls in a VM built without mbedTLS)
4main crashed: a VM reason such as divzero, oom or killed (appendix B), or a code below 64 or negative given to actor.Exit
64..99main exited with a library failure, actor.Failed plus a shared code (appendix B), as it is: http.ListenFailed is 69
100..255main exited with your code, actor.Exit(code) with code from 100; a code above 255 is 255

Only main counts: other actors’ crashes are reported on standard error but leave the status alone, so a program whose main ends normally exits 0. To fail a script, end main with a code:

if !ok {
	println("check failed")
	actor.Exit(100) // gogo run exits 100
}

When a linked actor’s exit takes main down, main exits with that actor’s own reason: 4 if it crashed, but 150 if it called actor.Exit(150), 69 for a library failure.

If the VM itself is killed by a signal, gogo run exits 128 plus the signal’s number, as a shell does (130 for Ctrl-C, 137 for kill -9). Those statuses overlap the user range 100..255, so a script that must tell them apart should keep its own codes below 128. The host VM build/gogovm exits with the same statuses (it is where they come from).

Options:

  • --fs-root DIR: back /flash with DIR/flash (created if missing) and /sd with DIR/sd (only if it exists). Without it there is no storage. Programs stay inside those directories: symlinks in them are not followed (opening one, or a path through one, is BadPath; ReadDir lists it as a file), and neither are FIFOs or devices. On a host file system that ignores case (macOS by default) the media ignore case too. The VM program build/gogovm also takes --fs-quota BYTES (tests only): each medium may then hold that many bytes of files, counting what is already there; deletes give room back, and fs.Usage reports (used, quota). See section 16.5. And it takes --without NAME,... (tests only): the named drivers and mounts (kbd, tls, /sd, …) are left out of the host board, as on a firmware built without them. --host-net (or GOGO_NET=host in the environment, which gogo run passes on) makes the tcp and tcp_listen ports use the host’s real sockets (chapters 10.1 and 20).
  • --key c=pin: in a terminal, pressing the character c presses the simulated GPIO input pin (the level goes to 0, then back to 1). Up to 16 keys.
  • --actor-memory, --memory, --max-actors, --max-ports, --max-links, --bytes-handles: the VM’s limits, passed to gogovm as they are (the next section). gogo run --actor-memory 16K --memory 160K --max-actors 1024 --max-ports 16 --max-links 8 --bytes-handles 64/16 prog runs prog with a board’s limits (tests/golden/board_limits checks it against the board build, build/gogovm_mcu); all six, since the host’s tables are sized from them.

Standard input feeds the simulated hardware:

  • If it is not a terminal (a file or a pipe), it is a script, read one line at a time whenever the VM is idle and a port that can produce events is open:

    LineMeaning
    <pin> <0|1>a GPIO input changes level
    key <name>a key press and release (kbd port)
    keydown <name>, keyup <name>press or release only, for modifiers
    battery <mV> <charging> <external>a battery sample (power port)
    imu sample <gx> <gy> <gz> <ax> <ay> <az>, imu gesture <kind> [value]IMU data (imu port, chapter 15)
    ir rx <us> <us> ...a received infrared frame (ir_rx port, chapter 15)
    mic tone <hz> <ms>, mic silence <ms>microphone input (mic port, chapter 16)
    sleep <ms>pause before the next line

    Unknown lines are reported on standard error and skipped. Key lines are dropped while no kbd port is open. At the end of the script no more input can arrive, so an idle program can end.

  • If it is a terminal, --key characters drive GPIO pins and, while a kbd port is open, other keys become key presses. Ctrl-D ends the input; Ctrl-C stops the program (and restores the terminal).

Output. println writes to standard output. Crash reports and the simulated GPIO outputs (gpio: pin 5 = 1) go to standard error.

The VM. gogo run uses the first of: $GOGO_VM; gogovm (or the release asset name gogovm-<os>-<arch>) in the directory of the gogo executable, symlinks resolved; build/gogovm in the gogo source tree around the gogo executable or the current directory. If none is found it says so and what to do. gogo env prints the one it would use.

Environment. GOGO_VM names the VM to use (above). GOGOPATH is the package search path of the build. GOGO_CONFIG names the configuration file that sys.Config reads (default ~/.gogo/config). GOGO_UNIX_TIME_MS starts the wall clock (sys.Time, chapter 10.8) at that Unix time in ms instead of the computer’s clock; 0, or a time earlier than the VM’s build, starts it unknown, as on a board.

There is no network on the host (chapter 10).

gogovm

The host VM: it runs one image, as gogo run does after building it (gogo run finds it and passes it its flags), and is what a script or a server runs directly.

gogovm [flags] <file.ggb> [args...]     run an image; args are the program's (sys.Args)
gogovm [flags] --info                   print the VM's parameters as this run would resolve them
gogovm -h | --help                      list the flags
gogovm --sizeof-actor | --sizeof-net | --has-tls    build facts (alone)

Flags come before the image; everything after it is the program’s. An unknown flag is a usage error (exit 1).

The VM’s parameters. Each is also a config key (chapter 11.3) and a field of an embedding host’s gogo_config (chapter 18.3); the flag beats the key, the key beats the default, the same rule on every platform. A value past the most is cut to it with one line on standard error (gogo: vm.actor_memory 2G is over this VM's 1G; using 1G); a flag that is not a number, or has no value, is a usage error. SIZE is bytes, with an optional K, M or G; --memory 0 is no limit (it undoes a vm.memory key). gogovm answers its parameter flags in its config store, as typed: a program’s sys.Config("vm.actor_memory") sees what was asked (8G), not what the VM clamped it to (1G; actor.Limit tells that). Ports and actors share the 65536 PID slots: ports past what the actors leave are cut, with a line when you gave them. If the VM cannot start with the parameters (out of memory), it names the config keys that changed them and starts without them (the flags kept); a flag that cannot fit is an error (exit 1).

FlagKeyDefault (a board’s)MostBounds
--actor-memory SIZEvm.actor_memory1M (16K)1G (256K)an actor’s memory (heap, stack, mailbox) unless SpawnOpt sets it; at least 1K
--memory SIZEvm.memoryno limit (160K)none (160K)all actors together
--max-actors Nvm.max_actors16384 (1024)61440live actors at once (the PIDs above are node links’ remote ones)
--max-ports Nvm.max_ports1024 (16)2048ports open at once; actors + ports at most 65536
--max-links Nnode.max_links512 (8)2048node links of distributed actors (chapter 20); at most the ports, and on a board what fits a quarter of its memory
--bytes-handles N[/M]vm.handles4096/256 (64/16)65535 (1024)off-heap Bytes, in the VM and (M) per actor
code.mem16M (64K)4G - 1loaded module code (chapter 14)

gogovm --info prints them as the run would have them, one line of name=value fields, the format of gogo device info’s limits line:

$ gogovm --info
actor_memory=1M memory=unlimited max_actors=16384 max_ports=1024 max_links=512 code_mem=16M bytes_handles=4096/256
$ GOGO_CONFIG=my.cfg gogovm --actor-memory 4M --info
actor_memory=4M memory=2G max_actors=16384 max_ports=1024 max_links=512 code_mem=16M bytes_handles=4096/256

(the second with vm.memory=2G in my.cfg).

Other flags.

FlagMeaning
--fs-root DIR/flash from DIR/flash (created), /sd from DIR/sd if it exists (above)
--key C=PINin a terminal, the character C presses the simulated GPIO input PIN (0..63; repeatable)
--screen ansi|text|nonehow the screen port shows its grid: ANSI on the terminal, a text dump of every frame, or nothing (default: ansi on a terminal, else text)
--host-netthe tcp and tcp_listen ports use the host’s sockets (GOGO_NET=host likewise): a real network peer, such as a server node (chapter 20)
--net-fd Nfile descriptor N (inherited, a socketpair end) is the simulated network link; not with --host-net
--sim-clocktime moves only when the network simulator says so (needs --net-fd)
--without NAME,...tests: leave the named drivers (kbd, tls, …) and mounts (/sd) out of the board
--fs-quota BYTEStests: each medium may hold BYTES of files (section 16.5)

Environment.

VariableMeaning
GOGO_CONFIGthe config store, one key=value a line (default ~/.gogo/config): sys.Config, and the VM’s keys above
GOGO_NET=hostas --host-net
GOGO_UNIX_TIME_MSstart the wall clock at that Unix time in ms (0: unknown, as on a board)
GOGO_TLS_CA_FILEthe PEM file of trusted certificates for the tls port (default the system bundle; chapter 17.6)
GOGO_TLS_BUNDLE_FILEtests: trust anchors from an ESP-IDF certificate bundle, with the firmware’s rule
GOGO_TLS_STATSwhen set, one tls-stats ... line on standard error at exit

Exit status is gogo run’s (above): 0 when main ends normally, 1 for a usage error or no memory at boot, 2 for a bad image, 3 for an image that requires what this VM lacks, 4 when main crashes, and main’s own code from 64.

gogo env

gogo env [-path dirs]

Prints the version, the package search path (where it comes from: $GOGOPATH, $HOME/gogo when GOGOPATH is unset, or -path) and the VM gogo run would use, with where it was found:

$ gogo env
version   v0.4.0 (image format 15.4)
GOGOPATH  /home/you/gogo ($HOME/gogo, GOGOPATH is unset)
search    1. the build root (imports starting with its directory's name)
          2. /home/you/gogo
gogovm    /usr/local/bin/gogovm (next to gogo)

A VM that cannot be found is reported on the gogovm line, and the exit status is still 0.

gogo dis

gogo dis <file.ggb>

Prints the bytecode of an image, function by function. Useful to see what the compiler made of your code, or to compare two builds:

$ gogo build docs/book/examples/02-hello -o hello.ggb
$ gogo dis hello.ggb
func main (params=0 regs=4):
  0000  LOADK r1, "hello, gogo"
  0002  LOADK r2, 42
  0004  LOADK r3, true
  0006  BUILTIN r0, r1, 3, PRINTLN
  0008  LOADK r0, nil
  0010  RET r0

The VM is register based: each function has a fixed number of registers, which live in a stack frame in the actor’s memory.

gogo info

gogo info [-path dirs] <file.ggb|dir|file.gg>

Says what an image is and what it needs, read from the image file: its format version (major.minor, the lowest the program needs, so the oldest firmware that runs it), its size, the drivers and mounts it requires (what a firmware must have to boot it, or to code.Load it as a module), and its entries (the exported functions code.Spawn starts by name; (boot) marks the one a board starts):

$ gogo info examples/netdemo
format     15.0
size       46112 bytes: 94 functions, 58 types, 9605 code words, 1462 constant words
requires   gpio, netif, tcp, tcp_listen, udp
optional   tls (gogo/http)
entries    main (boot)

Given a directory or a .gg file, it builds it in memory first (-path as for gogo build) and adds the optional line: the drivers the program’s packages mark //gogo:optional (with the packages that do), which the image does not record because a firmware without them runs it anyway. A file that is not a gogo image, is damaged, or has a format this gogo does not know is an error.

gogo flash

gogo flash [-port P] [-esptool path] [-path dirs] [-no-usb-reset] <app.ggb|dir|file.gg>

Writes an image to the board’s program partition at 0x210000, with a header and a CRC that the firmware checks at boot. Given a directory or a .gg file it builds it first, as gogo run does (to a temporary image; -path as for gogo build), so gogo flash ./app is gogo build and gogo flash in one step. Needs the board’s gogo firmware to be installed already (chapter 2).

  • -port P: the serial port. Default: the only board port, a /dev/cu.usbmodem* on macOS, a /dev/ttyACM* on Linux (one whose USB device sysfs shows is not Espressif’s, vendor id 303a, is left out); with none or several, gogo flash stops and asks for -port. Windows has no default: pass -port COM5.
  • -esptool path: the esptool to run. Default: esptool or esptool.py from PATH (. ~/esp/esp-idf/export.sh puts it there).
  • -no-usb-reset: no automatic USB reset when esptool fails on a silent board (above).

gogo flash refuses files that are not gogo images, images of another format version (rebuild it with gogo build) and images over the 1 MB partition.

gogo push

gogo push [-port P] [-timeout seconds] [-no-usb-reset] <file.ggb> [/flash/path]

Copies an image (a module, chapter 14) to the board’s /flash, over the serial console while the board runs: to /flash/<file name>, or to the path given (its directory must exist; names as in chapter 9). The board writes it under a temporary name, reads it back, checks its length and CRC-32, and only then renames it over the target, so the target is either the old file or the whole new one. Any failure, a refused chunk, a mismatch, the cable pulled, leaves the target as it was. The temporary file is .gogo-push in the target’s directory (which is why that name cannot be a target); a push cut off by a pulled cable leaves it there, taking space and listed by fs.ReadDir, until the next push into that directory.

  • -port P: as for gogo flash.
  • -timeout seconds: how long to wait for each answer of the board (default 5). A board that does not answer is reset (above) and the push starts over once.

It refuses a file that is not an image of a format this gogo knows, and a path outside /flash. A firmware older than gogo push answers that it has no push. Only one program can have the serial port open: close gogo monitor first.

gogo monitor

gogo monitor [-port P] [-timeout seconds] [-until text] [-reset] [-no-usb-reset]

Copies the board’s console to standard output.

  • -timeout seconds: stop after this long (default 10; fractions such as 0.5 are fine). -t is its old name: it still works in this release, with a note on standard error, and goes away in the next.
  • -until text: stop after the first line containing text, e.g. -until "gogo: vm exited".
  • -reset: reset the board first, so the capture starts at boot. Without it, opening the port never resets the board.
  • -port P: as for gogo flash.
  • -no-usb-reset: when nothing arrived, do not check the USB link and reset it (above).

It is not interactive. Only one program can have the serial port open, so stop gogo monitor before gogo flash or gogo config.

gogo firmware

gogo firmware (-board sticks3|cardputer | -port P [-esptool path] [-no-usb-reset]) [-o dir] [-build] [-with list] [-without list] [-component dir]... files...

Chooses which optional parts the firmware needs to contain for a set of images and modules, so a build does not carry a network stack or an SD driver nobody uses. It reads the requirement names each file carries (what gogo build writes), maps each to the feature that builds it, and writes <dir>/sdkconfig.gogo, a list of CONFIG_GOGO_* lines, then prints the idf.py command that builds with it. It never flashes.

  • Feature names: net kbd power sd exfat cjk imu irtx irrx mic speaker tls screen node float ble bleprov. The requirement names they build: net the drivers netif, udp, tcp and tcp_listen; kbd, power, imu, mic, speaker, tls, screen, node (distributed actors, chapter 20) and ble (Bluetooth LE, chapter 23) the driver of the same name; irtx and irrx the drivers ir_tx and ir_rx; sd the mount /sd (appendix F); float the requirement float (floating point in the VM and gogo/math). gpio and /flash are in every firmware; any other name is an error unless a driver component given with -component provides it. net, kbd, power and float are on only when a file requires them (or -with adds them). The others are on by default on boards that have them: sd, imu, irtx/irrx (the infrared sender and receiver), mic/speaker, tls (the TLS client, chapter 17), node and ble can be required too, so a file that needs one keeps it on, while exfat (exFAT media) and cjk (the Chinese font) are not. irtx and irrx share one firmware switch, as do mic and speaker, so they go on and off together. ble also brings its ESP-IDF settings (Bluetooth and NimBLE, sdkconfig.ble); -without ble leaves Bluetooth out of the firmware altogether. bleprov (Wi-Fi setup from a phone over Bluetooth, section 2.1) is on by default with ble whenever net is on; no program requires it, and it needs both ble and net (not kbd: the Cardputer’s setup key is read without the keyboard driver). -without bleprov keeps the ble port and drops the setup mode.
  • -with a,b adds features. -without a,b removes them; a feature that a file requires cannot be removed (error). exfat goes off with sd, tls, node and bleprov with net, and bleprov with ble.
  • A required feature the board lacks is an error that names it, for example kbd or sd on the sticks3.
  • -board names the board. Instead, -port P asks the board on that port: one read-only esptool command (chip-id; -esptool as for gogo flash) reads its chip, and an ESP32-S3 with embedded PSRAM is the M5StickS3, one without is the Cardputer ADV (as gogo setup decides). The board resets afterwards and runs its program again. -no-usb-reset as for gogo flash.
  • -component dir (repeatable) builds an ESP-IDF component of your own into the firmware: a driver on gogo.h that registers itself with GOGO_BOARD_PORT (chapter 22). The directory has the component’s CMakeLists.txt and a gogo-driver.json naming the requirement names it provides, {"format": 1, "ports": ["acme.dice"]}, which then satisfy the images’ requirements. The tool turns on CONFIG_GOGO_BOARD_PORTS (the firmware’s host-port layer) and passes the directories to idf.py as EXTRA_COMPONENT_DIRS; without -component both are off again. A component’s name is its directory’s, so two components may not share one, and none may be called main, driver or like one of gogo’s or ESP-IDF’s components (a list built into the tool, plus the components of an ESP-IDF at $IDF_PATH or ~/esp/esp-idf, so the check holds without ESP-IDF exported); the name takes letters, digits, _ and - (acme_dice), and a path may not contain ;, a space or $. The json’s names go into CONFIG_GOGO_BOARD_PORT_NAMES, and the firmware says at boot each one it did not register; with -build the tool also checks the linker map and fails for a component that put no GOGO_BOARD_PORT in the firmware (one not linked whole). A name of a built-in driver, or one two components give, is an error. gogo device info lists the registered ports among provides.
  • -o dir: the build directory and where sdkconfig.gogo goes (default build-fw-<board>). -build runs the printed command (from the gogo repository root, with ESP-IDF exported, chapter 2).

The tool owns the build directory. ESP-IDF would let an existing <dir>/sdkconfig override a changed sdkconfig.gogo, so if that file exists and any CONFIG_GOGO_* value in it differs from the new features, the tool deletes it and prints a line saying so. If nothing differs it is kept and the next build stays incremental. A lone - argument is an error.

gogo config

gogo config [-port P | -local] set <key> <value|->
gogo config [-port P | -local] get <key>
gogo config [-port P | -local] list
gogo config [-port P | -local] rm <key>
gogo config [-port P | -local] import [-n | -dry-run] <file|->
gogo config [-port P | -local] export
gogo config keys
gogo config [-port P] scan        # deprecated: gogo device scan
gogo config [-port P] stats       # deprecated: gogo device stats

Edits the configuration store on the board or in the local file. See chapter 11 for how the store is chosen, the key rules and the keys gogo uses (keys prints them; set checks a key under a gogo prefix, and its value, against that table). scan and stats are gogo device scan and gogo device stats (below), kept here for this release.

  • -port P: the board on that serial port.
  • -local: the local file ($GOGO_CONFIG, default ~/.gogo/config); setting $GOGO_CONFIG chooses it too. Writing a secret (wifi.password, node.token) there prints a warning that the file is plain text.
  • Neither: the one board connected. With no board, or several, the command fails (every operation but keys), naming the ports found.
  • import <file|-> sets every key of a key=value file (# comments and blank lines skipped, the value to the end of the line; - is standard input) after checking every line as set does; a bad line or a repeated key is reported as file:line and nothing is written. It prints set <key> per key (a secret as (set)) and imported N keys to .... On a board, a refused key stops the import and the error names the keys written and not written.
  • -n, -dry-run (import only): check and print what would be set, writing nothing.
  • export prints the store as a file import reads, sorted; secrets are comment lines without their values (# wifi.password=(set, not exported)).

gogo device

gogo device [-port P] info
gogo device [-port P] scan
gogo device [-port P] stats
gogo device [-port P] [-yes] format-flash
gogo device [-port P] usb-reset

Operations on the board itself, over its serial console (usb-reset excepted):

  • info shows the firmware the board runs: its version (the git describe it was built from, dev without git, -dirty for uncommitted changes), the board it was built for, the image format it runs (gogo version shows the one gogo writes), the VM’s limits as it runs with them (its parameters: the config keys over the board’s defaults, section 6.2; a firmware before them has no limits line) and the requirement names it provides (the drivers and mounts an image may require, as gogo info lists them for an image):

    $ gogo device info
    firmware  gogo v0.3.0
    board     sticks3 (M5StickS3)
    image     format 15.8 (runs images 15.0 to 15.8)
    limits    actor_memory=16K memory=160K max_actors=1024 max_ports=16 max_links=8 code_mem=64K bytes_handles=64/16
    provides  gpio netif udp tcp tcp_listen tls node power imu ir_tx ir_rx mic speaker screen /flash float
    

    A firmware older than info (v0.1.0) says so; its boot line (gogo monitor -reset) has its version.

  • scan lists the 2.4 GHz networks the board sees.

  • stats prints the board’s network counters, free memory and how full the VM’s fixed tables are, as used/capacity: bytes=N/64 (off-heap bytes.Bytes handles, of vm.handles), ports=N/16 (open ports, of vm.max_ports) and subs=N/4 (net.Subscribe slots). When a port open fails or a tcp write gets Done{-1}, these show whether a table is full. A firmware built without net prints no network counters and no subs. console_stack_free=N/4096 is the least stack the console task (which answers these commands and writes gogo push files) has had free.

  • format-flash erases every file on /flash: the board restarts and formats its /flash partition at the size fs.flash.size sets (chapter 9). Nothing else is touched: not the configuration store (Wi-Fi settings stay), not the program, not the firmware; the chip is never erased. It asks you to type yes first; -yes skips the question.

  • usb-reset bus-resets the board’s USB device, which brings back a USB link that went silent without restarting the chip or its program (the other operations do it on their own when the board does not answer, unless -no-usb-reset is given; see the start of this chapter). It finds the device from the serial port, refuses any device that is not Espressif’s (vendor id 0x303a) and a port another of your programs has open (programs of root or other users cannot be seen), and waits for the port to come back:

    $ gogo device -port /dev/cu.usbmodem5101 usb-reset
    reset USB device 303a:1001 at location 0x05100000 (USB bus reset; the chip keeps running)
    /dev/cu.usbmodem5101 is back
    

    On macOS it re-enumerates the device through IOKit; on Linux it is the USBDEVFS_RESET ioctl on /dev/bus/usb/BBB/DDD, which needs the udev rule of the known issues; Windows has no usb-reset (replug the board).

-port as for gogo flash. scan and stats were gogo config scan and gogo config stats, and format-flash was gogo config set fs.flash.format yes and a restart; the old forms still work in this release, with a note, and go away in the next.

gogo setup

gogo setup [-port P] [-board sticks3|cardputer] [-version vX.Y.Z] [-release-url URL|DIR]
           [-esptool path] [-offline] [-skip-wifi] [-new-layout] [-reflash] [-yes] [-dry-run]
           [-no-usb-reset]

Takes a board from new to running a program, in six steps (chapter 2 shows a run):

  1. finds esptool (version 5 or newer) and the board’s serial port (/dev/cu.usbmodem* on macOS, /dev/ttyACM* on Linux; with several, it asks);
  2. identifies the board with esptool (letting it detect the chip, and reading the partition table now on the board): an ESP32-S3 with embedded PSRAM is the M5StickS3, one without is the Cardputer ADV; you confirm, and any other chip is refused;
  3. gets the board’s firmware: downloads it from a release, checks every file against the release’s SHA256SUMS (a mismatch stops setup), and caches it in the user cache directory (gogo/release/<sha256>); without a release it builds the firmware locally (below);
  4. asks the firmware on the board for its info (as gogo device info) and reads the version of the firmware about to be flashed from its app image (gogo.bin’s ESP-IDF app descriptor, which carries the same git describe). When both are the same release or clean commit and the board matches, it reads the app’s descriptor from the board’s flash too (read-flash of 4 KB at the app’s offset, read-only; info has no build id) and compares its app_elf_sha256 with the firmware’s: the same version may be another build (-with, -without, -component). Only for the same build and partition table does it skip the flash: the board already runs gogo <version> (<board>, app <first 4 bytes of the SHA256>); not reflashing (-reflash to flash it anyway). The bootloader is not compared. Otherwise it says why in one line (board firmware unknown (...): no answer, a firmware older than info, a dev or -dirty build on the board; board runs gogo <x> (<board>), flashing ...; or board runs gogo <x> (<board>), but another build of it (...)) and flashes the bootloader, partition table and app at the offsets in the firmware’s flasher_args.json, then resets the board with a watchdog reset (the Cardputer ADV does not come back from esptool’s default reset). A local build of uncommitted changes (-dirty) is always flashed;
  5. scans for Wi-Fi networks on the board, and writes the chosen network and the password (read without echo) like gogo config set;
  6. flashes a small hello program like gogo flash and watches the console until it prints.

What it never does. It never erases the chip and never writes a merged image: esptool only ever runs read-flash, write-flash and version. The partition table must be at 0x8000. Every write must lie in the bootloader area (below 0x8000), on the partition table sector or inside an app partition of the partition table being written, and no write, rounded out to whole 4 KB flash sectors, may touch a protected range: the NVS partition (where the board keeps its settings, Wi-Fi included) of the table being written, of the table now on the board, and of the gogo partition table (0x9000..0xF000), all three. Setup checks this before it runs esptool. If the board’s table puts NVS elsewhere than the new one, or the partition table sector holds data that is not a readable table (blank flash is fine), setup stops unless -new-layout is given. The Wi-Fi password is never printed, logged or stored on the computer.

Which release. -release-url (or $GOGO_RELEASE_URL) names the files of one release: an http(s) URL or a local directory, such as one filled by gh release download or tools/release.sh. Otherwise -version vX.Y.Z picks a GitHub release of c4pt0r/gogo; otherwise the release matching this gogo (gogo version) if that is a release tag (vX.Y.Z, or with -rcN, -beta.N, -alpha.N), else the latest, pinned to its tag on the first request so every file comes from one release. Drafts are not visible to setup until published (platform/esp32s3/README.md). The assets setup reads are:

AssetWhat
SHA256SUMSthe SHA-256 of every other asset
<board>-flasher_args.jsonESP-IDF’s list of files and offsets for the board (sticks3, cardputer)
<board>-bootloader.bin, <board>-partition-table.bin, <board>-gogo.binthe files it lists, named <board>-<file name>
gogo-<os>-<arch>[.exe]the gogo command, for darwin, linux, windows on amd64, arm64
LICENSE, THIRD_PARTY_NOTICES.md, font-licenses.zip, LICENSE-APACHE-2.0.txtthe licenses that go with the binaries (setup does not read them)

A release’s version is also the C embedding API’s: the tag’s X.Y.Z (v0.2.0, or v0.2.0-rc1) must equal GOGO_VERSION_MAJOR, _MINOR and _PATCH in runtime/include/gogo.h (what gogo_version() reports, book chapter 18), and tools/release.sh refuses the tag otherwise. So every release bumps them, a firmware-only patch release included.

To try a release layout before publishing it, point setup at the directory, or serve it over HTTP:

tools/release.sh v0.1.0                 # build/release/v0.1.0/
gogo setup -release-url build/release/v0.1.0
python3 -m http.server -d build/release 8765 &
gogo setup -release-url http://127.0.0.1:8765/v0.1.0

Local firmware build. With -offline, or when the release cannot be downloaded (and you agree), setup builds the board’s default firmware with gogo firmware -build and every feature the board has, into build/setup-<board> of the gogo source tree. It needs to run inside the gogo source tree and ESP-IDF v6.1.1 (idf.py on PATH, else $IDF_PATH/export.sh or ~/esp/esp-idf/export.sh, which it sources).

Options:

  • -port P, -esptool path: as for gogo flash.
  • -board sticks3|cardputer: skip the board question.
  • -skip-wifi: leave the board’s Wi-Fi settings as they are.
  • -new-layout: flash although the board’s partition table keeps NVS elsewhere than the new firmware’s, or cannot be read. Neither NVS area is written, but the old settings are then not used, and the new firmware (or a later one) may reuse the space where they were.
  • -reflash: flash the firmware even when the board already runs the same version (step 4), without asking the board.
  • -yes: take the default answer to every question, without asking; the Wi-Fi step is then skipped, and a board esptool cannot tell apart needs -board.
  • -dry-run: run only what reads (esptool’s chip check, the download, the board’s info, the Wi-Fi scan) and print the esptool commands and settings that would be written, or that the firmware would not be reflashed, without writing anything.
  • -no-usb-reset: no automatic USB reset when esptool cannot reach the chip or the board does not answer its info (start of this chapter; only a device that fails the USB descriptor check is reset, so a new board, whose firmware never answers, is left alone).

On failure setup prints the problem and a fix: line, and stops; it is safe to run again.

gogo version

Prints the version of gogo (dev unless built by tools/release.sh) and the image format version it writes.

Building the firmware

The firmware is an ESP-IDF project in platform/esp32s3, built with idf.py (ESP-IDF v6.1.1). See chapter 2 for the commands and platform/esp32s3/README.md for build options (GOGO_BOARD, GOGO_CONSOLE=0, and the CONFIG_GOGO_* feature switches NET, KBD, BATTERY, SD, FS_EXFAT, FONT_CJK, IMU, IR, AUDIO, TLS) and hardware details. To choose the switches from what your programs need, use gogo firmware (above). gogo setup flashes a prebuilt firmware from a release instead.

Running the book’s examples

make vm && go build -o build/gogo ./cmd/gogo
docs/book/examples/run.sh              # all examples
docs/book/examples/run.sh 04-call      # one

make test-book does the same. run.sh runs each example the way the book shows (with its input, fsroot and config files) and compares the output with the expected.out and expected.err files next to it. An example of several packages keeps its program in app/ (the build root, so its imports start with app/); run.sh runs it from there, with an empty search path.

Checking a change to gogo

make test is the full check before a commit. Besides the C and Go tests, it runs:

  • make lint: gofmt on every .go file and on every .gg file (gogo source is Go syntax, but gofmt reads only .go, so tools/lint.sh checks a .go copy of each), go vet ./..., and shellcheck on tools/*.sh when it is installed. To format a .gg file, format a .go copy (or use gofmt on standard input: gofmt < f.gg > f.tmp && mv f.tmp f.gg).
  • make test-examples: every program in examples/ and platform/esp32s3/examples/ must build (the board-only ones too: building needs no board), and the ones with an expected.out run with gogo run and must print it (tools/examples.sh, which reads the same input, config, fsroot, mods/ and expected.err files as the golden tests). A new example without an expected.out is still built on every run. An example of several packages keeps its program in app/ (with app/expected.out); a .gg file beside app/ is a script, run when a <name>.expected.out is beside it; and a file gogopath names the example’s GOGOPATH, relative to the example (examples/packages uses all three).
  • make test-book: every example in this book, through docs/book/examples/run.sh (above).
  • make site-check: builds the website (make site: this book through mdBook, and the landing page site/index.html, into build/site) and checks that every link and anchor in it resolves (tools/sitecheck); skipped when mdbook is not installed.
  • make vmsize (and netsize, vfssize, screensize, floatlibsize): the code size of the VM core and of each runtime part as linked into the ESP32-S3 firmware (the firmware’s flags, a relaxed --gc-sections link from the part’s API), against their budgets (skipped without the ESP-IDF compiler); tools/vmsize.sh --objects gives the older, unlinked sum. vmsize also prints the VM core’s lines of C; tools/vmsize.sh --record appends the size and the line count to docs/vmsize-history.csv, and tools/vmsize.sh --no-float measures the core without floating point.

Outside make test: make test-lib (the standard library on the host Go toolchain, also part of go test ./...) and make test-tls-asan (the network and TLS tests under AddressSanitizer). The test workflow, .github/workflows/test.yml, runs all three on macOS and Linux (x86-64) once a day and when started by hand (Actions > test > Run workflow). The TLS tests need mbedTLS’s source (ESP-IDF’s components/mbedtls/mbedtls; MBEDTLS_DIR names another copy) and are skipped without it; the workflow fetches the commit ESP-IDF v6.1.1 pins.