1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - MB - include
3   File:     mb_fileinfo.h
4 
5   Copyright 2007-2008 Nintendo. All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law. They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Date:: 2008-09-18#$
14   $Rev: 8573 $
15   $Author: okubata_ryoma $
16  *---------------------------------------------------------------------------*/
17 
18 #ifndef	__MB_FILEINFO_H__
19 #define	__MB_FILEINFO_H__
20 
21 #include <nitro.h>
22 #include <nitro/mb.h>
23 
24 /* Macro definition -------------------------------------------------------- */
25 
26 #define MB_DL_SEGMENT_NUM				(3)     //      Three segments: RomHeader, ARM9Static, and ARM7Static
27 #define MB_DOWNLOAD_FILEINFO_SIZE		(sizeof(MBDownloadFileInfo))
28 
29 #define MB_AUTHCODE_SIZE				(136)   /* Authentication code size */
30 
31 #define ROM_HEADER_SIZE_FULL			(0x160)
32 
33 /* Type structure definition --------------------------------------------------------- */
34 
35 //---------------------------------------------------------
36 // Download file information for multiboot, to be sent from a parent device to a child device
37 //---------------------------------------------------------
38 
39 /*
40  * Segment type definitions
41  */
42 typedef enum MbSegmentType
43 {
44     MB_SEG_ARM9STATIC = 0,
45     MB_SEG_ARM7STATIC,
46     MB_SEG_ROMHEADER
47 }
48 MbSegmentType;
49 
50 /*
51  * The multiboot header structure for initial boot segment information
52  */
53 typedef struct MbDownloadFileInfoHeader
54 {
55     u32     arm9EntryAddr;             /* ARM9 entry address */
56     u32     arm7EntryAddr;             /* ARM7 entry address */
57     u32     padding;
58 }
59 MbDownloadFileInfoHeader;
60 
61 /*
62  * Segment composition information
63  */
64 typedef struct MbSegmentInfo
65 {
66     u32     recv_addr;                 // Temporary storage address at receive time
67     u32     load_addr;                 // Load address  (execution address)
68     u32     size;                      // Segment size
69     u32     target:1;                  // Target (MI_PROCESSOR_ARM9 or _ARM7. A file without attributes is ARM9)
70     u32     rsv:31;                    // Reserved
71 }
72 MbSegmentInfo;                         // 16 bytes
73 
74 
75 /*
76  * Structure for the entire initial boot segment
77  */
78 typedef struct
79 {
80     MbDownloadFileInfoHeader header;   // Header information (the entry address is stored here)
81     MbSegmentInfo seg[MB_DL_SEGMENT_NUM];       // Segment information
82     u32     auth_code[MB_AUTHCODE_SIZE / sizeof(u32)];  // Authentication code
83     u32     reserved[32 / sizeof(u32)]; // Reserved region
84 }
85 MBDownloadFileInfo;
86 
87 
88 /* Table for referencing block information */
89 typedef struct
90 {
91     // Offset from the start of the image in each segment
92     u32     seg_src_offset[MB_DL_SEGMENT_NUM];
93     u16     seg_head_blockno[MB_DL_SEGMENT_NUM];        // Starting block number of the segment
94     u16     block_num;                 /* Total number of blocks */
95 }
96 MB_BlockInfoTable;
97 
98 
99 /* Block transfer-related data */
100 typedef struct
101 {
102     u32     child_address;             // Storage address of the child device
103     u32     size;                      // Block size
104     u32     offset;                    // Set so that it is held in the offset value from the start of the image
105     u8      segment_no;
106     u8      pad[3];
107 }
108 MB_BlockInfo;
109 
110 /* Const variables -------------------------------------------------------- */
111 
112 extern const MbSegmentType MBi_defaultLoadSegList[MB_DL_SEGMENT_NUM];
113 
114 /* Functions --------------------------------------------------------------- */
115 
116 /*
117  * Gets segment information from a pointer to MbDownloadFileInfoHeader
118  *
119  */
MBi_GetSegmentInfo(MbDownloadFileInfoHeader * mdfi,int i)120 static inline MbSegmentInfo *MBi_GetSegmentInfo(MbDownloadFileInfoHeader * mdfi, int i)
121 {
122     return ((MbSegmentInfo *) (mdfi + 1)) + i;
123 }
124 
125 BOOL    MBi_MakeBlockInfoTable(MB_BlockInfoTable * table, MbDownloadFileInfoHeader * mdfi);
126 BOOL    MBi_get_blockinfo(MB_BlockInfo * bi, MB_BlockInfoTable * table, u32 block,
127                           MbDownloadFileInfoHeader * mdfi);
128 u16     MBi_get_blocknum(MB_BlockInfoTable * table);
129 BOOL    MBi_IsAbleToRecv(u8 segment_no, u32 address, u32 size);
130 
131 #endif /* __MB_FILEINFO_H__ */
132