Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 1 | #include "interfaces/openbmc_intf.h"
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 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 | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 6 | static const gchar* dbus_object_path = "/org/openbmc/flash";
|
Norman James | 26072c0 | 2015-08-25 07:14:29 -0500 | [diff] [blame] | 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
|
Norman James | 471ab59 | 2015-08-30 22:29:40 -0500 | [diff] [blame] | 12 | on_init (Flash *f,
|
| 13 | GDBusMethodInvocation *invocation,
|
| 14 | gpointer user_data)
|
| 15 | {
|
| 16 | flash_complete_init(f,invocation);
|
| 17 | return TRUE;
|
| 18 |
|
| 19 | }
|
| 20 |
|
| 21 | static gboolean
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 22 | on_update_via_file (Flash *f,
|
| 23 | GDBusMethodInvocation *invocation,
|
| 24 | gchar* write_file,
|
| 25 | gpointer user_data)
|
| 26 | {
|
| 27 | g_print("Flashing BIOS from file\n");
|
| 28 | // get size from file
|
| 29 | struct stat stbuf;
|
| 30 | uint32_t address = 0, read_size = 0, write_size = 0;
|
| 31 |
|
| 32 | if (stat(write_file, &stbuf))
|
| 33 | {
|
| 34 | g_print("Failed to get file size");
|
| 35 | //TODO: Error handling
|
| 36 | }
|
| 37 | write_size = stbuf.st_size;
|
| 38 | erase_chip();
|
| 39 | program_file(write_file, address, write_size);
|
| 40 | flash_complete_update_via_file(f,invocation);
|
| 41 | return TRUE;
|
| 42 | }
|
| 43 |
|
| 44 | static void
|
| 45 | on_bus_acquired (GDBusConnection *connection,
|
| 46 | const gchar *name,
|
| 47 | gpointer user_data)
|
| 48 | {
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 49 | ObjectSkeleton *object;
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 50 | // g_print ("Acquired a message bus connection: %s\n",name);
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 51 | cmdline *cmd = user_data;
|
| 52 | if (cmd->argc < 2)
|
| 53 | {
|
| 54 | g_print("No objects created. Put object name(s) on command line\n");
|
| 55 | return;
|
| 56 | }
|
| 57 | manager = g_dbus_object_manager_server_new (dbus_object_path);
|
| 58 | int i=0;
|
| 59 | for (i=1;i<cmd->argc;i++)
|
| 60 | {
|
| 61 | gchar *s;
|
| 62 | s = g_strdup_printf ("%s/%s",dbus_object_path,cmd->argv[i]);
|
| 63 | object = object_skeleton_new (s);
|
| 64 | g_free (s);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 65 |
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 66 | Flash* flash = flash_skeleton_new ();
|
| 67 | object_skeleton_set_flash (object, flash);
|
| 68 | g_object_unref (flash);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 69 |
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 70 | //define method callbacks here
|
| 71 | g_signal_connect (flash,
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 72 | "handle-update-via-file",
|
| 73 | G_CALLBACK (on_update_via_file),
|
| 74 | NULL); /* user_data */
|
Norman James | 471ab59 | 2015-08-30 22:29:40 -0500 | [diff] [blame] | 75 |
|
| 76 | g_signal_connect (flash,
|
| 77 | "handle-init",
|
| 78 | G_CALLBACK (on_init),
|
| 79 | NULL); /* user_data */
|
| 80 |
|
| 81 |
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 82 | /* Export the object (@manager takes its own reference to @object) */
|
| 83 | g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
|
| 84 | g_object_unref (object);
|
| 85 | }
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 86 |
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 87 | /* Export all objects */
|
| 88 | g_dbus_object_manager_server_set_connection (manager, connection);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 89 | }
|
| 90 |
|
| 91 | static void
|
| 92 | on_name_acquired (GDBusConnection *connection,
|
| 93 | const gchar *name,
|
| 94 | gpointer user_data)
|
| 95 | {
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 96 | // g_print ("Acquired the name %s\n", name);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 97 | }
|
| 98 |
|
| 99 | static void
|
| 100 | on_name_lost (GDBusConnection *connection,
|
| 101 | const gchar *name,
|
| 102 | gpointer user_data)
|
| 103 | {
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 104 | //g_print ("Lost the name %s\n", name);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 105 | }
|
| 106 |
|
| 107 | gint
|
| 108 | main (gint argc, gchar *argv[])
|
| 109 | {
|
| 110 | GMainLoop *loop;
|
Norman James | 952b38d | 2015-08-27 21:30:06 -0500 | [diff] [blame] | 111 | cmdline cmd;
|
| 112 | cmd.argc = argc;
|
| 113 | cmd.argv = argv;
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 114 |
|
| 115 | guint id;
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 116 | loop = g_main_loop_new (NULL, FALSE);
|
| 117 |
|
| 118 | id = g_bus_own_name (G_BUS_TYPE_SESSION,
|
Norman James | 26072c0 | 2015-08-25 07:14:29 -0500 | [diff] [blame] | 119 | dbus_name,
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 120 | G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
|
| 121 | G_BUS_NAME_OWNER_FLAGS_REPLACE,
|
| 122 | on_bus_acquired,
|
| 123 | on_name_acquired,
|
| 124 | on_name_lost,
|
Norman James | 952b38d | 2015-08-27 21:30:06 -0500 | [diff] [blame] | 125 | &cmd,
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 126 | NULL);
|
| 127 |
|
| 128 | g_main_loop_run (loop);
|
| 129 |
|
| 130 | g_bus_unown_name (id);
|
| 131 | g_main_loop_unref (loop);
|
| 132 | return 0;
|
| 133 | }
|