2009-09-14 15:29:27 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2009 coresystems GmbH
|
|
|
|
* written by Patrick Georgi <patrick.georgi@coresystems.de>
|
|
|
|
*
|
|
|
|
* This program 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; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program 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 this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2011-10-21 23:24:57 +02:00
|
|
|
#include "swab.h"
|
|
|
|
#define ntohl(x) (host_bigendian?(x):swab32(x))
|
|
|
|
#define htonl(x) (host_bigendian?(x):swab32(x))
|
|
|
|
#define ntohll(x) (host_bigendian?(x):swab64(x))
|
|
|
|
#define htonll(x) (host_bigendian?(x):swab64(x))
|
2009-09-14 15:29:27 +02:00
|
|
|
|
|
|
|
extern void *offset;
|
|
|
|
extern struct cbfs_header *master_header;
|
|
|
|
extern uint32_t phys_start, phys_end, align, romsize;
|
2011-10-21 23:24:57 +02:00
|
|
|
extern int host_bigendian;
|
2009-09-14 15:29:27 +02:00
|
|
|
|
2011-10-21 23:24:57 +02:00
|
|
|
static inline void *phys_to_virt(uint32_t addr)
|
2009-09-14 15:29:27 +02:00
|
|
|
{
|
|
|
|
return offset + addr;
|
|
|
|
}
|
|
|
|
|
2011-10-21 23:24:57 +02:00
|
|
|
static inline uint32_t virt_to_phys(void *addr)
|
2009-09-14 15:29:27 +02:00
|
|
|
{
|
2009-09-22 17:55:01 +02:00
|
|
|
return (unsigned long)(addr - offset) & 0xffffffff;
|
2009-09-14 15:29:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#define ALIGN(val, by) (((val) + (by)-1)&~((by)-1))
|
|
|
|
|
2009-11-09 18:18:02 +01:00
|
|
|
uint32_t getfilesize(const char *filename);
|
2009-09-14 15:29:27 +02:00
|
|
|
void *loadfile(const char *filename, uint32_t * romsize_p, void *content,
|
|
|
|
int place);
|
|
|
|
void *loadrom(const char *filename);
|
2010-06-24 15:37:59 +02:00
|
|
|
int writerom(const char *filename, void *start, uint32_t size);
|
2009-09-14 15:29:27 +02:00
|
|
|
|
|
|
|
int iself(unsigned char *input);
|
|
|
|
|
|
|
|
typedef void (*comp_func_ptr) (char *, int, char *, int *);
|
|
|
|
typedef enum { CBFS_COMPRESS_NONE = 0, CBFS_COMPRESS_LZMA = 1 } comp_algo;
|
|
|
|
|
|
|
|
comp_func_ptr compression_function(comp_algo algo);
|
|
|
|
|
|
|
|
uint64_t intfiletype(const char *name);
|
|
|
|
|
|
|
|
int parse_elf_to_payload(unsigned char *input, unsigned char **output,
|
|
|
|
comp_algo algo);
|
|
|
|
int parse_elf_to_stage(unsigned char *input, unsigned char **output,
|
|
|
|
comp_algo algo, uint32_t * location);
|
|
|
|
|
|
|
|
void *create_cbfs_file(const char *filename, void *data, uint32_t * datasize,
|
|
|
|
uint32_t type, uint32_t * location);
|
|
|
|
|
|
|
|
int create_cbfs_image(const char *romfile, uint32_t romsize,
|
2012-08-16 01:05:50 +02:00
|
|
|
const char *bootblock, uint32_t align, uint32_t offs);
|
2009-09-14 15:29:27 +02:00
|
|
|
|
|
|
|
int add_file_to_cbfs(void *content, uint32_t contentsize, uint32_t location);
|
2012-08-16 01:05:50 +02:00
|
|
|
int remove_file_from_cbfs(const char *filename);
|
2009-09-14 15:29:27 +02:00
|
|
|
void print_cbfs_directory(const char *filename);
|
2011-01-13 10:09:21 +01:00
|
|
|
int extract_file_from_cbfs(const char *filename, const char *payloadname, const char *outpath);
|
2012-07-17 21:11:59 +02:00
|
|
|
int remove_file_from_cbfs(const char *filename);
|
2009-09-22 17:55:01 +02:00
|
|
|
|
2009-11-09 18:18:02 +01:00
|
|
|
uint32_t cbfs_find_location(const char *romfile, uint32_t filesize,
|
|
|
|
const char *filename, uint32_t align);
|
|
|
|
|
2010-04-24 23:24:06 +02:00
|
|
|
void print_supported_filetypes(void);
|
|
|
|
|
2009-09-22 17:55:01 +02:00
|
|
|
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
|