blob: f74ce9098ee6daaa38e4e7b951763e293e0a6320 [file] [log] [blame]
Norman Jamese2765102015-08-19 22:00:55 -05001#include "interfaces/flash.h"
2#include "pflash/pflash.c"
Norman James10ff6a32015-08-27 14:24:17 -05003#include "openbmc.h"
Norman Jamese2765102015-08-19 22:00:55 -05004
5/* ---------------------------------------------------------------------------------------------------- */
Norman James26072c02015-08-25 07:14:29 -05006static const gchar* dbus_object_path = "/org/openbmc/flash/BIOS";
7static const gchar* dbus_name = "org.openbmc.flash.BIOS";
Norman Jamese2765102015-08-19 22:00:55 -05008
9static GDBusObjectManagerServer *manager = NULL;
Norman Jamese2765102015-08-19 22:00:55 -050010
11static gboolean
12on_update_via_file (Flash *f,
13 GDBusMethodInvocation *invocation,
14 gchar* write_file,
15 gpointer user_data)
16{
17 g_print("Flashing BIOS from file\n");
18 // get size from file
19 struct stat stbuf;
20 uint32_t address = 0, read_size = 0, write_size = 0;
21
22 if (stat(write_file, &stbuf))
23 {
24 g_print("Failed to get file size");
25 //TODO: Error handling
26 }
27 write_size = stbuf.st_size;
28 erase_chip();
29 program_file(write_file, address, write_size);
30 flash_complete_update_via_file(f,invocation);
31 return TRUE;
32}
33
34static void
35on_bus_acquired (GDBusConnection *connection,
36 const gchar *name,
37 gpointer user_data)
38{
Norman James10ff6a32015-08-27 14:24:17 -050039 ObjectSkeleton *object;
40 g_print ("Acquired a message bus connection: %s\n",name);
41 cmdline *cmd = user_data;
42 if (cmd->argc < 2)
43 {
44 g_print("No objects created. Put object name(s) on command line\n");
45 return;
46 }
47 manager = g_dbus_object_manager_server_new (dbus_object_path);
48 int i=0;
49 for (i=1;i<cmd->argc;i++)
50 {
51 gchar *s;
52 s = g_strdup_printf ("%s/%s",dbus_object_path,cmd->argv[i]);
53 object = object_skeleton_new (s);
54 g_free (s);
Norman Jamese2765102015-08-19 22:00:55 -050055
Norman James10ff6a32015-08-27 14:24:17 -050056 Flash* flash = flash_skeleton_new ();
57 object_skeleton_set_flash (object, flash);
58 g_object_unref (flash);
Norman Jamese2765102015-08-19 22:00:55 -050059
Norman James10ff6a32015-08-27 14:24:17 -050060 //define method callbacks here
61 g_signal_connect (flash,
Norman Jamese2765102015-08-19 22:00:55 -050062 "handle-update-via-file",
63 G_CALLBACK (on_update_via_file),
64 NULL); /* user_data */
65
Norman James10ff6a32015-08-27 14:24:17 -050066 /* Export the object (@manager takes its own reference to @object) */
67 g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
68 g_object_unref (object);
69 }
Norman Jamese2765102015-08-19 22:00:55 -050070
Norman James10ff6a32015-08-27 14:24:17 -050071 /* Export all objects */
72 g_dbus_object_manager_server_set_connection (manager, connection);
Norman Jamese2765102015-08-19 22:00:55 -050073}
74
75static void
76on_name_acquired (GDBusConnection *connection,
77 const gchar *name,
78 gpointer user_data)
79{
80 g_print ("Acquired the name %s\n", name);
81}
82
83static void
84on_name_lost (GDBusConnection *connection,
85 const gchar *name,
86 gpointer user_data)
87{
88 g_print ("Lost the name %s\n", name);
89}
90
91gint
92main (gint argc, gchar *argv[])
93{
94 GMainLoop *loop;
95
96 guint id;
97 //g_type_init ();
98 loop = g_main_loop_new (NULL, FALSE);
99
100 id = g_bus_own_name (G_BUS_TYPE_SESSION,
Norman James26072c02015-08-25 07:14:29 -0500101 dbus_name,
Norman Jamese2765102015-08-19 22:00:55 -0500102 G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
103 G_BUS_NAME_OWNER_FLAGS_REPLACE,
104 on_bus_acquired,
105 on_name_acquired,
106 on_name_lost,
107 loop,
108 NULL);
109
110 g_main_loop_run (loop);
111
112 g_bus_unown_name (id);
113 g_main_loop_unref (loop);
114 return 0;
115}