@ -159,33 +159,13 @@ int nodename_eq(const char *s1, const char *s2)
void *load_blob(const char *filename)
void *load_blob(const char *filename)
{
{
int fd;
char *blob;
int offset = 0;
int ret = utilfdt_read_err(filename, &blob);
int bufsize = 1024;
char *p = NULL;
int ret;
fd = open(filename, O_RDONLY);
if (fd < 0)
CONFIG("Couldn't open blob from \"%s\": %s", filename,
strerror(errno));
p = xmalloc(bufsize);
do {
if (offset == bufsize) {
bufsize *= 2;
p = xrealloc(p, bufsize);
}
ret = read(fd, &p[offset], bufsize - offset);
if (ret < 0)
CONFIG("Couldn't read from \"%s\": %s", filename,
strerror(errno));
offset += ret;
} while (ret != 0);
return p;
if (ret)
CONFIG("Couldn't open blob from \"%s\": %s", filename,
strerror(ret));
return blob;
}
}
void *load_blob_arg(int argc, char *argv[])
void *load_blob_arg(int argc, char *argv[])
@ -197,28 +177,11 @@ void *load_blob_arg(int argc, char *argv[])
void save_blob(const char *filename, void *fdt)
void save_blob(const char *filename, void *fdt)
{
{
int fd;
int ret = utilfdt_write_err(filename, fdt);
int totalsize;
int offset;
if (ret)
char *p;
CONFIG("Couldn't write blob to \"%s\": %s", filename,
int ret;
strerror(ret));
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (fd < 0)
CONFIG("Couldn't open \"%s\" to write blob: %s", filename,
strerror(errno));
totalsize = fdt_totalsize(fdt);
offset = 0;
p = fdt;
while (offset < totalsize) {
ret = write(fd, p + offset, totalsize - offset);
if (ret < 0)
CONFIG("Couldn't write to \"%s\": %s", filename,
strerror(errno));
offset += ret;
}
}
}
void *open_blob_rw(void *blob)
void *open_blob_rw(void *blob)