2 * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
4 * This tool was based on:
5 * TP-Link WR941 V2 firmware checksum fixing tool.
6 * Copyright (C) 2008,2009 Wang Jian <lark@linux.net.cn>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published
10 * by the Free Software Foundation.
15 #ifndef mktplinkfw_lib_h
16 #define mktplinkfw_lib_h
18 #define ALIGN(x,a) ({ typeof(a) __a = (a); (((x) + __a - 1) & ~(__a - 1)); })
19 #define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0]))
26 #define ERR(fmt, ...) do { \
28 fprintf(stderr, "[%s] *** error: " fmt "\n", \
29 progname, ## __VA_ARGS__ ); \
32 #define ERRS(fmt, ...) do { \
35 fprintf(stderr, "[%s] *** error: " fmt ": %s\n", \
36 progname, ## __VA_ARGS__, strerror(save)); \
39 #define DBG(fmt, ...) do { \
40 fprintf(stderr, "[%s] " fmt "\n", progname, ## __VA_ARGS__ ); \
45 char *file_name
; /* name of the file */
46 uint32_t file_size
; /* length of the file */
57 struct flash_layout
*find_layout(struct flash_layout
*layouts
, const char *id
);
58 void get_md5(const char *data
, int size
, uint8_t *md5
);
59 int get_file_stat(struct file_info
*fdata
);
60 int read_to_buf(const struct file_info
*fdata
, char *buf
);
61 int pad_jffs2(char *buf
, int currlen
, int maxlen
);
62 int write_fw(const char *ofname
, const char *data
, int len
);
63 inline void inspect_fw_pstr(const char *label
, const char *str
);
64 inline void inspect_fw_phex(const char *label
, uint32_t val
);
65 inline void inspect_fw_phexdec(const char *label
, uint32_t val
);
66 inline void inspect_fw_pmd5sum(const char *label
, const uint8_t *val
, const char *text
);
68 #endif /* mktplinkfw_lib_h */