Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 1 | #include "interfaces/flash.h"
|
| 2 | #include "pflash/pflash.c"
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 3 | #include "openbmc.h"
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 4 |
|
| 5 | /* ---------------------------------------------------------------------------------------------------- */
|
Norman James | 26072c0 | 2015-08-25 07:14:29 -0500 | [diff] [blame] | 6 | static const gchar* dbus_object_path = "/org/openbmc/flash/BIOS";
|
| 7 | static const gchar* dbus_name = "org.openbmc.flash.BIOS";
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 8 |
|
| 9 | static GDBusObjectManagerServer *manager = NULL;
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 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 | {
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 39 | 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 James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 55 |
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 56 | Flash* flash = flash_skeleton_new ();
|
| 57 | object_skeleton_set_flash (object, flash);
|
| 58 | g_object_unref (flash);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 59 |
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 60 | //define method callbacks here
|
| 61 | g_signal_connect (flash,
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 62 | "handle-update-via-file",
|
| 63 | G_CALLBACK (on_update_via_file),
|
| 64 | NULL); /* user_data */
|
| 65 |
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 66 | /* 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 James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 70 |
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 71 | /* Export all objects */
|
| 72 | g_dbus_object_manager_server_set_connection (manager, connection);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 73 | }
|
| 74 |
|
| 75 | static void
|
| 76 | on_name_acquired (GDBusConnection *connection,
|
| 77 | const gchar *name,
|
| 78 | gpointer user_data)
|
| 79 | {
|
| 80 | g_print ("Acquired the name %s\n", name);
|
| 81 | }
|
| 82 |
|
| 83 | static void
|
| 84 | on_name_lost (GDBusConnection *connection,
|
| 85 | const gchar *name,
|
| 86 | gpointer user_data)
|
| 87 | {
|
| 88 | g_print ("Lost the name %s\n", name);
|
| 89 | }
|
| 90 |
|
| 91 | gint
|
| 92 | main (gint argc, gchar *argv[])
|
| 93 | {
|
| 94 | GMainLoop *loop;
|
Norman James | 952b38d | 2015-08-27 21:30:06 -0500 | [diff] [blame] | 95 | cmdline cmd;
|
| 96 | cmd.argc = argc;
|
| 97 | cmd.argv = argv;
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 98 |
|
| 99 | guint id;
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 100 | loop = g_main_loop_new (NULL, FALSE);
|
| 101 |
|
| 102 | id = g_bus_own_name (G_BUS_TYPE_SESSION,
|
Norman James | 26072c0 | 2015-08-25 07:14:29 -0500 | [diff] [blame] | 103 | dbus_name,
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 104 | G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
|
| 105 | G_BUS_NAME_OWNER_FLAGS_REPLACE,
|
| 106 | on_bus_acquired,
|
| 107 | on_name_acquired,
|
| 108 | on_name_lost,
|
Norman James | 952b38d | 2015-08-27 21:30:06 -0500 | [diff] [blame] | 109 | &cmd,
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 110 | NULL);
|
| 111 |
|
| 112 | g_main_loop_run (loop);
|
| 113 |
|
| 114 | g_bus_unown_name (id);
|
| 115 | g_main_loop_unref (loop);
|
| 116 | return 0;
|
| 117 | }
|