blob: ede06e5340b26a041d1078046af639e63e27ecf8 [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>
20
21extern void *offset;
22extern struct cbfs_header *master_header;
23extern uint32_t phys_start, phys_end, align, romsize;
24
25static void *phys_to_virt(uint32_t addr)
26{
27 return offset + addr;
28}
29
30static uint32_t virt_to_phys(void *addr)
31{
Stefan Reinauer853270a2009-09-22 15:55:01 +000032 return (unsigned long)(addr - offset) & 0xffffffff;
Patrick Georgib7b56dd82009-09-14 13:29:27 +000033}
34
35#define ALIGN(val, by) (((val) + (by)-1)&~((by)-1))
36
Patrick Georgi0da38dd2009-11-09 17:18:02 +000037uint32_t getfilesize(const char *filename);
Patrick Georgib7b56dd82009-09-14 13:29:27 +000038void *loadfile(const char *filename, uint32_t * romsize_p, void *content,
39 int place);
40void *loadrom(const char *filename);
41void writerom(const char *filename, void *start, uint32_t size);
42
43int iself(unsigned char *input);
44
45typedef void (*comp_func_ptr) (char *, int, char *, int *);
46typedef enum { CBFS_COMPRESS_NONE = 0, CBFS_COMPRESS_LZMA = 1 } comp_algo;
47
48comp_func_ptr compression_function(comp_algo algo);
49
50uint64_t intfiletype(const char *name);
51
52int parse_elf_to_payload(unsigned char *input, unsigned char **output,
53 comp_algo algo);
54int parse_elf_to_stage(unsigned char *input, unsigned char **output,
55 comp_algo algo, uint32_t * location);
56
57void *create_cbfs_file(const char *filename, void *data, uint32_t * datasize,
58 uint32_t type, uint32_t * location);
59
60int create_cbfs_image(const char *romfile, uint32_t romsize,
61 const char *bootblock, uint32_t align);
62
63int add_file_to_cbfs(void *content, uint32_t contentsize, uint32_t location);
64void print_cbfs_directory(const char *filename);
Stefan Reinauer853270a2009-09-22 15:55:01 +000065
Patrick Georgi0da38dd2009-11-09 17:18:02 +000066uint32_t cbfs_find_location(const char *romfile, uint32_t filesize,
67 const char *filename, uint32_t align);
68
Stefan Reinauer853270a2009-09-22 15:55:01 +000069#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))