1/* $NetBSD: overlay_bad_fixup.c,v 1.1.1.2 2019/12/22 12:34:06 skrll Exp $ */ 2 3// SPDX-License-Identifier: LGPL-2.1-or-later 4/* 5 * libfdt - Flat Device Tree manipulation 6 * Testcase for DT overlays() 7 * Copyright (C) 2016 Free Electrons 8 * Copyright (C) 2016 NextThing Co. 9 */ 10 11#include <stdio.h> 12 13#include <libfdt.h> 14 15#include "tests.h" 16 17#define CHECK(code, expected) \ 18 { \ 19 err = (code); \ 20 if (err != expected) \ 21 FAIL(#code ": %s", fdt_strerror(err)); \ 22 } 23 24/* 4k ought to be enough for anybody */ 25#define FDT_COPY_SIZE (4 * 1024) 26 27static void *open_dt(char *path) 28{ 29 void *dt, *copy; 30 int err; 31 32 dt = load_blob(path); 33 copy = xmalloc(FDT_COPY_SIZE); 34 35 /* 36 * Resize our DTs to 4k so that we have room to operate on 37 */ 38 CHECK(fdt_open_into(dt, copy, FDT_COPY_SIZE), 0); 39 40 return copy; 41} 42 43int main(int argc, char *argv[]) 44{ 45 void *fdt_base, *fdt_overlay; 46 int err; 47 48 test_init(argc, argv); 49 if (argc != 3) 50 CONFIG("Usage: %s <base dtb> <overlay dtb>", argv[0]); 51 52 fdt_base = open_dt(argv[1]); 53 fdt_overlay = open_dt(argv[2]); 54 55 /* Apply the overlay */ 56 CHECK(fdt_overlay_apply(fdt_base, fdt_overlay), -FDT_ERR_BADOVERLAY); 57 58 PASS(); 59} 60