#ident "$Id: disk_common.h,v 1.5 2008/08/08 18:32:47 cnguyen Exp $"
/*
 *               Copyright (C) 2005, BroadOn Communications Corp.
 *
 *  These coded instructions, statements, and computer programs contain
 *  unpublished  proprietary information of BroadOn Communications Corp.,
 *  and  are protected by Federal copyright law. They may not be disclosed
 *  to  third  parties or copied or duplicated in any form, in whole or in
 *  part, without the prior written consent of BroadOn Communications Corp.
 */

/*
 * Header file for routines common to generating disk and partition
 * images
 */

#ifndef _DISK_COMMON_H_
#define _DISK_COMMON_H_

#include <stdbool.h>

#include "types.h"
#include "sha1.h"
#include "estypes.h"            // From NC/GBA tree
#include "es_int.h"             // From NC/GBA tree
#include "iosccert.h"           // From NC/GBA tree


#if (defined(htonll))
#undef htonll
#endif

#if (defined(ntohll))
#undef ntohll
#endif

// __tune_i686__ is set on Cygwin - it doesn't set i386 :(
#if defined(__ARMEL__) || defined(__i386__) || defined(__tune_i686__)
#define htonll(x) ((u64)( ((u64)((htonl((u32)(x)))) << 32) | (htonl((u32)(((u64)(x))>>32))) ))
#define ntohll(x) ((u64)( ((u64)((ntohl((u32)(x)))) << 32) | (ntohl((u32)(((u64)(x))>>32))) ))
#elif defined (__ARMEB__)
#define htonll(x) (x)
#define ntohll(x) (x)
#else
#error Undefined architecture
#endif

bool readBinFileIntoArray(const char* const fileName, u8 **array, u32 *size);
bool copyBinFileToOutFile(FILE *outFile, const char* const inFileName);
bool copyPartialBinFileToOutFile(FILE *outFile, const char* const inFileName,
                                 const off_t startPosition, const off_t length);
#endif
