blob: 7034e0c1cf4e221c3ce645c06e5a70b0d1f4f01b [file] [log] [blame]
Patrick Georgib7b56dd82009-09-14 13:29:27 +00001/*
2 * Copyright (C) 2009 coresystems GmbH
3 * written by Patrick Georgi <patrick.georgi@coresystems.de>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
17 */
18
19#include <stdint.h>
Stefan Reinauera1e48242011-10-21 14:24:57 -070020#include "swab.h"
21#define ntohl(x) (host_bigendian?(x):swab32(x))
22#define htonl(x) (host_bigendian?(x):swab32(x))
23#define ntohll(x) (host_bigendian?(x):swab64(x))
24#define htonll(x) (host_bigendian?(x):swab64(x))
Patrick Georgib7b56dd82009-09-14 13:29:27 +000025
26extern void *offset;
27extern struct cbfs_header *master_header;
28extern uint32_t phys_start, phys_end, align, romsize;
Stefan Reinauera1e48242011-10-21 14:24:57 -070029extern int host_bigendian;
Patrick Georgib7b56dd82009-09-14 13:29:27 +000030
Stefan Reinauera1e48242011-10-21 14:24:57 -070031static inline void *phys_to_virt(uint32_t addr)
Patrick Georgib7b56dd82009-09-14 13:29:27 +000032{
33 return offset + addr;
34}
35
Stefan Reinauera1e48242011-10-21 14:24:57 -070036static inline uint32_t virt_to_phys(void *addr)
Patrick Georgib7b56dd82009-09-14 13:29:27 +000037{
Stefan Reinauer853270a2009-09-22 15:55:01 +000038 return (unsigned long)(addr - offset) & 0xffffffff;
Patrick Georgib7b56dd82009-09-14 13:29:27 +000039}
40
41#define ALIGN(val, by) (((val) + (by)-1)&~((by)-1))
42
Patrick Georgi0da38dd2009-11-09 17:18:02 +000043uint32_t getfilesize(const char *filename);
Patrick Georgib7b56dd82009-09-14 13:29:27 +000044void *loadfile(const char *filename, uint32_t * romsize_p, void *content,
45 int place);
46void *loadrom(const char *filename);
Stefan Reinauer9bb043852010-06-24 13:37:59 +000047int writerom(const char *filename, void *start, uint32_t size);
Patrick Georgib7b56dd82009-09-14 13:29:27 +000048
49int iself(unsigned char *input);
50
51typedef void (*comp_func_ptr) (char *, int, char *, int *);
52typedef enum { CBFS_COMPRESS_NONE = 0, CBFS_COMPRESS_LZMA = 1 } comp_algo;
53
54comp_func_ptr compression_function(comp_algo algo);
55
56uint64_t intfiletype(const char *name);
57
58int parse_elf_to_payload(unsigned char *input, unsigned char **output,
59 comp_algo algo);
60int parse_elf_to_stage(unsigned char *input, unsigned char **output,
61 comp_algo algo, uint32_t * location);
62
63void *create_cbfs_file(const char *filename, void *data, uint32_t * datasize,
64 uint32_t type, uint32_t * location);
65
66int create_cbfs_image(const char *romfile, uint32_t romsize,
67 const char *bootblock, uint32_t align);
68
69int add_file_to_cbfs(void *content, uint32_t contentsize, uint32_t location);
70void print_cbfs_directory(const char *filename);
Aurelien Guillaumefe7d6b92011-01-13 09:09:21 +000071int extract_file_from_cbfs(const char *filename, const char *payloadname, const char *outpath);
Stefan Reinauer853270a2009-09-22 15:55:01 +000072
Patrick Georgi0da38dd2009-11-09 17:18:02 +000073uint32_t cbfs_find_location(const char *romfile, uint32_t filesize,
74 const char *filename, uint32_t align);
75
Stefan Reinauer07040582010-04-24 21:24:06 +000076void print_supported_filetypes(void);
77
Stefan Reinauer853270a2009-09-22 15:55:01 +000078#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))