2019-06-20 23:19:41 +02:00
|
|
|
// SPDX-License-Identifier: LGPL-2.1-or-later
|
2006-12-01 06:59:43 +01:00
|
|
|
/*
|
|
|
|
* libfdt - Flat Device Tree manipulation
|
|
|
|
* Basic testcase for read-only access
|
|
|
|
* Copyright (C) 2006 David Gibson, IBM Corporation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <limits.h>
|
2007-03-23 05:16:54 +01:00
|
|
|
#include <stdint.h>
|
2006-12-01 06:59:43 +01:00
|
|
|
|
|
|
|
#include <libfdt.h>
|
|
|
|
|
|
|
|
#include "tests.h"
|
|
|
|
#include "testdata.h"
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2006-12-15 05:12:47 +01:00
|
|
|
void *fdt, *fdt1;
|
2006-12-01 06:59:43 +01:00
|
|
|
void *buf;
|
|
|
|
int oldsize, bufsize, packsize;
|
|
|
|
int err;
|
|
|
|
const char *inname;
|
|
|
|
char outname[PATH_MAX];
|
|
|
|
|
|
|
|
test_init(argc, argv);
|
|
|
|
fdt = load_blob_arg(argc, argv);
|
|
|
|
inname = argv[1];
|
|
|
|
|
|
|
|
oldsize = fdt_totalsize(fdt);
|
|
|
|
|
|
|
|
bufsize = oldsize * 2;
|
|
|
|
|
|
|
|
buf = xmalloc(bufsize);
|
2010-02-24 12:29:19 +01:00
|
|
|
/* don't leak uninitialized memory into our output */
|
|
|
|
memset(buf, 0, bufsize);
|
2006-12-01 06:59:43 +01:00
|
|
|
|
2006-12-15 05:12:47 +01:00
|
|
|
fdt1 = buf;
|
|
|
|
err = fdt_open_into(fdt, fdt1, bufsize);
|
|
|
|
if (err)
|
2006-12-01 06:59:43 +01:00
|
|
|
FAIL("fdt_open_into(): %s", fdt_strerror(err));
|
|
|
|
sprintf(outname, "opened.%s", inname);
|
|
|
|
save_blob(outname, fdt1);
|
|
|
|
|
2006-12-15 05:12:47 +01:00
|
|
|
err = fdt_pack(fdt1);
|
|
|
|
if (err)
|
2006-12-01 06:59:43 +01:00
|
|
|
FAIL("fdt_pack(): %s", fdt_strerror(err));
|
|
|
|
sprintf(outname, "repacked.%s", inname);
|
2006-12-15 05:12:47 +01:00
|
|
|
save_blob(outname, fdt1);
|
2006-12-01 06:59:43 +01:00
|
|
|
|
2006-12-15 05:12:47 +01:00
|
|
|
packsize = fdt_totalsize(fdt1);
|
2006-12-01 06:59:43 +01:00
|
|
|
|
|
|
|
verbose_printf("oldsize = %d, bufsize = %d, packsize = %d\n",
|
|
|
|
oldsize, bufsize, packsize);
|
|
|
|
PASS();
|
|
|
|
}
|