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__
45 #include "base/types.hh"
51 SerialTag = 0x54410006,
63 /** Tag (normally starts with 'T''A' and 16 bits of number */
64 virtual uint32_t tag() = 0;
65 /** If the header should be 0 size */
66 virtual bool null() { return false; }
68 uint32_t size() const { return _size; }
70 AtagHeader(uint32_t s)
73 storage = new uint32_t[size()];
81 uint32_t copyOut(uint8_t *p)
83 storage[0] = null() ? 0 : size();
85 memcpy(p, storage, size() << 2);
90 class AtagCore : public AtagHeader
93 static const uint32_t Size = 5;
94 uint32_t tag() { return CoreTag; }
96 void flags(uint32_t i) { storage[2] = i; }
97 void pagesize(uint32_t i) { storage[3] = i; }
98 void rootdev(uint32_t i) { storage[4] = i; }
104 class AtagMem : public AtagHeader
107 static const uint32_t Size = 4;
108 uint32_t tag() { return MemTag; }
110 void memSize(uint32_t i) { storage[2] = i; }
111 void memStart(uint32_t i) { storage[3] = i; }
117 class AtagRev : public AtagHeader
120 static const uint32_t Size = 3;
121 uint32_t tag() { return RevTag; }
123 void rev(uint32_t i) { storage[2] = i; }
130 class AtagSerial : public AtagHeader
133 static const uint32_t Size = 4;
134 uint32_t tag() { return SerialTag; }
136 void sn(uint64_t i) { storage[2] = (uint32_t)i; storage[3] = i >> 32; }
142 class AtagCmdline : public AtagHeader
145 static const uint32_t Size = 3;
146 uint32_t tag() { return CmdTag; }
148 void cmdline(const std::string &s)
150 // Add one for null terminator
151 int len = s.length() + 1;
153 // 2 + ceiling(len/4)
154 _size = 2 + ((len + 3) >> 2);
157 storage = new uint32_t[size()];
159 strcpy((char*)&storage[2] , s.c_str());
166 class AtagNone : public AtagHeader
169 static const uint32_t Size = 2;
170 virtual bool null() { return true; }
171 uint32_t tag() { return NoneTag; }
178 // example ARM Linux bootloader code
179 // this example is distributed under the BSD licence
180 // Code taken from http://www.simtec.co.uk/products/SWLINUX/files/booting_article.html
183 // list of possible tags
184 #define ATAG_NONE 0x00000000
185 #define ATAG_CORE 0x54410001
186 #define ATAG_MEM 0x54410002
187 #define ATAG_VIDEOTEXT 0x54410003
188 #define ATAG_RAMDISK 0x54410004
189 #define ATAG_INITRD2 0x54420005
190 #define ATAG_SERIAL 0x54410006
191 #define ATAG_REVISION 0x54410007
192 #define ATAG_VIDEOLFB 0x54410008
193 #define ATAG_CMDLINE 0x54410009
195 // structures for each atag
197 u32 size; // length of tag in words including this header
212 struct atag_videotext {
224 struct atag_ramdisk {
230 struct atag_initrd2 {
235 struct atag_serialnr {
240 struct atag_revision {
244 struct atag_videolfb {
261 struct atag_cmdline {
266 struct atag_header hdr;
268 struct atag_core core;
270 struct atag_videotext videotext;
271 struct atag_ramdisk ramdisk;
272 struct atag_initrd2 initrd2;
273 struct atag_serialnr serialnr;
274 struct atag_revision revision;
275 struct atag_videolfb videolfb;
276 struct atag_cmdline cmdline;
282 #endif // __ARCH_ARM_LINUX_ATAG_HH__