Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 1 | /* |
| 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> |
Patrick Georgi | 26774f2 | 2009-11-21 19:54:02 +0000 | [diff] [blame] | 20 | #ifndef WIN32 |
| 21 | #include <arpa/inet.h> |
| 22 | #else |
| 23 | #define ntohl(x) (((x)>>24) | ((x)<<24) | (((x)>>8)&0xff00) | (((x)<<8)&0xff0000)) |
| 24 | #define htonl ntohl |
| 25 | #endif |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 26 | |
| 27 | extern void *offset; |
| 28 | extern struct cbfs_header *master_header; |
| 29 | extern uint32_t phys_start, phys_end, align, romsize; |
| 30 | |
| 31 | static void *phys_to_virt(uint32_t addr) |
| 32 | { |
| 33 | return offset + addr; |
| 34 | } |
| 35 | |
| 36 | static uint32_t virt_to_phys(void *addr) |
| 37 | { |
Stefan Reinauer | 853270a | 2009-09-22 15:55:01 +0000 | [diff] [blame] | 38 | return (unsigned long)(addr - offset) & 0xffffffff; |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | #define ALIGN(val, by) (((val) + (by)-1)&~((by)-1)) |
| 42 | |
Patrick Georgi | 0da38dd | 2009-11-09 17:18:02 +0000 | [diff] [blame] | 43 | uint32_t getfilesize(const char *filename); |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 44 | void *loadfile(const char *filename, uint32_t * romsize_p, void *content, |
| 45 | int place); |
| 46 | void *loadrom(const char *filename); |
Stefan Reinauer | 9bb04385 | 2010-06-24 13:37:59 +0000 | [diff] [blame^] | 47 | int writerom(const char *filename, void *start, uint32_t size); |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 48 | |
| 49 | int iself(unsigned char *input); |
| 50 | |
| 51 | typedef void (*comp_func_ptr) (char *, int, char *, int *); |
| 52 | typedef enum { CBFS_COMPRESS_NONE = 0, CBFS_COMPRESS_LZMA = 1 } comp_algo; |
| 53 | |
| 54 | comp_func_ptr compression_function(comp_algo algo); |
| 55 | |
| 56 | uint64_t intfiletype(const char *name); |
| 57 | |
| 58 | int parse_elf_to_payload(unsigned char *input, unsigned char **output, |
| 59 | comp_algo algo); |
| 60 | int parse_elf_to_stage(unsigned char *input, unsigned char **output, |
| 61 | comp_algo algo, uint32_t * location); |
| 62 | |
| 63 | void *create_cbfs_file(const char *filename, void *data, uint32_t * datasize, |
| 64 | uint32_t type, uint32_t * location); |
| 65 | |
| 66 | int create_cbfs_image(const char *romfile, uint32_t romsize, |
| 67 | const char *bootblock, uint32_t align); |
| 68 | |
| 69 | int add_file_to_cbfs(void *content, uint32_t contentsize, uint32_t location); |
| 70 | void print_cbfs_directory(const char *filename); |
Stefan Reinauer | 853270a | 2009-09-22 15:55:01 +0000 | [diff] [blame] | 71 | |
Patrick Georgi | 0da38dd | 2009-11-09 17:18:02 +0000 | [diff] [blame] | 72 | uint32_t cbfs_find_location(const char *romfile, uint32_t filesize, |
| 73 | const char *filename, uint32_t align); |
| 74 | |
Stefan Reinauer | 0704058 | 2010-04-24 21:24:06 +0000 | [diff] [blame] | 75 | void print_supported_filetypes(void); |
| 76 | |
Stefan Reinauer | 853270a | 2009-09-22 15:55:01 +0000 | [diff] [blame] | 77 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) |