Skip to content

Commit 7e5122f

Browse files
committed
initial import
Signed-off-by: Sascha Hauer <[email protected]>
0 parents  commit 7e5122f

File tree

16 files changed

+2355
-0
lines changed

16 files changed

+2355
-0
lines changed

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
CFLAGS=-Wall
3+
LDFLAGS=-lconfuse
4+
all: genimage
5+
DEPS = genimage.h list.h
6+
7+
%.o: %.c $(DEPS)
8+
$(CC) -c -o $@ $< $(CFLAGS)
9+
10+
genimage: genimage.o image-jffs2.o image-ext2.o image-ubi.o image-ubifs.o \
11+
image-flash.o image-file.o image-tar.o image-hd.o util.o config.o
12+
13+
clean:
14+
rm -f *.o genimage

config.c

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
#define _GNU_SOURCE
2+
#include <confuse.h>
3+
#include <stdio.h>
4+
#include <string.h>
5+
#include <stdlib.h>
6+
#include <errno.h>
7+
8+
#include "genimage.h"
9+
10+
static LIST_HEAD(optlist);
11+
12+
struct config {
13+
const char *name;
14+
cfg_opt_t opt;
15+
const char *env;
16+
char cmdlineopt;
17+
struct list_head list;
18+
char *value;
19+
char *def;
20+
};
21+
22+
const char *get_opt(const char *name)
23+
{
24+
struct config *c;
25+
26+
list_for_each_entry(c, &optlist, list) {
27+
if (!strcmp(c->name, name))
28+
return c->value;
29+
}
30+
31+
return NULL;
32+
}
33+
34+
int add_opt(const char *name, char cmdline, const char *env, cfg_opt_t *opt, char *def)
35+
{
36+
struct config *c = xzalloc(sizeof(*c));
37+
38+
c->name = strdup(name);
39+
c->cmdlineopt = cmdline;
40+
c->env = env;
41+
c->def = def;
42+
memcpy(&c->opt, opt, sizeof(cfg_opt_t));
43+
44+
list_add_tail(&c->list, &optlist);
45+
46+
return 0;
47+
}
48+
49+
cfg_opt_t *get_config_opts(void)
50+
{
51+
struct config *c;
52+
int num_opts = 0;;
53+
cfg_opt_t *opts;
54+
int i = 0;
55+
cfg_opt_t cfg_end[] = {
56+
CFG_END()
57+
};
58+
59+
list_for_each_entry(c, &optlist, list)
60+
num_opts++;
61+
62+
opts = xzalloc(sizeof(cfg_opt_t) * (num_opts + 1));
63+
64+
list_for_each_entry(c, &optlist, list) {
65+
memcpy(&opts[i], &c->opt, sizeof(cfg_opt_t));
66+
i++;
67+
}
68+
69+
memcpy(&opts[i], cfg_end, sizeof(cfg_opt_t));
70+
71+
return opts;
72+
}
73+
74+
int set_config_opts(int argc, char *argv[], cfg_t *cfg)
75+
{
76+
struct config *c;
77+
cfg_t *cfgsec;
78+
79+
list_for_each_entry(c, &optlist, list) {
80+
char *str = c->def;
81+
if (str)
82+
c->value = strdup(str);
83+
}
84+
85+
list_for_each_entry(c, &optlist, list) {
86+
char *str = getenv(c->env);
87+
if (str) {
88+
if (c->value)
89+
free(c->value);
90+
c->value = strdup(str);
91+
}
92+
}
93+
94+
cfgsec = cfg_getsec(cfg, "config");
95+
if (cfgsec) {
96+
list_for_each_entry(c, &optlist, list) {
97+
char *str = cfg_getstr(cfgsec, c->opt.name);
98+
if (str) {
99+
if (c->value)
100+
free(c->value);
101+
c->value = strdup(str);
102+
}
103+
}
104+
}
105+
106+
return 0;
107+
}
108+
109+
const char *imagepath(void)
110+
{
111+
return get_opt("outputpath");
112+
}
113+
114+
const char *inputpath(void)
115+
{
116+
return get_opt("inputpath");
117+
}
118+
119+
const char *rootpath(void)
120+
{
121+
return get_opt("rootpath");
122+
}
123+
124+
const char *tmppath(void)
125+
{
126+
return get_opt("tmppath");
127+
}
128+
129+
static struct config opts[] = {
130+
{
131+
.name = "rootpath",
132+
.opt = CFG_STR("rootpath", NULL, CFGF_NONE),
133+
.cmdlineopt = 'r',
134+
.env = "PTXMKIMAGE_ROOTPATH",
135+
}, {
136+
.name = "tmppath",
137+
.opt = CFG_STR("tmppath", NULL, CFGF_NONE),
138+
.cmdlineopt = 't',
139+
.env = "PTXMKIMAGE_TMPPATH",
140+
}, {
141+
.name = "inputpath",
142+
.opt = CFG_STR("inputpath", NULL, CFGF_NONE),
143+
.cmdlineopt = 'i',
144+
.env = "PTXMKIMAGE_INPUTPATH",
145+
}, {
146+
.name = "outputpath",
147+
.opt = CFG_STR("outputpath", NULL, CFGF_NONE),
148+
.cmdlineopt = 'o',
149+
.env = "PTXMKIMAGE_OUTPUTPATH",
150+
}, {
151+
.name = "mkfsubifs",
152+
.opt = CFG_STR("mkfsubifs", NULL, CFGF_NONE),
153+
.cmdlineopt = 'o',
154+
.env = "PTXMKIMAGE_MKFSUBIFS",
155+
.def = "mkfs.ubifs",
156+
}, {
157+
.name = "mkfsjffs2",
158+
.opt = CFG_STR("mkfsjffs2", NULL, CFGF_NONE),
159+
.cmdlineopt = 'o',
160+
.env = "PTXMKIMAGE_MKFJFFS2",
161+
.def = "mkfs.jffs2",
162+
}, {
163+
.name = "ubinize",
164+
.opt = CFG_STR("ubinize", NULL, CFGF_NONE),
165+
.cmdlineopt = 'o',
166+
.env = "PTXMKIMAGE_UBINIZE",
167+
.def = "ubinize",
168+
}, {
169+
.name = "genext2fs",
170+
.opt = CFG_STR("genext2fs", NULL, CFGF_NONE),
171+
.cmdlineopt = 'o',
172+
.env = "PTXMKIMAGE_GENEXT2FS",
173+
.def = "genext2fs",
174+
}, {
175+
.name = "tar",
176+
.opt = CFG_STR("tar", NULL, CFGF_NONE),
177+
.cmdlineopt = 'o',
178+
.env = "PTXMKIMAGE_TAR",
179+
.def = "tar",
180+
},
181+
};
182+
183+
int init_config(void)
184+
{
185+
int i, ret;
186+
187+
for (i = 0; i < ARRAY_SIZE(opts); i++) {
188+
ret = add_opt(opts[i].name, opts[i].cmdlineopt, opts[i].env, &opts[i].opt, opts[i].def);
189+
if (ret)
190+
return ret;
191+
}
192+
193+
return 0;
194+
}

flash.conf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
flash nand-64M-512 {
2+
pebsize = 16384
3+
lebsize = 15360
4+
numpebs = 4096
5+
minimum-io-unit-size = 512
6+
vid-header-offset = 512
7+
sub-page-size = 512
8+
}
9+
10+
flash nor-64M-128k {
11+
pebsize = 131072
12+
lebsize = 130944
13+
numpebs = 256
14+
minimum-io-unit-size = 1
15+
vid-header-offset = 64
16+
sub-page-size = 1
17+
}
18+

0 commit comments

Comments
 (0)