2 * Copyright (C) 2009 Sony Computer Entertainment Inc.
3 * Copyright 2009 Sony Corp.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <sys/types.h>
30 #include <system/system.h>
31 #include "talloc/talloc.h"
33 #include "ui-system.h"
36 * pb_start_daemon - start the pb-discover daemon.
39 int pb_start_daemon(void)
43 char *name = talloc_asprintf(NULL, "%s/sbin/pb-discover",
44 pb_system_apps.prefix);
49 result = pb_run_cmd(argv, 0, 0);
54 pb_log("%s: failed: (%d)\n", __func__, result);
60 * kexec_load - kexec load helper.
61 * @l_image: The local image file for kexec to execute.
62 * @l_initrd: Optional local initrd file for kexec --initrd, can be NULL.
63 * @args: Optional command line args for kexec --append, can be NULL.
66 static int kexec_load(const char *l_image, const char *l_initrd,
67 const char *args, int dry_run)
72 char *s_initrd = NULL;
76 *p++ = pb_system_apps.kexec; /* 1 */
80 s_initrd = talloc_asprintf(NULL, "--initrd=%s", l_initrd);
82 *p++ = s_initrd; /* 3 */
86 s_args = talloc_asprintf(NULL, "--append=%s", args);
88 *p++ = s_args; /* 4 */
91 *p++ = l_image; /* 5 */
94 result = pb_run_cmd(argv, 1, dry_run);
97 pb_log("%s: failed: (%d)\n", __func__, result);
99 talloc_free(s_initrd);
106 * kexec_reboot - Helper to boot the new kernel.
108 * Must only be called after a successful call to kexec_load().
111 static int kexec_reboot(int dry_run)
117 /* First try running shutdown. Init scripts should run 'exec -e' */
120 *p++ = pb_system_apps.shutdown; /* 1 */
122 *p++ = "now"; /* 3 */
125 result = pb_run_cmd(argv, 1, dry_run);
127 /* On error, force a kexec with the -e option */
131 *p++ = pb_system_apps.kexec; /* 1 */
135 result = pb_run_cmd(argv, 1, 0);
139 pb_log("%s: failed: (%d)\n", __func__, result);
145 * pb_run_kexec - Run kexec with the supplied boot options.
148 int pb_run_kexec(const struct pb_kexec_data *kd, int dry_run)
151 char *l_image = NULL;
152 char *l_initrd = NULL;
153 unsigned int clean_image = 0;
154 unsigned int clean_initrd = 0;
156 pb_log("%s: image: '%s'\n", __func__, kd->image);
157 pb_log("%s: initrd: '%s'\n", __func__, kd->initrd);
158 pb_log("%s: args: '%s'\n", __func__, kd->args);
163 l_image = pb_load_file(NULL, kd->image, &clean_image);
169 l_initrd = pb_load_file(NULL, kd->initrd, &clean_initrd);
174 if (!l_image && !l_initrd)
177 result = kexec_load(l_image, l_initrd, kd->args, dry_run);
185 talloc_free(l_image);
186 talloc_free(l_initrd);
189 result = kexec_reboot(dry_run);
195 * pb_elf_hash - Standard elf hash routine.
198 unsigned int pb_elf_hash(const char *str)
200 unsigned int h = 0, g;
203 h = (h << 4) + *str++;
209 pb_log("%s: %x\n", __func__, h);
214 * pb_cat_hash - Hashes concatenation of two strings.
217 unsigned int pb_cat_hash(const char *a, const char *b)
222 s = talloc_asprintf(NULL, "%s%s", a, b);