dtb_object.hh revision 9538
19538Satgutier@umich.edu/*
29538Satgutier@umich.edu * Copyright (c) 2013 The Regents of The University of Michigan
39538Satgutier@umich.edu * All rights reserved.
49538Satgutier@umich.edu *
59538Satgutier@umich.edu * Redistribution and use in source and binary forms, with or without
69538Satgutier@umich.edu * modification, are permitted provided that the following conditions are
79538Satgutier@umich.edu * met: redistributions of source code must retain the above copyright
89538Satgutier@umich.edu * notice, this list of conditions and the following disclaimer;
99538Satgutier@umich.edu * redistributions in binary form must reproduce the above copyright
109538Satgutier@umich.edu * notice, this list of conditions and the following disclaimer in the
119538Satgutier@umich.edu * documentation and/or other materials provided with the distribution;
129538Satgutier@umich.edu * neither the name of the copyright holders nor the names of its
139538Satgutier@umich.edu * contributors may be used to endorse or promote products derived from
149538Satgutier@umich.edu * this software without specific prior written permission.
159538Satgutier@umich.edu *
169538Satgutier@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
179538Satgutier@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
189538Satgutier@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
199538Satgutier@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
209538Satgutier@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
219538Satgutier@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
229538Satgutier@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
239538Satgutier@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
249538Satgutier@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
259538Satgutier@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
269538Satgutier@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
279538Satgutier@umich.edu *
289538Satgutier@umich.edu * Authors: Anthony Gutierrez
299538Satgutier@umich.edu */
309538Satgutier@umich.edu
319538Satgutier@umich.edu#ifndef __DTB_OBJECT_HH__
329538Satgutier@umich.edu#define __DTB_OBJECT_HH__
339538Satgutier@umich.edu
349538Satgutier@umich.edu#include "base/loader/object_file.hh"
359538Satgutier@umich.edu
369538Satgutier@umich.edu/** @file
379538Satgutier@umich.edu * This implements an object file format to support loading
389538Satgutier@umich.edu * and modifying flattened device tree blobs for use with
399538Satgutier@umich.edu * current and future ARM Linux kernels.
409538Satgutier@umich.edu */
419538Satgutier@umich.educlass DtbObject : public ObjectFile
429538Satgutier@umich.edu{
439538Satgutier@umich.edu    protected:
449538Satgutier@umich.edu        DtbObject(const std::string &_filename, int _fd,
459538Satgutier@umich.edu                  size_t _len, uint8_t *_data,
469538Satgutier@umich.edu                  Arch _arch, OpSys _opSys);
479538Satgutier@umich.edu
489538Satgutier@umich.edu        /** Bool marking if this dtb file has replaced the original
499538Satgutier@umich.edu         *  read in DTB file with a new modified buffer
509538Satgutier@umich.edu         */
519538Satgutier@umich.edu        bool fileDataMmapped;
529538Satgutier@umich.edu
539538Satgutier@umich.edu    public:
549538Satgutier@umich.edu        virtual ~DtbObject();
559538Satgutier@umich.edu
569538Satgutier@umich.edu        /** Adds the passed in Command Line options for the kernel
579538Satgutier@umich.edu          * to the proper location in the device tree.
589538Satgutier@umich.edu          * @param _args command line to append
599538Satgutier@umich.edu          * @param len length of the command line string
609538Satgutier@umich.edu          * @return returns true on success, false otherwise
619538Satgutier@umich.edu          */
629538Satgutier@umich.edu        bool addBootCmdLine(const char* _args, size_t len);
639538Satgutier@umich.edu        bool loadGlobalSymbols(SymbolTable *symtab,
649538Satgutier@umich.edu            Addr addrMask = std::numeric_limits<Addr>::max());
659538Satgutier@umich.edu        bool loadLocalSymbols(SymbolTable *symtab,
669538Satgutier@umich.edu            Addr addrMask = std::numeric_limits<Addr>::max());
679538Satgutier@umich.edu
689538Satgutier@umich.edu        /** Static function that tries to load file as a
699538Satgutier@umich.edu          * flattened device tree blob.
709538Satgutier@umich.edu          * @param fname path to file
719538Satgutier@umich.edu          * @param fd file descriptor of object file
729538Satgutier@umich.edu          * @param len length of file
739538Satgutier@umich.edu          * @param data mmap'ed data buffer containing file contents
749538Satgutier@umich.edu          * @return ObjectFile representing closest match of file type
759538Satgutier@umich.edu          */
769538Satgutier@umich.edu        static ObjectFile *tryFile(const std::string &fname, int fd,
779538Satgutier@umich.edu                                   size_t len, uint8_t *data);
789538Satgutier@umich.edu};
799538Satgutier@umich.edu
809538Satgutier@umich.edu#endif //__DTB_OBJECT_HH__
81