Lua Hook for bootenv

296 views
Skip to first unread message

Ayoub Zaki

unread,
Sep 18, 2020, 3:48:38 PM9/18/20
to swupdate
Hello,

I'm trying to setup a Lua hook for bootenv as follow:

https://pastebin.com/raw/v9DAmmTV


The hook is executed but the bootenv.value is no applied:

Swupdate v2020.04.0
Licensed under GPLv2. See source distribution for detailed copyright notices.
[INFO ] : SWUPDATE running :  [lua_handlers_init] : No Lua handler(s) found.
[TRACE] : SWUPDATE running :  [lua_handlers_init] : Lua handler search path:
/usr/local/share/lua/5.2/swupdate_handlers.lua
/usr/local/share/lua/5.2/swupdate_handlers/init.lua
/usr/local/lib/lua/5.2/swupdate_handlers.lua
/usr/local/lib/lua/5.2/swupdate_handlers/init.lua
/usr/share/lua/5.2/swupdate_handlers.lua
/usr/share/lua/5.2/swupdate_handlers/init.lua
./swupdate_handlers.lua
Registered handlers:
dummy
archive
tar
uboot
bootloader
lua
raw
rawfile
rawcopy
shellscript
preinstall
postinstall
[TRACE] : SWUPDATE running :  [read_sw_version_file] : Installed rootfs: Version v0.1_20200429
[TRACE] : SWUPDATE running :  [network_initializer] : Main loop Daemon
[TRACE] : SWUPDATE running :  [listener_create] : creating socket at /tmp/swupdateprog
[TRACE] : SWUPDATE running :  [listener_create] : creating socket at /tmp/sockinstctrl
[TRACE] : SWUPDATE running :  [extract_sw_description] : Found file:
filename sw-description
size 860
checksum 0xfe96 VERIFIED
[TRACE] : SWUPDATE running :  [get_common_fields] : Version 1.0.0
[TRACE] : SWUPDATE running :  [parser] : Getting script
[TRACE] : SWUPDATE running :  [parser] : Found Lua Software:

function set_active_system(bootenv)
os.execute("fw_printenv -n active_system > /tmp/active_system")
fh = io.open("/tmp/active_system")
active_system = fh:read()
print("active_system:" .. tostring(active_system))
if active_system == "A" then
bootenv.value= "B"
else
bootenv.value= "A"
end
fh.close()
swupdate.trace("bootenv.value: " .. bootenv.value)
return true, bootenv
end
[TRACE] : SWUPDATE running :  [parse_images] : Found compressed Image rootfs v0.1_20200429: ozyx-image-qt5demo-qemux86.ext4.gz in device : /dev/null for handler raw
[TRACE] : SWUPDATE running :  [parse_bootloader] : Bootloader var: upgrade_available = 1
[TRACE] : SWUPDATE running :  [lua_parser_fn] : Prepared to run set_active_system
active_system:A
[TRACE] : SWUPDATE running :  [notify_helper] : bootenv.value: B
[TRACE] : SWUPDATE running :  [LUAstackDump] : (1) [bool  ] true
[TRACE] : SWUPDATE running :  [lua_dump_table] : (2) [table ] compressed = false
[TRACE] : SWUPDATE running :  [lua_dump_table] : (2) [table ] installed_directly = false
[TRACE] : SWUPDATE running :  [lua_dump_table] : (2) [table ] name = active_system
[TRACE] : SWUPDATE running :  [lua_dump_table] : (2) [table ] volume =
[TRACE] : SWUPDATE running :  [lua_dump_table] : (2) [table ] offset = 0
[TRACE] : SWUPDATE running :  [lua_dump_table] : (2) [table ] install_if_higher = false
[TRACE] : SWUPDATE running :  [lua_dump_table] : (2) [table ] device =
[TRACE] : SWUPDATE running :  [lua_dump_table] : (2) [table ] version = X
[TRACE] : SWUPDATE running :  [lua_dump_table] : (2) [table ] mtdname =
[TRACE] : SWUPDATE running :  [lua_dump_table] : (2) [table ] encrypted = false
[TRACE] : SWUPDATE running :  [lua_dump_table] : (2) [table ] partition = false
[TRACE] : SWUPDATE running :  [lua_dump_table] : (2) [table ] type =
[TRACE] : SWUPDATE running :  [lua_dump_table] : (2) [table ] filename =
[TRACE] : SWUPDATE running :  [lua_dump_table] : (2) [table ] path =
[TRACE] : SWUPDATE running :  [lua_dump_table] : (2) [table ] checksum = 0
[TRACE] : SWUPDATE running :  [lua_dump_table] : (2) [table ] sha256 = 0000000000000000000000000000000000000000000000000000000000000000
[TRACE] : SWUPDATE running :  [lua_dump_table] : (2) [table ] size = 0
[TRACE] : SWUPDATE running :  [lua_dump_table] : (2) [table ] install_if_different = false
[TRACE] : SWUPDATE running :  [lua_dump_table] : (2) [table ] script = false
[TRACE] : SWUPDATE running :  [lua_dump_table] : (2) [table ] data =
[TRACE] : SWUPDATE running :  [lua_dump_table] : (2) [table ] filesystem =
[TRACE] : SWUPDATE running :  [lua_dump_table] : (2) [table ] ivt =
[TRACE] : SWUPDATE running :  [lua_dump_table] : (2) [table ] value = B
[TRACE] : SWUPDATE running :  [lua_parser_fn] : Script returns 0
[TRACE] : SWUPDATE running :  [parse_bootloader] : Bootloader var: active_system = X
[TRACE] : SWUPDATE running :  [cpio_scan] : Found file:
filename setup.lua
size 296
not required
[TRACE] : SWUPDATE running :  [cpio_scan] : Found file:
filename ozyx-image-qt5demo-qemux86.ext4.gz
size 75029320
REQUIRED
[DEBUG] : SWUPDATE running :  [preupdatecmd] : Running Pre-update command
[TRACE] : SWUPDATE running :  [install_single_image] : Found installer for stream ozyx-image-qt5demo-qemux86.ext4.gz raw
[WARN ] : SWUPDATE running :  [copyfile] : compressed argument: boolean form is deprecated, use the string form
Software updated successfully
Please reboot the device to start the new software
[INFO ] : SWUPDATE successful !
[DEBUG] : SWUPDATE running :  [postupdate] : Running Post-update command


var: active_system = should be B in this case but in output it's stiil in its default value X !

Maybe I 'm missing something in the syntax, but I cannot figure it out!

any suggestion ?

Thank you!

Best regards,

Ayoub Zaki 

ayoub...@googlemail.com

unread,
Sep 19, 2020, 8:09:56 AM9/19/20
to swupdate
Hello,

After digging in the source code found out that :



GET_FIELD_STRING(p, elem, "value", dummy.id.version);

bootloader value is assigned with version !


I think it's a typo and maybe it should be corrected.



The following sw-description I can correclty make the hook setting bootloader value :


software =
{
        version = "1.0.0";

embedded-script = "

function set_active_system(image)
os.execute(\"fw_printenv -n active_system > /tmp/active_system\")
fh = io.open(\"/tmp/active_system\")
active_system = fh:read()
print(\"active_system:\" .. tostring(active_system))
if active_system == \"A\" then
image.version= \"B\"
else
image.version= \"A\"
end
fh.close()
swupdate.trace(\"image.version: \" .. image.version)
return true, image
end
"

        images: (
{
name = "rootfs";
version = "v0.1_20200429";
filename = "ozyx-image-qt5demo-qemux86.ext4.gz";
device = "/dev/null";
compressed=true;
type = "raw";
}
        );
uboot: (
{
name = "active_system";
   value = "X"; //dummy;
   hook = "set_active_system";
},
{
name = "upgrade_available";
   value = "1";

}
);
}


best regards,
Ayoub

Stefano Babic

unread,
Sep 19, 2020, 12:53:07 PM9/19/20
to ayoub...@googlemail.com, swupdate
Hallo Ayoub,

On 19.09.20 14:09, 'ayoub...@googlemail.com' via swupdate wrote:
> Hello,
>
> After digging in the source code found out that :
>
> https://github.com/sbabic/swupdate/blob/master/parser/parser.c#L546
>
>
> GET_FIELD_STRING(p, elem, "value", dummy.id.version);
>
> bootloader value is assigned with version !
>
>
> I think it's a typo and maybe it should be corrected.
>

It was not a type - the interface to the hook is an "image" table, and
this should report the values in the corresponding main C structure in
SWUpdate. Bootloader's environment does not match very well, and they
are stored as dictionary inside SWUpdate, and a similar couple in an
image is name/version. So it was a compromise, where "name" is the same
for bootenv and versions.
Best regards,
Stefano
> --
> You received this message because you are subscribed to the Google
> Groups "swupdate" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to swupdate+u...@googlegroups.com
> <mailto:swupdate+u...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/swupdate/b47117c6-cc90-4f40-91cd-431bf7393484n%40googlegroups.com
> <https://groups.google.com/d/msgid/swupdate/b47117c6-cc90-4f40-91cd-431bf7393484n%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
=====================================================================
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sba...@denx.de
=====================================================================
Reply all
Reply to author
Forward
0 new messages