diff mbox series

[v2,1/1] Lua: Add support for retrieving hardware boardname/revision

Message ID 20220731074545.998773-1-james.hilliard1@gmail.com
State Accepted
Headers show
Series [v2,1/1] Lua: Add support for retrieving hardware boardname/revision | expand

Commit Message

James Hilliard July 31, 2022, 7:45 a.m. UTC
If one wants to make use of the same lua script for different
boards/revisions one needs a way to fetch that information from
within the lua script.

This adds the following function:
local hw = swupdate.get_hw()
hw.boardname
hw.revision

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
Changes v1 -> v2:
  - return a table using one function instead of two separate functions
---
 corelib/lua_interface.c | 22 ++++++++++++++++++++++
 handlers/swupdate.lua   | 11 +++++++++++
 2 files changed, 33 insertions(+)

Comments

Stefano Babic Aug. 7, 2022, 9:21 a.m. UTC | #1
On 31.07.22 09:45, James Hilliard wrote:
> If one wants to make use of the same lua script for different
> boards/revisions one needs a way to fetch that information from
> within the lua script.
> 
> This adds the following function:
> local hw = swupdate.get_hw()
> hw.boardname
> hw.revision
> 
> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> ---
> Changes v1 -> v2:
>    - return a table using one function instead of two separate functions
> ---
>   corelib/lua_interface.c | 22 ++++++++++++++++++++++
>   handlers/swupdate.lua   | 11 +++++++++++
>   2 files changed, 33 insertions(+)
> 
> diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c
> index 68e6f81..ef1622e 100644
> --- a/corelib/lua_interface.c
> +++ b/corelib/lua_interface.c
> @@ -945,6 +945,27 @@ static int l_progress_update(lua_State *L)
>   }
>   #endif
>   
> +static int l_get_hw(lua_State *L)
> +{
> +	struct swupdate_cfg *cfg = get_swupdate_cfg();
> +
> +	if (get_hw_revision(&cfg->hw) < 0)
> +		goto l_get_hw_exit;
> +
> +	lua_newtable (L);
> +	lua_pushstring(L, "boardname");
> +	lua_pushstring(L, cfg->hw.boardname);
> +	lua_settable(L, -3);
> +	lua_pushstring(L, "revision");
> +	lua_pushstring(L, cfg->hw.revision);
> +	lua_settable(L, -3);
> +	return 1;
> +
> +l_get_hw_exit:
> +	lua_pushnil(L);
> +	return 1;
> +}
> +
>   static void lua_push_enum(lua_State *L, const char *name, int value)
>   {
>   	lua_pushstring(L, name);
> @@ -1002,6 +1023,7 @@ static const luaL_Reg l_swupdate[] = {
>           { "mount", l_mount },
>           { "umount", l_umount },
>           { "getroot", l_getroot },
> +        { "get_hw", l_get_hw },
>           { "getversion", lua_get_swupdate_version },
>           { "progress", lua_notify_progress },
>           { NULL, NULL }
> diff --git a/handlers/swupdate.lua b/handlers/swupdate.lua
> index b5ae92b..fc87a99 100644
> --- a/handlers/swupdate.lua
> +++ b/handlers/swupdate.lua
> @@ -127,6 +127,17 @@ swupdate.tmpdirscripts = function() end
>   swupdate.tmpdir = function() end
>   
>   
> +--- SWUpdate hardware information.
> +--- @class swupdate_hardware
> +--- @field boardname   string  SWUpdate's boardname
> +--- @field revision    string  SWUpdate's revision
> +
> +--- Get SWUpdate hardware.
> +--
> +--- @return swupdate_hardware  # Table with 'boardname' and 'revision' fields
> +swupdate.get_hw = function() end
> +
> +
>   --- SWUpdate version information.
>   --- @class swupdate_version
>   --- @field [1]         number  SWUpdate's version


Applied to -master, thanks !

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c
index 68e6f81..ef1622e 100644
--- a/corelib/lua_interface.c
+++ b/corelib/lua_interface.c
@@ -945,6 +945,27 @@  static int l_progress_update(lua_State *L)
 }
 #endif
 
+static int l_get_hw(lua_State *L)
+{
+	struct swupdate_cfg *cfg = get_swupdate_cfg();
+
+	if (get_hw_revision(&cfg->hw) < 0)
+		goto l_get_hw_exit;
+
+	lua_newtable (L);
+	lua_pushstring(L, "boardname");
+	lua_pushstring(L, cfg->hw.boardname);
+	lua_settable(L, -3);
+	lua_pushstring(L, "revision");
+	lua_pushstring(L, cfg->hw.revision);
+	lua_settable(L, -3);
+	return 1;
+
+l_get_hw_exit:
+	lua_pushnil(L);
+	return 1;
+}
+
 static void lua_push_enum(lua_State *L, const char *name, int value)
 {
 	lua_pushstring(L, name);
@@ -1002,6 +1023,7 @@  static const luaL_Reg l_swupdate[] = {
         { "mount", l_mount },
         { "umount", l_umount },
         { "getroot", l_getroot },
+        { "get_hw", l_get_hw },
         { "getversion", lua_get_swupdate_version },
         { "progress", lua_notify_progress },
         { NULL, NULL }
diff --git a/handlers/swupdate.lua b/handlers/swupdate.lua
index b5ae92b..fc87a99 100644
--- a/handlers/swupdate.lua
+++ b/handlers/swupdate.lua
@@ -127,6 +127,17 @@  swupdate.tmpdirscripts = function() end
 swupdate.tmpdir = function() end
 
 
+--- SWUpdate hardware information.
+--- @class swupdate_hardware
+--- @field boardname   string  SWUpdate's boardname
+--- @field revision    string  SWUpdate's revision
+
+--- Get SWUpdate hardware.
+--
+--- @return swupdate_hardware  # Table with 'boardname' and 'revision' fields
+swupdate.get_hw = function() end
+
+
 --- SWUpdate version information.
 --- @class swupdate_version
 --- @field [1]         number  SWUpdate's version