From bb9bd7e0b0c8e8e96b3a92ce39602549365a91ee Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Wed, 9 Nov 2022 18:20:57 +0100 Subject: [PATCH] Fix #311: document how to combine device tree with conditions Signed-off-by: Joachim Wiberg --- README.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/README.md b/README.md index afcc8169..1e1135b4 100644 --- a/README.md +++ b/README.md @@ -242,6 +242,43 @@ other init, e.g. init 4, but also using the more advanced `intictl` tool. +**Conditions** + +As mentioned previously, Finit has an advanced dependency system to +handle synchronization, called [conditions](doc/conditions.md). It can +be used in many ways; depend on another service, network availability, +etc. + +One *really cool* example useful for embedded systems is to run certain +scripts if a board has a certain feature encoded in its device tree. At +bootstrap we run the following `ident` script: + +```sh +#!/bin/sh +conddir=/var/run/finit/cond/hw/model +dtmodel=/sys/firmware/devicetree/base/model + +if ! test -e $dtmodel; then + exit 0 +fi + +model=$(cat $dtmodel | tr "[A-Z] " "[a-z]-") +mkdir -p $conddir && ln -s ../../reconf $conddir/$model +``` + +Provided the device tree node exists, and is a string, we can then use +the condition `` when starting other scripts. Here is an +example: + +``` +run [S] /path/to/ident -- +task [2] /path/to/foo-init -- Initializing Foo board +``` + +> Notice the trick with an empty description to hide the call to `ident` +> in the Finit progress output. + + **Plugins** Plugins can *extend* the functionality of Finit and *hook into* the