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 * run_kexec_local - Final kexec helper.
37 * @l_image: The local image file for kexec to execute.
38 * @l_initrd: Optional local initrd file for kexec --initrd, can be NULL.
39 * @args: Optional command line args for kexec --append, can be NULL.
42 static int run_kexec_local(const char *l_image, const char *l_initrd,
50 *p++ = pb_system_apps.kexec; /* 1 */
53 *p++ = "--initrd"; /* 2 */
54 *p++ = l_initrd; /* 3 */
58 *p++ = "--append"; /* 4 */
62 /* First try by telling kexec to run shutdown */
67 result = pb_run_cmd(argv);
69 /* kexec will return zero on success */
70 /* On error, force a kexec with the -f option */
73 *(p + 0) = "-f"; /* 6 */
74 *(p + 1) = l_image; /* 7 */
75 *(p + 2) = NULL; /* 8 */
77 result = pb_run_cmd(argv);
81 pb_log("%s: failed: (%d)\n", __func__, result);
87 * pb_run_kexec - Run kexec with the supplied boot options.
89 * For the convenience of the user, tries to load both files before
93 int pb_run_kexec(const struct pb_kexec_data *kd)
99 pb_log("%s: image: '%s'\n", __func__, kd->image);
100 pb_log("%s: initrd: '%s'\n", __func__, kd->initrd);
101 pb_log("%s: args: '%s'\n", __func__, kd->args);
104 l_image = pb_load_file(NULL, kd->image);
107 pb_log("%s: error null image\n", __func__);
110 l_initrd = kd->initrd ? pb_load_file(NULL, kd->initrd) : NULL;
112 if (!l_image || (kd->initrd && !l_initrd))
115 result = run_kexec_local(l_image, l_initrd, kd->args);
117 talloc_free(l_image);
118 talloc_free(l_initrd);
124 * pb_elf_hash - Standard elf hash routine.
127 unsigned int pb_elf_hash(const char *str)
129 unsigned int h = 0, g;
132 h = (h << 4) + *str++;
138 pb_log("%s: %x\n", __func__, h);
143 * pb_cat_hash - Hashes concatenation of two strings.
146 unsigned int pb_cat_hash(const char *a, const char *b)
151 s = talloc_asprintf(NULL, "%s%s", a, b);