/******************************************************************************/
/*                 Copyright C 1998-2002 Broadcom Corporation                 */
/*                                                                            */
/* This material is the confidential trade secret and proprietary information */
/* of Broadcom Corporation.  It may not be reproduced, used, sold or          */
/* transferred to any third party without the prior written consent of        */
/* Broadcom Corporation.   All rights reserved.                               */
/******************************************************************************/
/*   FileName        : bcm_loadImages.c                                       */
/*   Purpose         : Read the binaries images for booter and firmware from  */
/*                     specified file name                                    */
/*   Limitations     : None                                                   */
/*   Author          : Emmanuel Hanssens                                      */
/*   Creation Date   : 30-Apr-2002                                            */
/*   History         : Compiled by CVS                                        */
/******************************************************************************/
/*   $Id: bcm_loadImages.c,v 1.5 2004/09/27 15:33:11 hanssens Exp $  */
/******************************************************************************/

#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include "bcm_loadImages.h"
#include "bcm_errorHandler.h"

void loadImages(TargetImage* bootImage, TargetImage* fwImage)
{
  int         fd;
  struct stat fd_stat;
  extern char *firmware_image_file;

#if ! defined (NO_HOST_ACCESS) && ! defined (EEPROM_ON_BOARD)
  extern char *booter_image_file;

  /* open the booter image file */
  fd = open(booter_image_file, O_RDONLY);
  if (fd < 0)
    FATAL_ERROR("couldn't open %s for reading", booter_image_file);
  
  /* load into mem */
  fstat(fd, &fd_stat);
  bootImage->image = (uint8 *)
    mmap(0, fd_stat.st_size, PROT_READ, MAP_SHARED, fd, 0);
  bootImage->size = fd_stat.st_size;
  close(fd);
#else
  BCM_UNUSED_PARAMETER(bootImage);
#endif
  
  /* open the target image file */
  fd = open(firmware_image_file, O_RDONLY);
  if (fd < 0)
    FATAL_ERROR("couldn't open %s for reading", firmware_image_file);
  
  /* load into mem */
  fstat(fd, &fd_stat);
  fwImage->image = (uint8 *)
    mmap(0, fd_stat.st_size, PROT_READ, MAP_SHARED, fd, 0);
  fwImage->size = fd_stat.st_size;
  close(fd);
}
