Hi Stefano
Thanks for your help and advice!
I implemented just that, and it works as you said:
embedded-script = "
function find_where_to_install(image)
current_root = swupdate.getroot().value
swupdate.trace(\"Root =\" .. current_root)
if current_root == \"/dev/mmcblk0p1\" then
image.device = \"/dev/mmcblk0p2\"
elseif current_root == \"/dev/mmcblk0p2\" then
image.device = \"/dev/mmcblk0p1\"
else
swupdate.error(\"Could not identify an expected root
filesystem, aborting.\")
return false, nil
end
return true, image
end
";
For people reading this, the best reference is here:
https://sbabic.github.io/swupdate/sw-description.html#embedded-script
So, this works great to fix the target device, but if swupdate was
passed "-e stable, copy1" instead of "-e stable, copy2", I still get the
bootenv settings from "copy1", while I'd want all the settings for "copy2".
Is it possible to replace the whole "copy1" by "copy2" in a similar
way? It would be even better to directly select "copy1" or "copy2" based
on the current root filesystem, and not have to figure out the right
"-e" settings in the script or program that runs swupdate, but I'm not
sure this is possible as swupdate seems to want a "-e" option.
Anyway, following the same idea, I now have the check I initially
wanted, as implemented by this embedded script:
embedded-script = "
function check_target_partition(image)
current_root = swupdate.getroot().value
swupdate.trace(\"Root =\" .. current_root)
if current_root == image.device then
swupdate.error(\"Refusing to install the update in the
current root partition. Update cancelled.\")
return false, nil
end
return true, image
end
";
Thanks again.
Cheers