1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
5 * This tool was based on:
6 * TP-Link WR941 V2 firmware checksum fixing tool.
7 * Copyright (C) 2008,2009 Wang Jian <lark@linux.net.cn>
11 #ifndef mktplinkfw_lib_h
12 #define mktplinkfw_lib_h
14 #define ALIGN(x,a) ({ typeof(a) __a = (a); (((x) + __a - 1) & ~(__a - 1)); })
15 #define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0]))
22 #define ERR(fmt, ...) do { \
24 fprintf(stderr, "[%s] *** error: " fmt "\n", \
25 progname, ## __VA_ARGS__ ); \
28 #define ERRS(fmt, ...) do { \
31 fprintf(stderr, "[%s] *** error: " fmt ": %s\n", \
32 progname, ## __VA_ARGS__, strerror(save)); \
35 #define DBG(fmt, ...) do { \
36 fprintf(stderr, "[%s] " fmt "\n", progname, ## __VA_ARGS__ ); \
41 char *file_name
; /* name of the file */
42 uint32_t file_size
; /* length of the file */
53 struct flash_layout
*find_layout(struct flash_layout
*layouts
, const char *id
);
54 void get_md5(const char *data
, int size
, uint8_t *md5
);
55 int get_file_stat(struct file_info
*fdata
);
56 int read_to_buf(const struct file_info
*fdata
, char *buf
);
57 int write_fw(const char *ofname
, const char *data
, int len
);
58 inline void inspect_fw_pstr(const char *label
, const char *str
);
59 inline void inspect_fw_phex(const char *label
, uint32_t val
);
60 inline void inspect_fw_phexdec(const char *label
, uint32_t val
);
61 inline void inspect_fw_pmd5sum(const char *label
, const uint8_t *val
, const char *text
);
62 int build_fw(size_t header_size
);
64 #endif /* mktplinkfw_lib_h */