/*********************************************************************** * * Copyright (c) 2007 Broadcom Corporation * All Rights Reserved * * <:label-BRCM:2011:DUAL/GPL:standard * * Unless you and Broadcom execute a separate written software license * agreement governing use of this software, this software is licensed * to you under the terms of the GNU General Public License version 2 * (the "GPL"), available at http://www.broadcom.com/licenses/GPLv2.php, * with the following added to such license: * * As a special exception, the copyright holders of this software give * you permission to link this software with independent modules, and * to copy and distribute the resulting executable under terms of your * choice, provided that you also meet, for each linked independent * module, the terms and conditions of the license of that module. * An independent module is a module which is not derived from this * software. The special exception does not apply to any modifications * of the software. * * Not withstanding the above, under no circumstances may you combine * this software in any way with any other Broadcom software provided * under a license other than the GPL, without Broadcom's express prior * written consent. * * :> ************************************************************************/ #ifndef __CMS_IMAGE_H__ #define __CMS_IMAGE_H__ #include "cms.h" #include "bcm_imgutil_def.h" /*!\file cms_image.h * \brief Header file for public flash image functions. * * These functions can be included by any application, including GPL applications. * The image can be software images (cfe+fs+kernel, fs+kernel) or config files. * */ /** Minimum size for image uploads. * Config file uploads can be less than 2K. */ #define CMS_IMAGE_MIN_LEN 2048 /** For NAND ftpd upload, image size is not known and just set to 64MG as the max len * for memory allocation now and can be changed if needed later on. */ #define CMS_IMAGE_MAX_ALLOC_LEN 64 * 1024 * 1024 /** For NAND ftpd upload, the min required image size for image uploads for malloc is set to 4 MG * for memory allocation now and can be changed if needed. */ #define CMS_IMAGE_REQUIRED_LEN 4 * 1024 * 1024 /* The original definition of this enum is in tr69c/inc/tr69cdefs.h * It is copied here so that tr69c, cwmpd and cgi can all refer it * for image download. */ typedef enum { eFirmwareUpgrade=1, eWebContent =2, eVendorConfig =3, eVendorLog =4, eFirmwareStored =6 } eFileType; /*!\structure CmsImageTransferStats * \Keep track of upload/download image statistics */ typedef struct { UBOOL8 isDownload; /**< indicate whether transfer was a download(true) or upload(false). */ UINT8 fileType; /**< CmsImageFormat */ UINT32 fileSize; /**< size of file/image */ UINT32 faultCode; /**< fault code as defined in TR69 Amendment 5 */ char faultStr[BUFLEN_64]; /**< fault string as defined in TR69 Amendment 5; but reduce to 64 byte instead of 256 */ UINT32 startTime; /**< record at start of transfer number of seconds since Jan 1 1970. */ UINT32 completeTime; /**< record at end of transfer number of seconds since Jan 1 1970. */ } CmsImageTransferStats; /** Validate the given image and return the image format of the given image. * * The image can be a broadcom image, whole image, or config file. * This function will also verify that the image will fit in flash. * * @param imagePtr (IN) image to be parsed. * @param imageLen (IN) Length of image in bytes. * @param msgHandle (IN) message handle from the caller. * * @return CmsImageFormat enum. */ CmsImageFormat cmsImg_validateImage(const char *imagePtr, UINT32 imageLen, void *msgHandle); /** Write the image to flash. * The image can be a config file, a broadcom image, or flash image. * This function will validate the image before writing to flash. * * @param imagePtr (IN) image to be written. Surprisingly, for cfe+kernel+fs * flash writes, the image is modified, so we cannot * declare this parameter as const. * @param imageLen (IN) Length of image in bytes. * @param msgHandle (IN) message handle from the caller. * * @return CmsRet enum. */ CmsRet cmsImg_writeImage(char *imagePtr, UINT32 imageLen, void *msgHandle); CmsRet cmsImg_writeImage_noReboot(char *imagePtr, UINT32 imageLen, void *msgHandle); /** Just calls cmsImg_writeValidatedImageEx with opts=0 */ CmsRet cmsImg_writeValidatedImage(char *imagePtr, UINT32 imageLen, CmsImageFormat format, void *msgHandle); CmsRet cmsImg_writeValidatedImage_noReboot(char *imagePtr, UINT32 imageLen, CmsImageFormat format, void *msgHandle); CmsImageFormat cmsImg_parseImgHdr(UINT8 *bufP, UINT32 bufLen); /** Write a validated image in known format to flash. * The image can be a config file, a broadcom image, or flash image. * * @param imagePtr (IN) image to be written. Surprisingly, for cfe+kernel+fs * flash writes, the image is modified, so we cannot * declare this parameter as const. * @param imageLen (IN) Length of image in bytes. * @param format (IN) CmsImageFormat of the image. * @param msgHandle (IN) message handle from the caller. * @param opts (IN) Additional options, see CMS_IMAGE_WR_OPT_XXX above. * * @return CmsRet enum. */ CmsRet cmsImg_writeValidatedImageEx(char *imagePtr, UINT32 imageLen, CmsImageFormat format, void *msgHandle, UINT32 opts); void cmsImg_reboot(void); /** Return the number of bytes available in the flash for storing an image. * * Note this function does not return the size of the entire flash. * Rather, it returns the number of bytes available in * the flash for storing the image. * * @return the number of bytes available in the flash for storing an image. */ UINT32 cmsImg_getImageFlashSize(void); /** Return the number of bytes available in the flash for storing a config file. * * Note, if compressed config file is enabled, this function will return * a number that is larger than the actual number of bytes available in * the flash for storing the config file * * @return the number of bytes available for storing a config file. */ UINT32 cmsImg_getConfigFlashSize(void); /** Return the actual number of bytes available in the flash for storing a config file. * * This returns the actual number of bytes available in the flash for * storing a config file. External callers should not use this function. * * @return the number of bytes available for storing a config file. */ UINT32 cmsImg_getRealConfigFlashSize(void); /** Return TRUE if the flash has space for a backup config file. * * @return TRUE if the flash has space for a backup config file. */ UBOOL8 cmsImg_isBackupConfigFlashAvailable(void); /** Return the size, in bytes, of the broadcom image tag header. * * @return the number of bytes in the broadcom image tag header that is present * at the beginning of broadcom images. */ UINT32 cmsImg_getBroadcomImageTagSize(void); /** Return true if the image will fit in the flash. * * Compares the given image length with the image flash size minus a * CMS_IMAGE_OVERHEAD margin. Do we really need to have this margin? * Currently, only httpd uses this code. * * @param imageLen (IN) Length of image in bytes. * * @return True if the image will fit in the flash. */ UBOOL8 cmsImg_willFitInFlash(UINT32 imageLen); #define CMS_CONFIG_XML_TAG "