State-Scripts seem to be broken on Scarthgap

Recently, I updated my Yocto project from Dunfell to Scarthgap. In so doing, we had to modify and change some of the device-trees and some U-Boot build configurations. This requires the use of a post-install state script. I based the following recipie on the state-script example here:

LICENSE="CLOSED"
FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
SRC_URI:append = "file://post-install-script;subdir=${BP}"
inherit mender-state-scripts

do_compile() {
    cp ${S}/post-install-script ${MENDER_STATE_SCRIPTS_DIR}/ArtifactInstall_Leave_10
}

The layer itself DOES build

$ bitbake state-scripts
Loading cache: 100% |####################################| Time: 0:00:01
Loaded 4802 entries from dependency cache.
NOTE: Resolving any missing task queue dependencies

Build Configuration:
BB_VERSION           = "2.8.0"
BUILD_SYS            = "x86_64-linux"
NATIVELSBSTRING      = "universal"
TARGET_SYS           = "arm-poky-linux-gnueabi"
MACHINE              = "beaglebone-yocto"
DISTRO               = "poky"
DISTRO_VERSION       = "5.0.6"
TUNE_FEATURES        = "arm vfp cortexa8 neon callconvention-hard"
TARGET_FPU           = "hard"
meta-mender-core     = "HEAD:4c242af57ff0a00a4d44328896a5cd81c27c8c46"
meta-mender-beaglebone = "HEAD:76aac650898ccee805c45e00e0cab4af7997d87f"
meta-networking      
meta-oe              = "HEAD:3c293e14492f01e22a64004e2330fb620c27578a"
meta-ODF             = "scarthgap:84672097f0f27d1ca1a6c1ee1087b6d2e9de590e"
meta-python          = "HEAD:3c293e14492f01e22a64004e2330fb620c27578a"
meta-rtlwifi         = "HEAD:6cef327d783b36fcec52af4681ef49c9412a20d1"
meta-security        = "HEAD:bc865c5276c2ab4031229916e8d7c20148dfbac3"
meta-webserver       = "HEAD:3c293e14492f01e22a64004e2330fb620c27578a"
meta                 
meta-poky            
meta-yocto-bsp       = "HEAD:7117d115eab7351ecf21388ec720a3bb5f4a9b30"

Sstate summary: Wanted 118 Local 107 Mirrors 0 Missed 11 Current 163 (90% match, 96% complete)####################################               | ETA:  0:00:00
Initialising tasks: 100% |####################################| Time: 0:00:00
NOTE: Executing Tasks
NOTE: Tasks Summary: Attempted 855 tasks of which 834 didn't need to be rerun and all succeeded.
$

However, when this is included via IMAGE_INSTALL:append = " state-scripts", The image build results in an error:

image-odf-dev-1.0-r0 do_rootfs: Unable to install packages. Command '<Trimmed>' returned 255:
 * opkg_solver_install: No candidates to install state-scripts (null)!

Hi @HunterR_PP,

Thanks for reaching out! The key point is that the state scripts are not installed into the image, but bundled with the artifact during its creation. So you don’t need to extend IMAGE_INSTALL - in fact, as you’re seeing, it doesn’t work.
The magic happens in the mender-state-scripts class: meta-mender/meta-mender-core/classes/mender-state-scripts.bbclass at 0d393c2267a92091f975eb932338c07109f5f5fd · mendersoftware/meta-mender · GitHub

So you should be fine once you have removed the IMAGE_INSTALL:append line.

Greetz,
Josef

The problem with that is if IMAGE_INSTALL Isn’t defined then none of the recipe is executed. I can confirm that after removing that line there are no state scripts in the resultant mender artifacts.

Hi @HunterR_PP,

Sorry for taking some time, I really wanted to try and reproduce this before following up.
So there is an example implementation in meta-mender-demo to be found here: meta-mender/meta-mender-demo/recipes-mender/example-state-scripts/example-state-scripts_1.0.bb at master · mendersoftware/meta-mender · GitHub

The key thing is that a few state scripts have to be in the image, such as relating to the Idle state, but most of them are bundled with the Mender Artifact outside the image. Using a build including the example gives me state2.mender, which I did inspect using mender-artifact.

$ mender-artifact read state2.mender
Reading Artifact...
.............................................................. - 100 %
Mender artifact:
  Name: state2
  Format: mender
  Version: 3
  Signature: no signature
  Compatible devices: '[qemuarm64]'
  Provides group:
  Depends on one of artifact(s): []
  Depends on one of group(s): []
  State scripts:
    ArtifactCommit_Leave_50
    ArtifactInstall_Enter_00
    ArtifactInstall_Leave_99
    ArtifactReboot_Leave_50
    ArtifactCommit_Enter_50

You can find the separation logic at meta-mender/meta-mender-core/classes/mender-state-scripts.bbclass at 8178d12b8e2d611547a7022fac026d83026b7790 · mendersoftware/meta-mender · GitHub.

So yes you are right that there needs to be a trigger for the process using IMAGE_INSTALL. Can you maybe try the example recipe if that one builds correctly, so we can then figure out where your approach runs into problems?

Greetz,
Josef