1 /* $NetBSD: addr_size_cells.c,v 1.1.1.2 2017/06/08 15:59:26 skrll Exp $ */ 2 3 /* 4 * libfdt - Flat Device Tree manipulation 5 * Testcase for #address-cells and #size-cells handling 6 * Copyright (C) 2014 David Gibson, <david@gibson.dropbear.id.au> 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public License 10 * as published by the Free Software Foundation; either version 2.1 of 11 * the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, but 14 * WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this library; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 */ 22 #include <stdlib.h> 23 #include <stdio.h> 24 #include <string.h> 25 #include <stdint.h> 26 27 #include <libfdt.h> 28 29 #include "tests.h" 30 #include "testdata.h" 31 32 static void check_node(const void *fdt, const char *path, int ac, int sc) 33 { 34 int offset; 35 int xac, xsc; 36 37 offset = fdt_path_offset(fdt, path); 38 if (offset < 0) 39 FAIL("Couldn't find path %s", path); 40 41 xac = fdt_address_cells(fdt, offset); 42 xsc = fdt_size_cells(fdt, offset); 43 44 if (xac != ac) 45 FAIL("Address cells for %s is %d instead of %d\n", 46 path, xac, ac); 47 if (xsc != sc) 48 FAIL("Size cells for %s is %d instead of %d\n", 49 path, xsc, sc); 50 } 51 52 int main(int argc, char *argv[]) 53 { 54 void *fdt; 55 56 if (argc != 2) 57 CONFIG("Usage: %s <dtb file>\n", argv[0]); 58 59 test_init(argc, argv); 60 fdt = load_blob(argv[1]); 61 62 check_node(fdt, "/", 2, 2); 63 check_node(fdt, "/identity-bus@0", 2, 2); 64 check_node(fdt, "/simple-bus@1000000", 2, 1); 65 PASS(); 66 } 67