#!/bin/sh # som-modem -- does an nRF91 modem firmware suit a release? The one rule # som-program-nrf91 and som-test-nrf91 judge a board's modem by: the same family # as the release's oldest modem firmware (modem-min in its PROVENANCE), the same # major.minor, and that patch or a later one. It takes a later patch release to # stay compatible, which is usual but not proven for each release. # # som-modem accepts FLOOR print the versions FLOOR accepts # som-modem check FLOOR VERSION [RUN-ON...] print VERSION's verdict, and whether # it is one of RUN-ON; exit 0 if it is # accepted, 1 if not # # RUN-ON is the release's modem-validated line, the versions it was run on. It is # reported, and never changes the verdict. A version is _.., as # AT%SHORTSWVER prints it (nrf91x1_2.0.2); the mfw_ that AT+CGMR puts in front is # dropped, so mfw_nrf91x1_2.0.2 is the same version. Anything else is not # accepted. Exit 2: usage, or a FLOOR that is not such a version. set -u PROG=som-modem usage() { printf '%s\n' \ "usage: $PROG accepts FLOOR" \ " $PROG check FLOOR VERSION [RUN-ON...]" \ "" \ " FLOOR the release's oldest modem firmware (modem-min), e.g. nrf91x1_2.0.2" \ " VERSION the board's, as AT%SHORTSWVER or AT+CGMR prints it" \ " RUN-ON the versions the release was run on (modem-validated)" \ "" \ "Accepted: FLOOR's family and major.minor, at FLOOR's patch or later. check" \ "exits 0 for an accepted VERSION and 1 for any other; RUN-ON is only reported." } # parse VERSION: v_fam, v_maj, v_min and v_pat, or fail parse() { v_s=${1#mfw_} case "$v_s" in *_*) ;; *) return 1 ;; esac v_fam=${v_s%_*}; v_n=${v_s##*_} case "$v_n" in *.*.*) ;; *) return 1 ;; esac v_maj=${v_n%%.*}; v_n=${v_n#*.}; v_min=${v_n%%.*}; v_pat=${v_n#*.} case "$v_fam" in ''|*[!A-Za-z0-9_-]*) return 1 ;; esac for v_d in "$v_maj" "$v_min" "$v_pat"; do case "$v_d" in ''|*[!0-9]*|???????*) return 1 ;; esac done } # floor FLOOR: f_fam, f_maj, f_min, f_pat and r_text, what it accepts floor() { if ! parse "$1"; then echo "'$1' is not a modem firmware version (_..)" return 2 fi f_fam=$v_fam; f_maj=$v_maj; f_min=$v_min; f_pat=$v_pat r_text="${f_fam}_$f_maj.$f_min.$f_pat or a later $f_maj.$f_min.x" } check() { # FLOOR VERSION [RUN-ON...] floor "$1" || return 2 c_v=$2; shift 2 if parse "$c_v" && [ "$v_fam" = "$f_fam" ] && [ "$v_maj" -eq "$f_maj" ] && [ "$v_min" -eq "$f_min" ] && [ "$v_pat" -ge "$f_pat" ]; then c_rc=0; c_line="${c_v:-(none)} is within $r_text" else c_rc=1; c_line="${c_v:-(none)} is outside $r_text" fi if [ $# -gt 0 ]; then c_on=0; c_list="" for c_r; do [ "${c_r#mfw_}" = "${c_v#mfw_}" ] && c_on=1 c_list="$c_list${c_list:+, }$c_r" done if [ "$c_on" -eq 1 ]; then c_line="$c_line; the release was run on it" else c_line="$c_line; the release was run on $c_list, not on it"; fi fi echo "$c_line" return "$c_rc" } case "${1:-}" in accepts) [ $# -eq 2 ] || { usage >&2; exit 2; } floor "$2" || exit 2 echo "$r_text" ;; check) [ $# -ge 3 ] || { usage >&2; exit 2; } shift; check "$@"; exit $? ;; -h|--help) usage ;; *) usage >&2; exit 2 ;; esac