Leonard Anderweit | 3cde890 | 2024-03-12 15:30:32 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | |
| 3 | /* Logic to select a boot partition based on environment variables and switch |
| 4 | * to the other if the boot fails. */ |
| 5 | |
| 6 | doraucboot=0 |
| 7 | |
| 8 | raucbootpart0=1 |
| 9 | raucrootpart0=5 |
| 10 | raucbootpart1=2 |
| 11 | raucrootpart1=6 |
| 12 | |
| 13 | raucinit= |
| 14 | echo Booting RAUC A/B system; |
| 15 | test -n "${BOOT_ORDER}" || env set BOOT_ORDER "system0 system1"; |
| 16 | test -n "${BOOT_system0_LEFT}" || env set BOOT_system0_LEFT 3; |
| 17 | test -n "${BOOT_system1_LEFT}" || env set BOOT_system1_LEFT 3; |
| 18 | env set raucstatus; |
| 19 | for BOOT_SLOT in "${BOOT_ORDER}"; do |
| 20 | if test "x${raucstatus}" != "x"; then |
| 21 | echo Skipping remaing slots!; |
| 22 | elif test "x${BOOT_SLOT}" = "xsystem0"; then |
| 23 | if test ${BOOT_system0_LEFT} -gt 0; then |
| 24 | echo Found valid slot A, ${BOOT_system0_LEFT} attempts remaining; |
| 25 | setexpr BOOT_system0_LEFT ${BOOT_system0_LEFT} - 1; |
| 26 | env set mmcpart ${raucbootpart0}; |
| 27 | env set mmcroot ${raucrootpart0}; |
| 28 | env set raucargs rauc.slot=system0; |
| 29 | env set raucstatus success; |
| 30 | fi; |
| 31 | elif test "x${BOOT_SLOT}" = "xsystem1"; then |
| 32 | if test ${BOOT_system1_LEFT} -gt 0; then |
| 33 | echo Found valid slot B, ${BOOT_system1_LEFT} attempts remaining; |
| 34 | setexpr BOOT_system1_LEFT ${BOOT_system1_LEFT} - 1; |
| 35 | env set mmcpart ${raucbootpart1}; |
| 36 | env set mmcroot ${raucrootpart1}; |
| 37 | env set raucargs rauc.slot=system1; |
| 38 | env set raucstatus success; |
| 39 | fi; |
| 40 | fi; |
| 41 | done; |
| 42 | if test -n "${raucstatus}"; then |
| 43 | env delete raucstatus; |
| 44 | env save; |
| 45 | else |
| 46 | echo WARN: No valid slot found; |
| 47 | env set BOOT_system0_LEFT 3; |
| 48 | env set BOOT_system1_LEFT 3; |
| 49 | env delete raucstatus; |
| 50 | env save; |
| 51 | reset; |
| 52 | fi; |