/* set LD_LIBRARY_PATH env var and load kmods from overlay if we found a lib directory there */
if (!stat(ldlib_path, &s) && S_ISDIR(s.st_mode)) {
+ ULOG_INFO("loading kmods from internal overlay\n");
setenv("LD_LIBRARY_PATH", ldlib_path, 1);
snprintf(kmod_loader, sizeof(kmod_loader),
"/sbin/kmodloader %s/etc/modules-boot.d/", dirname(ldlib_path));
mkdir("/tmp/extroot/mnt/rom", 0755);
if (mount_move("/tmp/extroot", "", "/mnt")) {
- fprintf(stderr, "moving pivotroot failed - continue normal boot\n");
+ ULOG_ERR("moving pivotroot failed - continue normal boot\n");
umount("/tmp/extroot/mnt");
} else if (pivot("/mnt", "/rom")) {
- fprintf(stderr, "switching to pivotroot failed - continue normal boot\n");
+ ULOG_ERR("switching to pivotroot failed - continue normal boot\n");
umount("/mnt");
} else {
umount("/tmp/overlay");
}
} else if (find_mount("/tmp/extroot/overlay")) {
if (mount_move("/tmp/extroot", "", "/overlay")) {
- fprintf(stderr, "moving extroot failed - continue normal boot\n");
+ ULOG_ERR("moving extroot failed - continue normal boot\n");
umount("/tmp/extroot/overlay");
} else if (fopivot("/overlay", "/rom")) {
- fprintf(stderr, "switching to extroot failed - continue normal boot\n");
+ ULOG_ERR("switching to extroot failed - continue normal boot\n");
umount("/overlay");
} else {
umount("/tmp/overlay");
strncmp(t, "jffs2", 5) &&
strncmp(t, "ubifs", 5)) {
fclose(fp);
- fprintf(stderr, "block is mounted with wrong fs\n");
+ ULOG_ERR("block is mounted with wrong fs\n");
return NULL;
}
point = p;
int ret = -1;
if (!fp) {
- fprintf(stderr, "opening /proc/filesystems failed: %s\n", strerror(errno));
+ ULOG_ERR("opening /proc/filesystems failed: %s\n", strerror(errno));
goto out;
}
#include <libubox/list.h>
#include <libubox/blob.h>
+#include <libubox/ulog.h>
struct volume;
ret = mount(olddir, newdir, NULL, MS_NOATIME | MS_MOVE, NULL);
/* if (ret)
- fprintf(stderr, "failed %s %s: %s\n", olddir, newdir, strerror(errno));*/
+ ULOG_ERR("failed %s %s: %s\n", olddir, newdir, strerror(errno));*/
return ret;
}
ret = pivot_root(new, pivotdir);
if (ret < 0) {
- fprintf(stderr, "pivot_root failed %s %s: %s\n", new, pivotdir, strerror(errno));
+ ULOG_ERR("pivot_root failed %s %s: %s\n", new, pivotdir, strerror(errno));
return -1;
}
char overlay[64], lowerdir[64];
if (find_filesystem("overlay")) {
- fprintf(stderr, "BUG: no suitable fs found\n");
+ ULOG_ERR("BUG: no suitable fs found\n");
return -1;
}
/* Mainlined overlayfs has been renamed to "overlay", try that first */
if (mount(overlay, "/mnt", "overlay", MS_NOATIME, lowerdir)) {
if (mount(overlay, "/mnt", "overlayfs", MS_NOATIME, lowerdir)) {
- fprintf(stderr, "mount failed: %s, options %s\n",
- strerror(errno), lowerdir);
+ ULOG_ERR("mount failed: %s, options %s\n",
+ strerror(errno), lowerdir);
return -1;
}
}
p->fd = mtd_open(p->chr, 0);
if (p->fd < 0) {
p->fd = 0;
- fprintf(stderr, "Could not open mtd device: %s\n", p->chr);
+ ULOG_ERR("Could not open mtd device: %s\n", p->chr);
return -1;
}
if (ioctl(p->fd, MEMGETINFO, &mtdInfo)) {
mtd_volume_close(v);
- fprintf(stderr, "Could not get MTD device info from %s\n", p->chr);
+ ULOG_ERR("Could not get MTD device info from %s\n", p->chr);
return -1;
}
p->chr = strdup(buffer);
if (mtd_volume_load(v)) {
- fprintf(stderr, "reading %s failed\n", v->name);
+ ULOG_ERR("reading %s failed\n", v->name);
return -1;
}
size_t sz;
if (mtd_volume_load(v)) {
- fprintf(stderr, "reading %s failed\n", v->name);
+ ULOG_ERR("reading %s failed\n", v->name);
return -1;
}
sz = read(p->fd, &deadc0de, sizeof(deadc0de));
if (sz != sizeof(deadc0de)) {
- fprintf(stderr, "reading %s failed: %s\n", v->name, strerror(errno));
+ ULOG_ERR("reading %s failed: %s\n", v->name, strerror(errno));
return -1;
}
deadc0de = __be32_to_cpu(deadc0de);
if (deadc0de == 0xdeadc0de) {
- fprintf(stderr, "jffs2 is not ready - marker found\n");
+ ULOG_INFO("jffs2 is not ready - marker found\n");
return FS_DEADCODE;
}
jffs2 = __be16_to_cpu(deadc0de >> 16);
if (jffs2 == 0x1985) {
- fprintf(stderr, "jffs2 is ready\n");
+ ULOG_INFO("jffs2 is ready\n");
return FS_JFFS2;
}
if (v->type == UBIVOLUME && deadc0de == 0xffffffff) {
- fprintf(stderr, "jffs2 is ready\n");
+ ULOG_INFO("jffs2 is ready\n");
return FS_JFFS2;
}
- fprintf(stderr, "No jffs2 marker was found\n");
+ ULOG_INFO("No jffs2 marker was found\n");
return FS_NONE;
}
return -1;
if (offset % v->block_size || len % v->block_size) {
- fprintf(stderr, "mtd erase needs to be block aligned\n");
+ ULOG_ERR("mtd erase needs to be block aligned\n");
return -1;
}
for (eiu.start = first_block * v->block_size;
eiu.start < v->size && eiu.start < (first_block + num_blocks) * v->block_size;
eiu.start += v->block_size) {
- fprintf(stderr, "erasing %x %x\n", eiu.start, v->block_size);
+ ULOG_INFO("erasing %x %x\n", eiu.start, v->block_size);
ioctl(p->fd, MEMUNLOCK, &eiu);
if (ioctl(p->fd, MEMERASE, &eiu))
- fprintf(stderr, "Failed to erase block at 0x%x\n", eiu.start);
+ ULOG_ERR("Failed to erase block at 0x%x\n", eiu.start);
}
mtd_volume_close(v);
ret = ioctl(p->fd, MEMGETINFO, &mtdinfo);
if (ret) {
- fprintf(stderr, "ioctl(%d, MEMGETINFO) failed: %s\n", p->fd, strerror(errno));
+ ULOG_ERR("ioctl(%d, MEMGETINFO) failed: %s\n", p->fd, strerror(errno));
} else {
struct erase_info_user mtdlock;
return -1;
if (lseek(p->fd, offset, SEEK_SET) == (off_t) -1) {
- fprintf(stderr, "lseek/read failed\n");
+ ULOG_ERR("lseek/read failed\n");
return -1;
}
if (read(p->fd, buf, length) == -1) {
- fprintf(stderr, "read failed\n");
+ ULOG_ERR("read failed\n");
return -1;
}
return -1;
if (lseek(p->fd, offset, SEEK_SET) == (off_t) -1) {
- fprintf(stderr, "lseek/write failed at offset %d\n", offset);
+ ULOG_ERR("lseek/write failed at offset %d\n", offset);
perror("lseek");
return -1;
}
if (write(p->fd, buf, length) == -1) {
- fprintf(stderr, "write failed\n");
+ ULOG_ERR("write failed\n");
return -1;
}
if (dir[strlen(dir) - 1] == '/')
snprintf(globdir, 256, "%s*", dir);
else
- snprintf(globdir, 256, "%s/*", dir);
+ snprintf(globdir, 256, "%s/*", dir); /**/
if (!glob(globdir, GLOB_NOESCAPE | GLOB_MARK | GLOB_ONLYDIR, NULL, &gl))
for (j = 0; j < gl.gl_pathc; j++)
overlay_mount(struct volume *v, char *fs)
{
if (mkdir("/tmp/overlay", 0755)) {
- fprintf(stderr, "failed to mkdir /tmp/overlay: %s\n", strerror(errno));
+ ULOG_ERR("failed to mkdir /tmp/overlay: %s\n", strerror(errno));
return -1;
}
if (mount(v->blk, "/tmp/overlay", fs, MS_NOATIME, NULL)) {
- fprintf(stderr, "failed to mount -t %s %s /tmp/overlay: %s\n", fs, v->blk, strerror(errno));
+ ULOG_ERR("failed to mount -t %s %s /tmp/overlay: %s\n", fs, v->blk, strerror(errno));
return -1;
}
int ret;
if (!stat(SWITCH_JFFS2, &s)) {
- fprintf(stderr, "jffs2 switch already running\n");
+ ULOG_ERR("jffs2 switch already running\n");
return -1;
}
ret = mount(v->blk, "/rom/overlay", "jffs2", MS_NOATIME, NULL);
unlink("/tmp/.switch_jffs2");
if (ret) {
- fprintf(stderr, "failed - mount -t jffs2 %s /rom/overlay: %s\n", v->blk, strerror(errno));
+ ULOG_ERR("failed - mount -t jffs2 %s /rom/overlay: %s\n", v->blk, strerror(errno));
return -1;
}
if (mount("none", "/", NULL, MS_NOATIME | MS_REMOUNT, 0)) {
- fprintf(stderr, "failed - mount -o remount,ro none: %s\n", strerror(errno));
+ ULOG_ERR("failed - mount -o remount,ro none: %s\n", strerror(errno));
return -1;
}
- system("cp -a /tmp/root/* /rom/overlay");
+ system("cp -a /tmp/root/* /rom/overlay"); /**/
if (pivot("/rom", "/mnt")) {
- fprintf(stderr, "failed - pivot /rom /mnt: %s\n", strerror(errno));
+ ULOG_ERR("failed - pivot /rom /mnt: %s\n", strerror(errno));
return -1;
}
if (mount_move("/mnt", "/tmp/root", "")) {
- fprintf(stderr, "failed - mount -o move /mnt /tmp/root %s\n", strerror(errno));
+ ULOG_ERR("failed - mount -o move /mnt /tmp/root %s\n", strerror(errno));
return -1;
}
return -1;
if (find_filesystem("overlay")) {
- fprintf(stderr, "overlayfs not found\n");
+ ULOG_ERR("overlayfs not supported by kernel\n");
return ret;
}
mp = find_mount_point(v->blk, 0);
if (mp) {
- fprintf(stderr, "rootfs_data:%s is already mounted as %s\n", v->blk, mp);
+ ULOG_ERR("rootfs_data:%s is already mounted as %s\n", v->blk, mp);
return -1;
}
switch (volume_identify(v)) {
case FS_NONE:
- fprintf(stderr, "no jffs2 marker found\n");
+ ULOG_ERR("no jffs2 marker found\n");
/* fall through */
case FS_DEADCODE:
ret = switch2jffs(v);
if (!ret) {
- fprintf(stderr, "doing fo cleanup\n");
+ ULOG_INFO("performing overlay whiteout\n");
umount2("/tmp/root", MNT_DETACH);
foreachdir("/overlay/", handle_whiteout);
}
if (ret)
break;
if (mount_move("/tmp", "", "/overlay") || fopivot("/overlay", "/rom")) {
- fprintf(stderr, "switching to jffs2 failed\n");
+ ULOG_ERR("switching to jffs2 failed\n");
ret = -1;
}
break;
if (ret)
break;
if (mount_move("/tmp", "", "/overlay") || fopivot("/overlay", "/rom")) {
- fprintf(stderr, "switching to ubifs failed\n");
+ ULOG_ERR("switching to ubifs failed\n");
ret = -1;
}
break;
char *fstype;
if (mkdir("/tmp/overlay", 0755)) {
- fprintf(stderr, "failed to mkdir /tmp/overlay: %s\n", strerror(errno));
+ ULOG_ERR("failed to mkdir /tmp/overlay: %s\n", strerror(errno));
return -1;
}
}
if (mount(v->blk, "/tmp/overlay", fstype, MS_NOATIME, NULL)) {
- fprintf(stderr, "failed to mount -t %s %s /tmp/overlay: %s\n",
- fstype, v->blk, strerror(errno));
+ ULOG_ERR("failed to mount -t %s %s /tmp/overlay: %s\n",
+ fstype, v->blk, strerror(errno));
return -1;
}
mp = find_mount_point(v->blk, 0);
if (mp) {
- fprintf(stderr, "rootfs_data:%s is already mounted as %s\n", v->blk, mp);
+ ULOG_ERR("rootfs_data:%s is already mounted as %s\n", v->blk, mp);
return -1;
}
extroot_prefix = "/tmp/overlay";
if (!mount_extroot()) {
- fprintf(stderr, "switched to extroot\n");
+ ULOG_INFO("switched to extroot\n");
return 0;
}
- fprintf(stderr, "switching to overlay\n");
+ ULOG_INFO("switching to overlay\n");
if (mount_move("/tmp", "", "/overlay") || fopivot("/overlay", "/rom")) {
- fprintf(stderr, "switching to jffs2 failed - fallback to ramoverlay\n");
+ ULOG_ERR("switching to jffs2 failed - fallback to ramoverlay\n");
return ramoverlay();
}
uint32_t md5[4];
if (md5sum(file, md5)) {
- fprintf(stderr, "failed to generate md5 sum\n");
+ ULOG_ERR("failed to generate md5 sum\n");
return -1;
}
if (memcmp(md5, hash, sizeof(md5))) {
- fprintf(stderr, "failed to verify hash of %s.\n", file);
+ ULOG_ERR("failed to verify hash of %s.\n", file);
return -1;
}
do {
if (volume_read(v, &hdr, block * v->block_size, sizeof(struct file_header))) {
- fprintf(stderr, "scanning for next free block failed\n");
+ ULOG_ERR("scanning for next free block failed\n");
return 0;
}
for (i = (v->size / v->block_size) - 1; i > 0; i--) {
if (volume_read(v, sentinel, i * v->block_size, sizeof(*sentinel))) {
- fprintf(stderr, "failed to read header\n");
+ ULOG_ERR("failed to read header\n");
return -1;
}
be32_to_hdr(sentinel);
int ret = -1;
if (stat(file, &s) || md5sum(file, md5)) {
- fprintf(stderr, "stat failed on %s\n", file);
+ ULOG_ERR("stat failed on %s\n", file);
goto out;
}
if ((block * v->block_size) + pad_file_size(v, s.st_size) > v->size) {
- fprintf(stderr, "upgrade is too big for the flash\n");
+ ULOG_ERR("upgrade is too big for the flash\n");
goto out;
}
volume_erase(v, block * v->block_size, pad_file_size(v, s.st_size));
hdr_to_be32(&hdr);
if (volume_write(v, &hdr, block * v->block_size, sizeof(struct file_header))) {
- fprintf(stderr, "failed to write header\n");
+ ULOG_ERR("failed to write header\n");
goto out;
}
in = open(file, O_RDONLY);
if (in < 1) {
- fprintf(stderr, "failed to open %s\n", file);
+ ULOG_ERR("failed to open %s\n", file);
goto out;
}
int out, offset = 0;
if (volume_read(v, &hdr, block * v->block_size, sizeof(struct file_header))) {
- fprintf(stderr, "failed to read header\n");
+ ULOG_ERR("failed to read header\n");
return -1;
}
be32_to_hdr(&hdr);
out = open(file, O_WRONLY | O_CREAT, 0700);
if (!out) {
- fprintf(stderr, "failed to open %s\n", file);
+ ULOG_ERR("failed to open %s\n", file);
return -1;
}
close(out);
if (verify_file_hash(file, hdr.md5)) {
- fprintf(stderr, "md5 verification failed\n");
+ ULOG_ERR("md5 verification failed\n");
unlink(file);
return 0;
}
uint32_t seq;
if (stat("/tmp/config.tar.gz", &s)) {
- fprintf(stderr, "failed to stat /tmp/config.tar.gz\n");
+ ULOG_ERR("failed to stat /tmp/config.tar.gz\n");
return -1;
}
ret = snapshot_write_file(v, block, "/tmp/config.tar.gz", seq, CONF);
if (ret)
- fprintf(stderr, "failed to write sentinel\n");
+ ULOG_ERR("failed to write sentinel\n");
else
- fprintf(stderr, "wrote /tmp/config.tar.gz sentinel\n");
+ ULOG_INFO("wrote /tmp/config.tar.gz sentinel\n");
return ret;
}
ret = snapshot_write_file(v, block, "/tmp/config.tar.gz", seq, CONF);
if (ret)
- fprintf(stderr, "failed to write /tmp/config.tar.gz\n");
+ ULOG_ERR("failed to write /tmp/config.tar.gz\n");
else
- fprintf(stderr, "wrote /tmp/config.tar.gz\n");
+ ULOG_INFO("wrote /tmp/config.tar.gz\n");
return ret;
}
}
if (!is_config(&conf) && !is_config(&sentinel)) {
- // fprintf(stderr, "no config found\n");
+ // ULOG_ERR("no config found\n");
} else if (((is_config(&conf) && is_config(&sentinel)) &&
(memcmp(conf.md5, sentinel.md5, sizeof(conf.md5)) || (conf.seq != sentinel.seq))) ||
(is_config(&conf) && !is_config(&sentinel))) {
int ret = snapshot_read_file(v, next, "/tmp/config.tar.gz", CONF);
if (ret > 0) {
if (sentinel_write(v, conf.seq))
- fprintf(stderr, "failed to write sentinel data");
+ ULOG_ERR("failed to write sentinel data");
}
} else if (!is_config(&conf) && is_config(&sentinel) && next) {
int ret = snapshot_read_file(v, block, "/tmp/config.tar.gz", CONF);
if (ret > 0)
if (volatile_write(v, sentinel.seq))
- fprintf(stderr, "failed to write sentinel data");
+ ULOG_ERR("failed to write sentinel data");
} else
- fprintf(stderr, "config in sync\n");
+ ULOG_INFO("config in sync\n");
unlink("/tmp/config.tar.gz");
volname = read_string_from_file(voldir, "name");
if (!volname) {
- fprintf(stderr, "Couldn't read %s/name\n", voldir);
+ ULOG_ERR("Couldn't read %s/name\n", voldir);
return -1;
}