Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 1 | #include "interfaces/flash.h"
|
| 2 | #include "pflash/pflash.c"
|
| 3 |
|
| 4 | /* ---------------------------------------------------------------------------------------------------- */
|
| 5 |
|
| 6 | static GDBusObjectManagerServer *manager = NULL;
|
| 7 | static Flash *flash = NULL;
|
| 8 |
|
| 9 | static gboolean
|
| 10 | on_update_via_file (Flash *f,
|
| 11 | GDBusMethodInvocation *invocation,
|
| 12 | gchar* write_file,
|
| 13 | gpointer user_data)
|
| 14 | {
|
| 15 | g_print("Flashing BIOS from file\n");
|
| 16 | // get size from file
|
| 17 | struct stat stbuf;
|
| 18 | uint32_t address = 0, read_size = 0, write_size = 0;
|
| 19 |
|
| 20 | if (stat(write_file, &stbuf))
|
| 21 | {
|
| 22 | g_print("Failed to get file size");
|
| 23 | //TODO: Error handling
|
| 24 | }
|
| 25 | write_size = stbuf.st_size;
|
| 26 | erase_chip();
|
| 27 | program_file(write_file, address, write_size);
|
| 28 | flash_complete_update_via_file(f,invocation);
|
| 29 | return TRUE;
|
| 30 | }
|
| 31 |
|
| 32 | static void
|
| 33 | on_bus_acquired (GDBusConnection *connection,
|
| 34 | const gchar *name,
|
| 35 | gpointer user_data)
|
| 36 | {
|
| 37 | ObjectSkeleton *object;
|
| 38 | guint n;
|
| 39 |
|
| 40 | g_print ("Acquired a message bus connection: %s\n",name);
|
| 41 |
|
| 42 | manager = g_dbus_object_manager_server_new ("/org/openbmc/Flash/BIOS");
|
| 43 |
|
| 44 | gchar *s;
|
| 45 | s = g_strdup_printf ("/org/openbmc/Flash/BIOS/0");
|
| 46 | object = object_skeleton_new (s);
|
| 47 | g_free (s);
|
| 48 |
|
| 49 | flash = flash_skeleton_new ();
|
| 50 | object_skeleton_set_flash (object, flash);
|
| 51 | g_object_unref (flash);
|
| 52 |
|
| 53 | //define method callbacks here
|
| 54 | g_signal_connect (flash,
|
| 55 | "handle-update-via-file",
|
| 56 | G_CALLBACK (on_update_via_file),
|
| 57 | NULL); /* user_data */
|
| 58 |
|
| 59 | /* Export the object (@manager takes its own reference to @object) */
|
| 60 | g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
|
| 61 | g_object_unref (object);
|
| 62 |
|
| 63 | /* Export all objects */
|
| 64 | g_dbus_object_manager_server_set_connection (manager, connection);
|
| 65 | }
|
| 66 |
|
| 67 | static void
|
| 68 | on_name_acquired (GDBusConnection *connection,
|
| 69 | const gchar *name,
|
| 70 | gpointer user_data)
|
| 71 | {
|
| 72 | g_print ("Acquired the name %s\n", name);
|
| 73 | }
|
| 74 |
|
| 75 | static void
|
| 76 | on_name_lost (GDBusConnection *connection,
|
| 77 | const gchar *name,
|
| 78 | gpointer user_data)
|
| 79 | {
|
| 80 | g_print ("Lost the name %s\n", name);
|
| 81 | }
|
| 82 |
|
| 83 | gint
|
| 84 | main (gint argc, gchar *argv[])
|
| 85 | {
|
| 86 | GMainLoop *loop;
|
| 87 |
|
| 88 | guint id;
|
| 89 | //g_type_init ();
|
| 90 | loop = g_main_loop_new (NULL, FALSE);
|
| 91 |
|
| 92 | id = g_bus_own_name (G_BUS_TYPE_SESSION,
|
| 93 | "org.openbmc.Flash.BIOS",
|
| 94 | G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
|
| 95 | G_BUS_NAME_OWNER_FLAGS_REPLACE,
|
| 96 | on_bus_acquired,
|
| 97 | on_name_acquired,
|
| 98 | on_name_lost,
|
| 99 | loop,
|
| 100 | NULL);
|
| 101 |
|
| 102 | g_main_loop_run (loop);
|
| 103 |
|
| 104 | g_bus_unown_name (id);
|
| 105 | g_main_loop_unref (loop);
|
| 106 | return 0;
|
| 107 | }
|