OpenWrt – Diff between revs 2 and 3
?pathlinks?
Rev 2 | Rev 3 | |||
---|---|---|---|---|
Line 30... | Line 30... | |||
30 | |
30 | |
|
Line 31... | Line 31... | |||
31 | #include "mkdlinkfw-lib.h" |
31 | #include "mkdlinkfw-lib.h" |
|
Line -... | Line 32... | |||
- | 32 | |
||
- | 33 | extern char *progname; |
||
32 | |
34 | |
|
33 | extern char *progname; |
35 | static unsigned char jffs2_eof_mark[4] = { 0xde, 0xad, 0xc0, 0xde }; |
|
34 | |
- | ||
35 | uint32_t jboot_timestamp(void) |
- | ||
36 | { |
36 | |
|
37 | char *env = getenv("SOURCE_DATE_EPOCH"); |
- | ||
38 | char *endptr = env; |
- | ||
39 | time_t fixed_timestamp = -1; |
- | ||
40 | errno = 0; |
- | ||
41 | |
- | ||
42 | if (env && *env) { |
- | ||
43 | fixed_timestamp = strtoull(env, &endptr, 10); |
- | ||
44 | |
- | ||
45 | if (errno || (endptr && *endptr != '\0')) { |
- | ||
46 | fprintf(stderr, "Invalid SOURCE_DATE_EPOCH"); |
- | ||
47 | fixed_timestamp = -1; |
- | ||
48 | } |
- | ||
49 | } |
37 | uint32_t jboot_timestamp(void) |
|
50 | |
- | ||
51 | if (fixed_timestamp == -1) |
38 | { |
|
52 | time(&fixed_timestamp); |
39 | time_t rawtime; |
|
Line 53... | Line 40... | |||
53 | |
40 | time(&rawtime); |
|
54 | return (((uint32_t) fixed_timestamp) - TIMESTAMP_MAGIC) >> 2; |
41 | return (((uint32_t) rawtime) - TIMESTAMP_MAGIC) >> 2; |
|
55 | } |
42 | } |
|
Line 95... | Line 82... | |||
95 | |
82 | |
|
96 | int read_to_buf(const struct file_info *fdata, char *buf) |
83 | int read_to_buf(const struct file_info *fdata, char *buf) |
|
97 | { |
84 | { |
|
98 | FILE *f; |
85 | FILE *f; |
|
99 | int ret = EXIT_FAILURE; |
- | ||
Line 100... | Line 86... | |||
100 | size_t read; |
86 | int ret = EXIT_FAILURE; |
|
101 | |
87 | |
|
102 | f = fopen(fdata->file_name, "r"); |
88 | f = fopen(fdata->file_name, "r"); |
|
103 | if (f == NULL) { |
89 | if (f == NULL) { |
|
104 | ERRS("could not open \"%s\" for reading", fdata->file_name); |
90 | ERRS("could not open \"%s\" for reading", fdata->file_name); |
|
Line -... | Line 91... | |||
- | 91 | goto out; |
||
105 | goto out; |
92 | } |
|
106 | } |
93 | |
|
107 | |
94 | errno = 0; |
|
108 | read = fread(buf, fdata->file_size, 1, f); |
95 | fread(buf, fdata->file_size, 1, f); |
|
109 | if (ferror(f) || read != 1) { |
96 | if (errno != 0) { |
|
Line 110... | Line 97... | |||
110 | ERRS("unable to read from file \"%s\"", fdata->file_name); |
97 | ERRS("unable to read from file \"%s\"", fdata->file_name); |
|
Line 117... | Line 104... | |||
117 | fclose(f); |
104 | fclose(f); |
|
118 | out: |
105 | out: |
|
119 | return ret; |
106 | return ret; |
|
120 | } |
107 | } |
|
Line -... | Line 108... | |||
- | 108 | |
||
- | 109 | int pad_jffs2(char *buf, int currlen, int maxlen) |
||
- | 110 | { |
||
- | 111 | int len; |
||
- | 112 | uint32_t pad_mask; |
||
- | 113 | |
||
- | 114 | len = currlen; |
||
- | 115 | pad_mask = (4 * 1024) | (64 * 1024); /* EOF at 4KB and at 64KB */ |
||
- | 116 | while ((len < maxlen) && (pad_mask != 0)) { |
||
- | 117 | uint32_t mask; |
||
- | 118 | int i; |
||
- | 119 | |
||
- | 120 | for (i = 10; i < 32; i++) { |
||
- | 121 | mask = 1 << i; |
||
- | 122 | if (pad_mask & mask) |
||
- | 123 | break; |
||
- | 124 | } |
||
- | 125 | |
||
- | 126 | len = ALIGN(len, mask); |
||
- | 127 | |
||
- | 128 | for (i = 10; i < 32; i++) { |
||
- | 129 | mask = 1 << i; |
||
- | 130 | if ((len & (mask - 1)) == 0) |
||
- | 131 | pad_mask &= ~mask; |
||
- | 132 | } |
||
- | 133 | |
||
- | 134 | for (i = 0; i < sizeof(jffs2_eof_mark); i++) |
||
- | 135 | buf[len + i] = jffs2_eof_mark[i]; |
||
- | 136 | |
||
- | 137 | len += sizeof(jffs2_eof_mark); |
||
- | 138 | } |
||
- | 139 | |
||
- | 140 | return len; |
||
- | 141 | } |
||
121 | |
142 | |
|
122 | int write_fw(const char *ofname, const char *data, int len) |
143 | int write_fw(const char *ofname, const char *data, int len) |
|
123 | { |
144 | { |
|
124 | FILE *f; |
145 | FILE *f; |