Path: blob/master/scripts/dtc/libfdt/fdt_strerror.c
10818 views
/*1* libfdt - Flat Device Tree manipulation2* Copyright (C) 2006 David Gibson, IBM Corporation.3*4* libfdt is dual licensed: you can use it either under the terms of5* the GPL, or the BSD license, at your option.6*7* a) This library is free software; you can redistribute it and/or8* modify it under the terms of the GNU General Public License as9* published by the Free Software Foundation; either version 2 of the10* License, or (at your option) any later version.11*12* This library is distributed in the hope that it will be useful,13* but WITHOUT ANY WARRANTY; without even the implied warranty of14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15* GNU General Public License for more details.16*17* You should have received a copy of the GNU General Public18* License along with this library; if not, write to the Free19* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,20* MA 02110-1301 USA21*22* Alternatively,23*24* b) Redistribution and use in source and binary forms, with or25* without modification, are permitted provided that the following26* conditions are met:27*28* 1. Redistributions of source code must retain the above29* copyright notice, this list of conditions and the following30* disclaimer.31* 2. Redistributions in binary form must reproduce the above32* copyright notice, this list of conditions and the following33* disclaimer in the documentation and/or other materials34* provided with the distribution.35*36* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND37* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,38* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF39* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE40* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR41* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,42* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT43* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;44* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)45* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN46* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR47* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,48* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.49*/50#include "libfdt_env.h"5152#include <fdt.h>53#include <libfdt.h>5455#include "libfdt_internal.h"5657struct fdt_errtabent {58const char *str;59};6061#define FDT_ERRTABENT(val) \62[(val)] = { .str = #val, }6364static struct fdt_errtabent fdt_errtable[] = {65FDT_ERRTABENT(FDT_ERR_NOTFOUND),66FDT_ERRTABENT(FDT_ERR_EXISTS),67FDT_ERRTABENT(FDT_ERR_NOSPACE),6869FDT_ERRTABENT(FDT_ERR_BADOFFSET),70FDT_ERRTABENT(FDT_ERR_BADPATH),71FDT_ERRTABENT(FDT_ERR_BADSTATE),7273FDT_ERRTABENT(FDT_ERR_TRUNCATED),74FDT_ERRTABENT(FDT_ERR_BADMAGIC),75FDT_ERRTABENT(FDT_ERR_BADVERSION),76FDT_ERRTABENT(FDT_ERR_BADSTRUCTURE),77FDT_ERRTABENT(FDT_ERR_BADLAYOUT),78};79#define FDT_ERRTABSIZE (sizeof(fdt_errtable) / sizeof(fdt_errtable[0]))8081const char *fdt_strerror(int errval)82{83if (errval > 0)84return "<valid offset/length>";85else if (errval == 0)86return "<no error>";87else if (errval > -FDT_ERRTABSIZE) {88const char *s = fdt_errtable[-errval].str;8990if (s)91return s;92}9394return "<unknown error>";95}969798