]> git.ozlabs.org Git - petitboot/blob - discover/parser-utils.c
Use yaboot global boot option
[petitboot] / discover / parser-utils.c
1
2 #include <string.h>
3
4 #include <log/log.h>
5 #include <talloc/talloc.h>
6
7 #include "pb-protocol/pb-protocol.h"
8 #include "event.h"
9 #include "udev.h"
10 #include "device-handler.h"
11 #include "parser-utils.h"
12
13 void device_add_boot_option(struct device *device,
14                 struct boot_option *boot_option)
15 {
16         pb_log("%s: %s\n", __func__, device->id);
17         pb_log(" id     '%s'\n", boot_option->id);
18         pb_log(" name   '%s'\n", boot_option->name);
19         pb_log(" descr  '%s'\n", boot_option->description);
20         pb_log(" icon   '%s'\n", boot_option->icon_file);
21         pb_log(" image  '%s'\n", boot_option->boot_image_file);
22         pb_log(" initrd '%s'\n", boot_option->initrd_file);
23         pb_log(" args   '%s'\n", boot_option->boot_args);
24         list_add(&device->boot_options, &boot_option->list);
25         talloc_steal(device, boot_option);
26 }
27
28 const char *generic_icon_file(enum generic_icon_type type)
29 {
30         switch (type) {
31         case ICON_TYPE_DISK:
32                 return artwork_pathname("hdd.png");
33         case ICON_TYPE_USB:
34                 return artwork_pathname("usbpen.png");
35         case ICON_TYPE_OPTICAL:
36                 return artwork_pathname("cdrom.png");
37         case ICON_TYPE_NETWORK:
38         case ICON_TYPE_UNKNOWN:
39                 break;
40         }
41         return artwork_pathname("hdd.png");
42 }
43
44 enum generic_icon_type guess_device_type(struct discover_context *ctx)
45 {
46         struct event *event;
47         const char *type, *bus;
48
49         event = ctx->event;
50
51         type = event_get_param(event, "ID_TYPE");
52         bus = event_get_param(event, "ID_BUS");
53
54         if (type && streq(type, "cd"))
55                 return ICON_TYPE_OPTICAL;
56         if (!bus)
57                 return ICON_TYPE_UNKNOWN;
58         if (streq(bus, "usb"))
59                 return ICON_TYPE_USB;
60         if (streq(bus, "ata") || streq(bus, "scsi"))
61                 return ICON_TYPE_DISK;
62         return ICON_TYPE_UNKNOWN;
63 }