1/* 2 * libfdt - Flat Device Tree manipulation 3 * Testcase for variable sized cells in dtc 4 * Copyright (C) 2006 David Gibson, IBM Corporation. 5 * Copyright (C) 2011 The Chromium Authors. All rights reserved. 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public License 9 * as published by the Free Software Foundation; either version 2.1 of 10 * the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, but 13 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 */ 21#include <stdlib.h> 22#include <stdio.h> 23#include <string.h> 24#include <stdint.h> 25 26#include <libfdt.h> 27 28#include "tests.h" 29#include "testdata.h" 30 31static void check_compare_properties(void *fdt, 32 char const *name_one, 33 char const *name_two) 34{ 35 const void *propval; 36 int proplen; 37 38 propval = fdt_getprop(fdt, 0, name_one, &proplen); 39 40 if (!propval) 41 FAIL("fdt_getprop(\"%s\"): %s", 42 name_one, 43 fdt_strerror(proplen)); 44 45 check_getprop(fdt, 0, name_two, proplen, propval); 46} 47 48int main(int argc, char *argv[]) 49{ 50 void *fdt; 51 uint8_t expected_8[6] = {TEST_CHAR1, 52 TEST_CHAR2, 53 TEST_CHAR3, 54 TEST_CHAR4, 55 TEST_CHAR5, 56 TEST_VALUE_1 >> 24}; 57 fdt16_t expected_16[6]; 58 fdt32_t expected_32[6]; 59 fdt64_t expected_64[6]; 60 int i; 61 62 for (i = 0; i < 5; ++i) { 63 expected_16[i] = cpu_to_fdt16(expected_8[i]); 64 expected_32[i] = cpu_to_fdt32(expected_8[i]); 65 expected_64[i] = cpu_to_fdt64(expected_8[i]); 66 } 67 68 expected_16[5] = cpu_to_fdt16(TEST_VALUE_1 >> 16); 69 expected_32[5] = cpu_to_fdt32(TEST_VALUE_1); 70 expected_64[5] = cpu_to_fdt64(TEST_ADDR_1); 71 72 test_init(argc, argv); 73 fdt = load_blob_arg(argc, argv); 74 75 check_getprop(fdt, 0, "cells-8b", sizeof(expected_8), expected_8); 76 check_getprop(fdt, 0, "cells-16b", sizeof(expected_16), expected_16); 77 check_getprop(fdt, 0, "cells-32b", sizeof(expected_32), expected_32); 78 check_getprop(fdt, 0, "cells-64b", sizeof(expected_64), expected_64); 79 80 check_compare_properties(fdt, "cells-one-16b", "cells-one-32b"); 81 82 PASS(); 83} 84