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