pc1crypt: make decrypt/encrypt functions take void * as argument
[project/firmware-utils.git] / src / mkdlinkfw-lib.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * mkdlinkfw
4 *
5 * Copyright (C) 2018 Paweł Dembicki <paweldembicki@gmail.com>
6 *
7 * This tool is based on mktplinkfw.
8 * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
9 * Copyright (C) 2008,2009 Wang Jian <lark@linux.net.cn>
10 */
11
12 #ifndef mkdlinkfw_lib_h
13 #define mkdlinkfw_lib_h
14
15 #define AUH_MAGIC "DLK"
16 #define AUH_SIZE 80
17 #define AUH_LVPS 0x01
18 #define AUH_HDR_ID 0x4842
19 #define AUH_HDR_VER 0x02
20 #define AUH_SEC_ID 0x04
21 #define AUH_INFO_TYPE 0x04
22
23 #define STAG_SIZE 16
24 #define STAG_ID 0x04
25 #define STAG_MAGIC 0x2B24
26 #define STAG_CMARK_FACTORY 0xFF
27
28 #define SCH2_SIZE 40
29 #define SCH2_MAGIC 0x2124
30 #define SCH2_VER 0x02
31
32 /*
33 * compression type values in the header
34 * so far onlysupport for LZMA is added
35 */
36 #define FLAT 0
37 #define JZ 1
38 #define GZIP 2
39 #define LZMA 3
40
41 #define RAM_ENTRY_ADDR 0x80000000
42 #define RAM_LOAD_ADDR 0x80000000
43 #define JBOOT_SIZE 0x10000
44
45 #define ALL_HEADERS_SIZE (AUH_SIZE + STAG_SIZE + SCH2_SIZE)
46 #define MAX_HEADER_COUNTER 10
47 #define TIMESTAMP_MAGIC 0x35016f00L
48
49 #define FACTORY 0
50 #define SYSUPGRADE 1
51
52 #define ERR(fmt, ...) do { \
53 fflush(0); \
54 fprintf(stderr, "[%s] *** error: " fmt "\n", \
55 progname, ## __VA_ARGS__); \
56 } while (0)
57
58 #define ERRS(fmt, ...) do { \
59 int save = errno; \
60 fflush(0); \
61 fprintf(stderr, "[%s] *** error: " fmt ": %s\n", \
62 progname, ## __VA_ARGS__, strerror(save)); \
63 } while (0)
64
65 #define DBG(fmt, ...) do { \
66 fprintf(stderr, "[%s] " fmt "\n", progname, ## __VA_ARGS__); \
67 } while (0)
68
69 struct file_info {
70 char *file_name; /* name of the file */
71 uint32_t file_size; /* length of the file */
72 };
73
74 uint32_t jboot_timestamp(void);
75 uint16_t jboot_checksum(uint16_t start_val, uint16_t *data, int size);
76 int get_file_stat(struct file_info *fdata);
77 int read_to_buf(const struct file_info *fdata, char *buf);
78 int write_fw(const char *ofname, const char *data, int len);
79
80 #endif /* mkdlinkfw_lib_h */