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