2 * Copyright (c) 2010 ARM Limited
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 #ifndef __ARCH_ARM_LINUX_ATAG_HH__
41 #define __ARCH_ARM_LINUX_ATAG_HH__
46 #include "base/types.hh"
52 SerialTag = 0x54410006,
64 /** Tag (normally starts with 'T''A' and 16 bits of number */
65 virtual uint32_t tag() = 0;
66 /** If the header should be 0 size */
67 virtual bool null() { return false; }
69 uint32_t size() const { return _size; }
71 AtagHeader(uint32_t s)
74 storage = new uint32_t[size()];
82 uint32_t copyOut(uint8_t *p)
84 storage[0] = null() ? 0 : size();
86 memcpy(p, storage, size() << 2);
91 class AtagCore : public AtagHeader
94 static const uint32_t Size = 5;
95 uint32_t tag() { return CoreTag; }
97 void flags(uint32_t i) { storage[2] = i; }
98 void pagesize(uint32_t i) { storage[3] = i; }
99 void rootdev(uint32_t i) { storage[4] = i; }
105 class AtagMem : public AtagHeader
108 static const uint32_t Size = 4;
109 uint32_t tag() { return MemTag; }
111 void memSize(uint32_t i) { storage[2] = i; }
112 void memStart(uint32_t i) { storage[3] = i; }
118 class AtagRev : public AtagHeader
121 static const uint32_t Size = 3;
122 uint32_t tag() { return RevTag; }
124 void rev(uint32_t i) { storage[2] = i; }
131 class AtagSerial : public AtagHeader
134 static const uint32_t Size = 4;
135 uint32_t tag() { return SerialTag; }
137 void sn(uint64_t i) { storage[2] = (uint32_t)i; storage[3] = i >> 32; }
143 class AtagCmdline : public AtagHeader
146 static const uint32_t Size = 3;
147 uint32_t tag() { return CmdTag; }
149 void cmdline(const std::string &s)
151 // Add one for null terminator
152 int len = s.length() + 1;
154 // 2 + ceiling(len/4)
155 _size = 2 + ((len + 3) >> 2);
158 storage = new uint32_t[size()];
160 strcpy((char*)&storage[2] , s.c_str());
167 class AtagNone : public AtagHeader
170 static const uint32_t Size = 2;
171 virtual bool null() { return true; }
172 uint32_t tag() { return NoneTag; }
179 // example ARM Linux bootloader code
180 // this example is distributed under the BSD licence
181 // Code taken from http://www.simtec.co.uk/products/SWLINUX/files/booting_article.html
184 // list of possible tags
185 #define ATAG_NONE 0x00000000
186 #define ATAG_CORE 0x54410001
187 #define ATAG_MEM 0x54410002
188 #define ATAG_VIDEOTEXT 0x54410003
189 #define ATAG_RAMDISK 0x54410004
190 #define ATAG_INITRD2 0x54420005
191 #define ATAG_SERIAL 0x54410006
192 #define ATAG_REVISION 0x54410007
193 #define ATAG_VIDEOLFB 0x54410008
194 #define ATAG_CMDLINE 0x54410009
196 // structures for each atag
198 u32 size; // length of tag in words including this header
213 struct atag_videotext {
225 struct atag_ramdisk {
231 struct atag_initrd2 {
236 struct atag_serialnr {
241 struct atag_revision {
245 struct atag_videolfb {
262 struct atag_cmdline {
267 struct atag_header hdr;
269 struct atag_core core;
271 struct atag_videotext videotext;
272 struct atag_ramdisk ramdisk;
273 struct atag_initrd2 initrd2;
274 struct atag_serialnr serialnr;
275 struct atag_revision revision;
276 struct atag_videolfb videolfb;
277 struct atag_cmdline cmdline;
283 #endif // __ARCH_ARM_LINUX_ATAG_HH__