Partial log:
...
[INFO ] : SWUPDATE running : [download_info] : Received : 263634944 / 268440064
[INFO ] : SWUPDATE running : [download_info] : Received : 268353536 / 268440064
[TRACE] : SWUPDATE running : [extract_files] : END INSTALLING STREAMING
[TRACE] : SWUPDATE running : [network_initializer] : Valid image found: copying to FLASH
[INFO ] : SWUPDATE running : Installation in progress
...
[TRACE] : SWUPDATE running : [execute_shell_script] : Calling shell script /tmp/scripts/prewrite.sh : return with 0
...
[TRACE] : SWUPDATE running : [execute_shell_script] : Calling shell script /tmp/scripts/postwrite.sh : return with 0
[INFO ] : SWUPDATE successful ! SWUPDATE successful !
...
On sw-description:
scripts: (
{
filename = "prewrite.sh";
type = "preinstall";
},
{
filename = "postwrite.sh";
type = "postinstall";
}
);
images: (
{
filename = "rootfs.ext4"
device = "/dev/update";
installed-directly = true;
type = "raw";
}
I have trouble embedded lua script. The documentation says the syntax
embedded-scripts = "<lua code>"
So I assume the embedded-scripts node is to be inside the "images: (...)" node. I put the lua functions inside the double quotes as instructed by the documentation.
While the parser doesn't complain about the embedded lua code, however I cannot seem to be able to run the function inside. I modified the emmcpart.lua code from the official SWUpdate source code, and put the os.capture() and preinst() functions in there, replacing double-quotes with single quote.
My question:
(1) I want to run preinst() before the image is raw-streamed to the mmc, can you provide a pseudo code on how I should do that?
(2) Can I include the emmcpart.lua file in the "file: ()" node, and expect to run a function from emmcpart.lua through a hook? If so, please provide a pseudo code as example.
Thanks,
Kelvin
Looks like I have figured out (1). embedded-scripts= "<lua code>" section is placed under software = {} root section. I also had to escape "\" character with another "\" to pacify the parser. I added a hook="<function>" to the images attribute
software =
{
version = "0.0.2";
embedded-script = "
function os.capture(cmd, raw)
local f = assert(io.popen(cmd, 'r'))
local s = assert(f:read('*a'))
f:close()
if (raw) then return s end
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
s = string.gsub(s, '[\\n\\r]+', ' ')
return s
end
function preinst()
local cmdline = os.capture('cat /proc/cmdline', 1)
local bootmmcpart = string.sub(string.match(cmdline, 'mmcblk0p%d'), 9)
print('bootmmcpart = ' .. bootmmcpart)
local upgrademmcpart = bootmmcpart
if bootmmcpart == '1' then
upgrademmcpart = '2'
else
upgrademmcpart = '1'
end
print('upgrademmcpart = ' .. upgrademmcpart)
cmd = 'ln -s /dev/mmcblk0p' .. upgrademmcpart .. ' /dev/mmcpart_4_upgrade'
print('Setting symbolic link: ' .. cmd)
os.capture(cmd, 1)
cmd = 'fw_setenv mmcpart ' .. upgrademmcpart
print('Setting u-boot environment variable: ' .. cmd)
os.capture(cmd, 1)
return true, bootmmcpart
end
";
Controller = {
hardware-compatibility: [ "0.1" ];
images: (
{
filename = "boot.vfat";
device = "/dev/mmcpart_4_upgrade";
installed-directly = true;
type = "raw";
hook = "preinst"
sha256 = "f008f5a78f4d372f9a2812b0c4328237b5a9b483a6b403cac5c712c44fe2a0db";
}
);
};
}
Is there a way to embed a postinst() LUA function, so SWUpdate will call it automatically at post-installation of images and files?
I have only been able to call an embedded LUA function as a hook to an image or file.
Kelvin