'Unable to update EFI (BIOS) using nsh script when A/B partitioning is enabled

I have embedded linux (Buildroot based) OS with A/B partitioning enabled and trying to install EFI upgrades using nsh script. Note: Using EFIStub (directly booting kernel from EFI)

Here is the startup.nsh script, I wrote:

@echo -off
mode 80 25

$1:
if exist .\AfuEfi*.efi then
 echo "AfuEfix64.efi found!"
 if exist D015000U110XI12.BIN then
  echo "updating firmware"
  AfuEfix64.efi D015000U110XI12.BIN /p /b /n /x /me
  rm AfuEfix64.efi
  reset
 endif
endif

\\efi\\boot\\bootx64.efi

To me logically this could be done through following sequence:

  1. Booting through UEFI shell
  2. Determine the correct partition is selected (i.e. FS0: or FS1:)
  3. Run fs0:\startup.nsh fs0 (if FS0 is the highest in boot order else FS1)

I would like to perform above all steps without manual intervention.

For Point 1, I think I can alter the boot sequence in favour of efi shell by making changes in init script of initrd using efibootmgr. But, now I dont know I can proceed with step 2 or step 3 as the logic to determine bootorder in efi shell (e.g. bcfg) needs to be played on the efi shell, but how? Any idea?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source