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:
4410880SCurtis.Dunham@arm.com        DtbObject(const std::string &_filename, size_t _len, uint8_t *_data,
459538Satgutier@umich.edu                  Arch _arch, OpSys _opSys);
469538Satgutier@umich.edu
479538Satgutier@umich.edu        /** Bool marking if this dtb file has replaced the original
489538Satgutier@umich.edu         *  read in DTB file with a new modified buffer
499538Satgutier@umich.edu         */
509538Satgutier@umich.edu        bool fileDataMmapped;
519538Satgutier@umich.edu
529538Satgutier@umich.edu    public:
539538Satgutier@umich.edu        virtual ~DtbObject();
549538Satgutier@umich.edu
559538Satgutier@umich.edu        /** Adds the passed in Command Line options for the kernel
569538Satgutier@umich.edu          * to the proper location in the device tree.
579538Satgutier@umich.edu          * @param _args command line to append
589538Satgutier@umich.edu          * @param len length of the command line string
599538Satgutier@umich.edu          * @return returns true on success, false otherwise
609538Satgutier@umich.edu          */
619538Satgutier@umich.edu        bool addBootCmdLine(const char* _args, size_t len);
6210508SAli.Saidi@ARM.com
6310508SAli.Saidi@ARM.com        /** Parse the DTB file enough to find the provided release
6410508SAli.Saidi@ARM.com         * address and return it.
6510508SAli.Saidi@ARM.com         * @return release address for SMP boot
6610508SAli.Saidi@ARM.com         */
6710508SAli.Saidi@ARM.com        Addr findReleaseAddr();
6810508SAli.Saidi@ARM.com
6911392Sbrandon.potter@amd.com        bool loadAllSymbols(SymbolTable *symtab, Addr base = 0,
7011392Sbrandon.potter@amd.com                            Addr offset = 0, Addr addrMask = maxAddr);
7111392Sbrandon.potter@amd.com        bool loadGlobalSymbols(SymbolTable *symtab, Addr base = 0,
7211392Sbrandon.potter@amd.com                               Addr offset = 0, Addr addrMask = maxAddr);
7311392Sbrandon.potter@amd.com        bool loadLocalSymbols(SymbolTable *symtab, Addr base = 0,
7411392Sbrandon.potter@amd.com                              Addr offset = 0, Addr addrMask = maxAddr);
759538Satgutier@umich.edu
769538Satgutier@umich.edu        /** Static function that tries to load file as a
779538Satgutier@umich.edu          * flattened device tree blob.
789538Satgutier@umich.edu          * @param fname path to file
799538Satgutier@umich.edu          * @param len length of file
809538Satgutier@umich.edu          * @param data mmap'ed data buffer containing file contents
819538Satgutier@umich.edu          * @return ObjectFile representing closest match of file type
829538Satgutier@umich.edu          */
8310880SCurtis.Dunham@arm.com        static ObjectFile *tryFile(const std::string &fname,
849538Satgutier@umich.edu                                   size_t len, uint8_t *data);
859538Satgutier@umich.edu};
869538Satgutier@umich.edu
879538Satgutier@umich.edu#endif //__DTB_OBJECT_HH__
88