/* * Copyright (C) 2010 Tobias Klauser * * This file is part of nios2sim-ng. * * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive * for more details. */ #include #include #include #include #include "nios2sim-ng.h" #include "memory.h" #include "image.h" int image_load(const char *image_path, int image_format, struct memory *mem) { FILE *fp; loader_func_t loader; int ret; switch(image_format) { case FORMAT_ELF: loader = elf_load; break; case FORMAT_SREC: loader = srec_load; break; default: err("Invalid image format\n"); return -1; } fp = fopen(image_path, "r"); if (unlikely(fp == NULL)) { err("Could not open image file '%s': %s\n", image_path, strerror(errno)); return -1; } ret = loader(fp, image_path, mem); fclose(fp); return ret; }