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 | |
Stefan Reinauer | 6321758 | 2012-10-29 16:52:36 -0700 | [diff] [blame] | 19 | #ifndef __CBFSTOOL_COMMON_H |
| 20 | #define __CBFSTOOL_COMMON_H |
| 21 | |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 22 | #include <stdint.h> |
Stefan Reinauer | a1e4824 | 2011-10-21 14:24:57 -0700 | [diff] [blame] | 23 | #include "swab.h" |
| 24 | #define ntohl(x) (host_bigendian?(x):swab32(x)) |
| 25 | #define htonl(x) (host_bigendian?(x):swab32(x)) |
| 26 | #define ntohll(x) (host_bigendian?(x):swab64(x)) |
| 27 | #define htonll(x) (host_bigendian?(x):swab64(x)) |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 28 | |
| 29 | extern void *offset; |
Stefan Reinauer | 6321758 | 2012-10-29 16:52:36 -0700 | [diff] [blame] | 30 | extern uint32_t romsize; |
Stefan Reinauer | a1e4824 | 2011-10-21 14:24:57 -0700 | [diff] [blame] | 31 | extern int host_bigendian; |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 32 | |
Stefan Reinauer | a1e4824 | 2011-10-21 14:24:57 -0700 | [diff] [blame] | 33 | static inline void *phys_to_virt(uint32_t addr) |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 34 | { |
| 35 | return offset + addr; |
| 36 | } |
| 37 | |
Stefan Reinauer | a1e4824 | 2011-10-21 14:24:57 -0700 | [diff] [blame] | 38 | static inline uint32_t virt_to_phys(void *addr) |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 39 | { |
Stefan Reinauer | 853270a | 2009-09-22 15:55:01 +0000 | [diff] [blame] | 40 | return (unsigned long)(addr - offset) & 0xffffffff; |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | #define ALIGN(val, by) (((val) + (by)-1)&~((by)-1)) |
| 44 | |
Stefan Reinauer | 6321758 | 2012-10-29 16:52:36 -0700 | [diff] [blame] | 45 | size_t getfilesize(const char *filename); |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 46 | void *loadfile(const char *filename, uint32_t * romsize_p, void *content, |
| 47 | int place); |
| 48 | void *loadrom(const char *filename); |
Stefan Reinauer | 9bb04385 | 2010-06-24 13:37:59 +0000 | [diff] [blame] | 49 | int writerom(const char *filename, void *start, uint32_t size); |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 50 | |
| 51 | int iself(unsigned char *input); |
| 52 | |
| 53 | typedef void (*comp_func_ptr) (char *, int, char *, int *); |
| 54 | typedef enum { CBFS_COMPRESS_NONE = 0, CBFS_COMPRESS_LZMA = 1 } comp_algo; |
| 55 | |
| 56 | comp_func_ptr compression_function(comp_algo algo); |
| 57 | |
| 58 | uint64_t intfiletype(const char *name); |
| 59 | |
| 60 | int parse_elf_to_payload(unsigned char *input, unsigned char **output, |
| 61 | comp_algo algo); |
| 62 | int parse_elf_to_stage(unsigned char *input, unsigned char **output, |
| 63 | comp_algo algo, uint32_t * location); |
| 64 | |
| 65 | void *create_cbfs_file(const char *filename, void *data, uint32_t * datasize, |
| 66 | uint32_t type, uint32_t * location); |
| 67 | |
| 68 | int create_cbfs_image(const char *romfile, uint32_t romsize, |
Stefan Reinauer | a90bd52 | 2012-08-15 16:05:50 -0700 | [diff] [blame] | 69 | const char *bootblock, uint32_t align, uint32_t offs); |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 70 | |
| 71 | int add_file_to_cbfs(void *content, uint32_t contentsize, uint32_t location); |
Stefan Reinauer | a90bd52 | 2012-08-15 16:05:50 -0700 | [diff] [blame] | 72 | int remove_file_from_cbfs(const char *filename); |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 73 | void print_cbfs_directory(const char *filename); |
Aurelien Guillaume | fe7d6b9 | 2011-01-13 09:09:21 +0000 | [diff] [blame] | 74 | int extract_file_from_cbfs(const char *filename, const char *payloadname, const char *outpath); |
Mathias Krause | 5c581c4 | 2012-07-17 21:11:59 +0200 | [diff] [blame] | 75 | int remove_file_from_cbfs(const char *filename); |
Stefan Reinauer | 853270a | 2009-09-22 15:55:01 +0000 | [diff] [blame] | 76 | |
Patrick Georgi | 0da38dd | 2009-11-09 17:18:02 +0000 | [diff] [blame] | 77 | uint32_t cbfs_find_location(const char *romfile, uint32_t filesize, |
| 78 | const char *filename, uint32_t align); |
| 79 | |
Stefan Reinauer | 0704058 | 2010-04-24 21:24:06 +0000 | [diff] [blame] | 80 | void print_supported_filetypes(void); |
| 81 | |
Stefan Reinauer | 6321758 | 2012-10-29 16:52:36 -0700 | [diff] [blame] | 82 | #define ARRAY_SIZE(a) (int)(sizeof(a) / sizeof((a)[0])) |
| 83 | |
| 84 | #endif |