/* * VAS_EBOOT -- GRand Unified Bootloader * Copyright (C) 2002,2003,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc. * * VAS_EBOOT is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * VAS_EBOOT is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with VAS_EBOOT. If not, see . */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define ENABLE_RELOCATABLE 0 #ifdef VAS_EBOOT_BUILD const char *program_name = VAS_EBOOT_BUILD_PROGRAM_NAME; #else #include "progname.h" #endif #ifdef VAS_EBOOT_UTIL int VasEBoot_err_printf (const char *fmt, ...) { va_list ap; int ret; va_start (ap, fmt); ret = vfprintf (stderr, fmt, ap); va_end (ap); return ret; } #endif char * VasEBoot_util_get_path (const char *dir, const char *file) { char *path; path = (char *) xmalloc (strlen (dir) + 1 + strlen (file) + 1); sprintf (path, "%s/%s", dir, file); return path; } char * VasEBoot_util_read_image (const char *path) { char *img; FILE *fp; size_t size; VasEBoot_util_info ("reading %s", path); size = VasEBoot_util_get_image_size (path); img = (char *) xmalloc (size); fp = VasEBoot_util_fopen (path, "rb"); if (! fp) VasEBoot_util_error (_("cannot open `%s': %s"), path, strerror (errno)); if (fread (img, 1, size, fp) != size) VasEBoot_util_error (_("cannot read `%s': %s"), path, strerror (errno)); fclose (fp); return img; } void VasEBoot_util_write_image_at (const void *img, size_t size, VasEBoot_off_t offset, FILE *out, const char *name) { VasEBoot_util_info ("writing 0x%" VAS_EBOOT_HOST_PRIxLONG_LONG " bytes at offset 0x%" VAS_EBOOT_HOST_PRIxLONG_LONG, (unsigned long long) size, (unsigned long long) offset); if (fseeko (out, offset, SEEK_SET) == -1) VasEBoot_util_error (_("cannot seek `%s': %s"), name, strerror (errno)); if (fwrite (img, 1, size, out) != size) VasEBoot_util_error (_("cannot write to `%s': %s"), name, strerror (errno)); } void VasEBoot_util_write_image (const char *img, size_t size, FILE *out, const char *name) { VasEBoot_util_info ("writing 0x%" VAS_EBOOT_HOST_PRIxLONG_LONG " bytes", (unsigned long long) size); if (fwrite (img, 1, size, out) != size) { if (!name) VasEBoot_util_error (_("cannot write to the stdout: %s"), strerror (errno)); else VasEBoot_util_error (_("cannot write to `%s': %s"), name, strerror (errno)); } } VasEBoot_err_t VasEBoot_script_execute_cmdline (struct VasEBoot_script_cmd *cmd __attribute__ ((unused))) { return 0; } VasEBoot_err_t VasEBoot_script_execute_cmdlist (struct VasEBoot_script_cmd *cmd __attribute__ ((unused))) { return 0; } VasEBoot_err_t VasEBoot_script_execute_cmdif (struct VasEBoot_script_cmd *cmd __attribute__ ((unused))) { return 0; } VasEBoot_err_t VasEBoot_script_execute_cmdfor (struct VasEBoot_script_cmd *cmd __attribute__ ((unused))) { return 0; } VasEBoot_err_t VasEBoot_script_execute_cmdwhile (struct VasEBoot_script_cmd *cmd __attribute__ ((unused))) { return 0; } VasEBoot_err_t VasEBoot_script_execute (struct VasEBoot_script *script) { if (script == 0 || script->cmd == 0) return 0; return script->cmd->exec (script->cmd); } int VasEBoot_getkey (void) { return -1; } void VasEBoot_refresh (void) { fflush (stdout); } static void VasEBoot_xputs_real (const char *str) { fputs (str, stdout); } void (*VasEBoot_xputs) (const char *str) = VasEBoot_xputs_real; VasEBoot_uint64_t VasEBoot_dl_ref (VasEBoot_dl_t mod) { (void) mod; return 0; } VasEBoot_uint64_t VasEBoot_dl_unref (VasEBoot_dl_t mod) { (void) mod; return 0; } /* Some functions that we don't use. */ void VasEBoot_mm_init_region (void *addr __attribute__ ((unused)), VasEBoot_size_t size __attribute__ ((unused))) { } void VasEBoot_register_exported_symbols (void) { } /* Used in comparison of arrays of strings with qsort */ int VasEBoot_qsort_strcmp (const void *p1, const void *p2) { return strcmp(*(char *const *)p1, *(char *const *)p2); }