1*630b011fSAntonio Nino Diaz /* 2*630b011fSAntonio Nino Diaz * libfdt - Flat Device Tree manipulation 3*630b011fSAntonio Nino Diaz * Copyright (C) 2006 David Gibson, IBM Corporation. 4*630b011fSAntonio Nino Diaz * 5*630b011fSAntonio Nino Diaz * libfdt is dual licensed: you can use it either under the terms of 6*630b011fSAntonio Nino Diaz * the GPL, or the BSD license, at your option. 7*630b011fSAntonio Nino Diaz * 8*630b011fSAntonio Nino Diaz * a) This library is free software; you can redistribute it and/or 9*630b011fSAntonio Nino Diaz * modify it under the terms of the GNU General Public License as 10*630b011fSAntonio Nino Diaz * published by the Free Software Foundation; either version 2 of the 11*630b011fSAntonio Nino Diaz * License, or (at your option) any later version. 12*630b011fSAntonio Nino Diaz * 13*630b011fSAntonio Nino Diaz * This library is distributed in the hope that it will be useful, 14*630b011fSAntonio Nino Diaz * but WITHOUT ANY WARRANTY; without even the implied warranty of 15*630b011fSAntonio Nino Diaz * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*630b011fSAntonio Nino Diaz * GNU General Public License for more details. 17*630b011fSAntonio Nino Diaz * 18*630b011fSAntonio Nino Diaz * You should have received a copy of the GNU General Public 19*630b011fSAntonio Nino Diaz * License along with this library; if not, write to the Free 20*630b011fSAntonio Nino Diaz * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 21*630b011fSAntonio Nino Diaz * MA 02110-1301 USA 22*630b011fSAntonio Nino Diaz * 23*630b011fSAntonio Nino Diaz * Alternatively, 24*630b011fSAntonio Nino Diaz * 25*630b011fSAntonio Nino Diaz * b) Redistribution and use in source and binary forms, with or 26*630b011fSAntonio Nino Diaz * without modification, are permitted provided that the following 27*630b011fSAntonio Nino Diaz * conditions are met: 28*630b011fSAntonio Nino Diaz * 29*630b011fSAntonio Nino Diaz * 1. Redistributions of source code must retain the above 30*630b011fSAntonio Nino Diaz * copyright notice, this list of conditions and the following 31*630b011fSAntonio Nino Diaz * disclaimer. 32*630b011fSAntonio Nino Diaz * 2. Redistributions in binary form must reproduce the above 33*630b011fSAntonio Nino Diaz * copyright notice, this list of conditions and the following 34*630b011fSAntonio Nino Diaz * disclaimer in the documentation and/or other materials 35*630b011fSAntonio Nino Diaz * provided with the distribution. 36*630b011fSAntonio Nino Diaz * 37*630b011fSAntonio Nino Diaz * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 38*630b011fSAntonio Nino Diaz * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 39*630b011fSAntonio Nino Diaz * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 40*630b011fSAntonio Nino Diaz * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 41*630b011fSAntonio Nino Diaz * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 42*630b011fSAntonio Nino Diaz * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 43*630b011fSAntonio Nino Diaz * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 44*630b011fSAntonio Nino Diaz * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 45*630b011fSAntonio Nino Diaz * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 46*630b011fSAntonio Nino Diaz * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 47*630b011fSAntonio Nino Diaz * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 48*630b011fSAntonio Nino Diaz * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 49*630b011fSAntonio Nino Diaz * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 50*630b011fSAntonio Nino Diaz */ 51*630b011fSAntonio Nino Diaz #include "libfdt_env.h" 52*630b011fSAntonio Nino Diaz 53*630b011fSAntonio Nino Diaz #include <fdt.h> 54*630b011fSAntonio Nino Diaz #include <libfdt.h> 55*630b011fSAntonio Nino Diaz 56*630b011fSAntonio Nino Diaz #include "libfdt_internal.h" 57*630b011fSAntonio Nino Diaz 58*630b011fSAntonio Nino Diaz struct fdt_errtabent { 59*630b011fSAntonio Nino Diaz const char *str; 60*630b011fSAntonio Nino Diaz }; 61*630b011fSAntonio Nino Diaz 62*630b011fSAntonio Nino Diaz #define FDT_ERRTABENT(val) \ 63*630b011fSAntonio Nino Diaz [(val)] = { .str = #val, } 64*630b011fSAntonio Nino Diaz 65*630b011fSAntonio Nino Diaz static struct fdt_errtabent fdt_errtable[] = { 66*630b011fSAntonio Nino Diaz FDT_ERRTABENT(FDT_ERR_NOTFOUND), 67*630b011fSAntonio Nino Diaz FDT_ERRTABENT(FDT_ERR_EXISTS), 68*630b011fSAntonio Nino Diaz FDT_ERRTABENT(FDT_ERR_NOSPACE), 69*630b011fSAntonio Nino Diaz 70*630b011fSAntonio Nino Diaz FDT_ERRTABENT(FDT_ERR_BADOFFSET), 71*630b011fSAntonio Nino Diaz FDT_ERRTABENT(FDT_ERR_BADPATH), 72*630b011fSAntonio Nino Diaz FDT_ERRTABENT(FDT_ERR_BADPHANDLE), 73*630b011fSAntonio Nino Diaz FDT_ERRTABENT(FDT_ERR_BADSTATE), 74*630b011fSAntonio Nino Diaz 75*630b011fSAntonio Nino Diaz FDT_ERRTABENT(FDT_ERR_TRUNCATED), 76*630b011fSAntonio Nino Diaz FDT_ERRTABENT(FDT_ERR_BADMAGIC), 77*630b011fSAntonio Nino Diaz FDT_ERRTABENT(FDT_ERR_BADVERSION), 78*630b011fSAntonio Nino Diaz FDT_ERRTABENT(FDT_ERR_BADSTRUCTURE), 79*630b011fSAntonio Nino Diaz FDT_ERRTABENT(FDT_ERR_BADLAYOUT), 80*630b011fSAntonio Nino Diaz FDT_ERRTABENT(FDT_ERR_INTERNAL), 81*630b011fSAntonio Nino Diaz FDT_ERRTABENT(FDT_ERR_BADNCELLS), 82*630b011fSAntonio Nino Diaz FDT_ERRTABENT(FDT_ERR_BADVALUE), 83*630b011fSAntonio Nino Diaz FDT_ERRTABENT(FDT_ERR_BADOVERLAY), 84*630b011fSAntonio Nino Diaz FDT_ERRTABENT(FDT_ERR_NOPHANDLES), 85*630b011fSAntonio Nino Diaz }; 86*630b011fSAntonio Nino Diaz #define FDT_ERRTABSIZE (sizeof(fdt_errtable) / sizeof(fdt_errtable[0])) 87*630b011fSAntonio Nino Diaz 88*630b011fSAntonio Nino Diaz const char *fdt_strerror(int errval) 89*630b011fSAntonio Nino Diaz { 90*630b011fSAntonio Nino Diaz if (errval > 0) 91*630b011fSAntonio Nino Diaz return "<valid offset/length>"; 92*630b011fSAntonio Nino Diaz else if (errval == 0) 93*630b011fSAntonio Nino Diaz return "<no error>"; 94*630b011fSAntonio Nino Diaz else if (errval > -FDT_ERRTABSIZE) { 95*630b011fSAntonio Nino Diaz const char *s = fdt_errtable[-errval].str; 96*630b011fSAntonio Nino Diaz 97*630b011fSAntonio Nino Diaz if (s) 98*630b011fSAntonio Nino Diaz return s; 99*630b011fSAntonio Nino Diaz } 100*630b011fSAntonio Nino Diaz 101*630b011fSAntonio Nino Diaz return "<unknown error>"; 102*630b011fSAntonio Nino Diaz } 103