diff mbox series

[2/2] Lua: add function emmcbootpart

Message ID 20240215151026.115341-2-stefano.babic@swupdate.org
State Changes Requested
Delegated to: Stefano Babic
Headers show
Series [1/2] handler: eMMC internal register | expand

Commit Message

Stefano Babic Feb. 15, 2024, 3:10 p.m. UTC
Function returns the HW boot device of an eMMC.

Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
---
 corelib/lua_interface.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

--
2.34.1
diff mbox series

Patch

diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c
index de3b8702..a9e30b33 100644
--- a/corelib/lua_interface.c
+++ b/corelib/lua_interface.c
@@ -967,6 +967,22 @@  l_get_hw_exit:
 	return 1;
 }

+static int l_get_emmc_bootpart(lua_State *L)
+{
+	const char *device = luaL_checkstring(L, 1);
+	int active = -1, fd;
+
+	if (device) {
+		fd = open(device, O_RDONLY);
+		if (fd) {
+			active = emmc_get_active_bootpart(fd);
+			close(fd);
+		}
+	}
+	lua_pushinteger(L, active);
+	return 1;
+}
+
 static void lua_push_enum(lua_State *L, const char *name, int value)
 {
 	lua_pushstring(L, name);
@@ -1188,6 +1204,7 @@  static const luaL_Reg l_swupdate[] = {
         { "get_hw", l_get_hw },
         { "getversion", lua_get_swupdate_version },
         { "progress", lua_notify_progress },
+        { "emmcbootpart", l_get_emmc_bootpart },
         { NULL, NULL }
 };