Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 1 | #include "interfaces/flash.h"
|
| 2 | #include "pflash/pflash.c"
|
| 3 |
|
| 4 | /* ---------------------------------------------------------------------------------------------------- */
|
Norman James | 26072c0 | 2015-08-25 07:14:29 -0500 | [diff] [blame] | 5 | static const gchar* dbus_object_path = "/org/openbmc/flash/BIOS";
|
| 6 | static const gchar* dbus_name = "org.openbmc.flash.BIOS";
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 7 |
|
| 8 | static GDBusObjectManagerServer *manager = NULL;
|
| 9 | static Flash *flash = NULL;
|
| 10 |
|
| 11 | static gboolean
|
| 12 | on_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 |
|
| 34 | static void
|
| 35 | on_bus_acquired (GDBusConnection *connection,
|
| 36 | const gchar *name,
|
| 37 | gpointer user_data)
|
| 38 | {
|
| 39 | ObjectSkeleton *object;
|
| 40 | guint n;
|
| 41 |
|
| 42 | g_print ("Acquired a message bus connection: %s\n",name);
|
| 43 |
|
Norman James | 26072c0 | 2015-08-25 07:14:29 -0500 | [diff] [blame] | 44 | manager = g_dbus_object_manager_server_new (dbus_object_path);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 45 |
|
| 46 | gchar *s;
|
Norman James | 26072c0 | 2015-08-25 07:14:29 -0500 | [diff] [blame] | 47 | s = g_strdup_printf ("%s/0",dbus_object_path);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 48 | object = object_skeleton_new (s);
|
| 49 | g_free (s);
|
| 50 |
|
| 51 | flash = flash_skeleton_new ();
|
| 52 | object_skeleton_set_flash (object, flash);
|
| 53 | g_object_unref (flash);
|
| 54 |
|
| 55 | //define method callbacks here
|
| 56 | g_signal_connect (flash,
|
| 57 | "handle-update-via-file",
|
| 58 | G_CALLBACK (on_update_via_file),
|
| 59 | NULL); /* user_data */
|
| 60 |
|
| 61 | /* Export the object (@manager takes its own reference to @object) */
|
| 62 | g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
|
| 63 | g_object_unref (object);
|
| 64 |
|
| 65 | /* Export all objects */
|
| 66 | g_dbus_object_manager_server_set_connection (manager, connection);
|
| 67 | }
|
| 68 |
|
| 69 | static void
|
| 70 | on_name_acquired (GDBusConnection *connection,
|
| 71 | const gchar *name,
|
| 72 | gpointer user_data)
|
| 73 | {
|
| 74 | g_print ("Acquired the name %s\n", name);
|
| 75 | }
|
| 76 |
|
| 77 | static void
|
| 78 | on_name_lost (GDBusConnection *connection,
|
| 79 | const gchar *name,
|
| 80 | gpointer user_data)
|
| 81 | {
|
| 82 | g_print ("Lost the name %s\n", name);
|
| 83 | }
|
| 84 |
|
| 85 | gint
|
| 86 | main (gint argc, gchar *argv[])
|
| 87 | {
|
| 88 | GMainLoop *loop;
|
| 89 |
|
| 90 | guint id;
|
| 91 | //g_type_init ();
|
| 92 | loop = g_main_loop_new (NULL, FALSE);
|
| 93 |
|
| 94 | id = g_bus_own_name (G_BUS_TYPE_SESSION,
|
Norman James | 26072c0 | 2015-08-25 07:14:29 -0500 | [diff] [blame] | 95 | dbus_name,
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 96 | G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
|
| 97 | G_BUS_NAME_OWNER_FLAGS_REPLACE,
|
| 98 | on_bus_acquired,
|
| 99 | on_name_acquired,
|
| 100 | on_name_lost,
|
| 101 | loop,
|
| 102 | NULL);
|
| 103 |
|
| 104 | g_main_loop_run (loop);
|
| 105 |
|
| 106 | g_bus_unown_name (id);
|
| 107 | g_main_loop_unref (loop);
|
| 108 | return 0;
|
| 109 | }
|