Kinetis Bootloader  2.0.0
Common bootloader for Kinetis devices
src/bm_usb/fat_directory_entry.h
1 /*
2  * Copyright (c) 2013, Freescale Semiconductor, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * o Redistributions of source code must retain the above copyright notice, this list
9  * of conditions and the following disclaimer.
10  *
11  * o Redistributions in binary form must reproduce the above copyright notice, this
12  * list of conditions and the following disclaimer in the documentation and/or
13  * other materials provided with the distribution.
14  *
15  * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16  * contributors may be used to endorse or promote products derived from this
17  * software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 #if !defined(_FAT_DIRECTORY_ENTRY_H_)
31 #define _FAT_DIRECTORY_ENTRY_H_
32 
33 #include "bootloader_common.h"
34 #include <wchar.h>
35 
38 
40 // Definitions
42 
45 {
52 
55 
58 
61 };
62 
63 #pragma pack(push)
64 #pragma pack(1)
65 typedef union FatDirectoryEntry
85 {
87  struct
88  {
89  uint8_t name[11];
90  uint8_t attributes;
91  uint8_t ntReserved;
92  uint8_t creationTimeTenths;
93  uint16_t creationTime;
94  uint16_t creationDate;
95  uint16_t lastAccessDate;
96  uint16_t firstClusterHigh;
97  uint16_t writeTime;
98  uint16_t writeDate;
99  uint16_t firstClusterLow;
100  uint32_t fileSize;
101  } entry;
103  struct
104  {
105  uint8_t order;
106  wchar_t name1[5];
107  uint8_t attributes;
108  uint8_t entryType;
109  uint8_t checksum;
110  wchar_t name2[6];
111  uint16_t firstClusterLow;
112  wchar_t name3[2];
113  } longName;
115 #pragma pack(pop)
116 
118 #define MAKE_FAT_VOLUME_LABEL(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, t, d) \
119  { \
120  .entry = { \
121  .name = { (c1), (c2), (c3), (c4), (c5), (c6), (c7), (c8), (c9), (c10), (c11) }, \
122  .attributes = kVolumeIdAttribute, \
123  .writeTime = (t), \
124  .writeDate = (d), \
125  } \
126  }
127 
138 #define MAKE_FAT_DIR_ENTRY(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, a, t, d, cluster, s) \
139  { \
140  .entry = {.name = { (c1), (c2), (c3), (c4), (c5), (c6), (c7), (c8), (c9), (c10), (c11) }, \
141  .attributes = (a), \
142  .creationTime = (t), \
143  .creationDate = (d), \
144  .lastAccessDate = (d), \
145  .writeTime = (t), \
146  .writeDate = (d), \
147  .firstClusterLow = (cluster), \
148  .fileSize = (s) } \
149  }
150 
157 #define MAKE_FAT_LONG_NAME(o, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, k, l) \
158  { \
159  .longName = {.order = (o) | (l), \
160  .name1 = { (c1), (c2), (c3), (c4), (c5) }, \
161  .attributes = kLongNameAttribute, \
162  .checksum = (k), \
163  .name2 = { (c6), (c7), (c8), (c9), (c10), (c11) }, \
164  .name3 = { (c12), (c13) } } \
165  }
166 
172 #define MAKE_FAT_DATE(d, m, y) ((uint16_t)(((((y)-1980) & 0x7f) << 9) | (((m)&0xf) << 5) | ((d)&0x1f)))
173 
179 #define MAKE_FAT_TIME(h, m, s) ((uint16_t)((((h)&0x1f) << 11) | (((m)&0x3f) << 5) | (((s) / 2) & 0x1f)))
180 
182 
183 #endif // _FAT_DIRECTORY_ENTRY_H_
184 // EOF
Read only.
Definition: src/bm_usb/fat_directory_entry.h:46
The first name byte is set to this value to mark a directory entry as free.
Definition: src/bm_usb/fat_directory_entry.h:60
FAT filesystem directory entry.
Definition: src/bm_usb/fat_directory_entry.h:84
Directory.
Definition: src/bm_usb/fat_directory_entry.h:50
Attribute value to identify a long file name entry.
Definition: src/bm_usb/fat_directory_entry.h:54
System.
Definition: src/bm_usb/fat_directory_entry.h:48
Volume ID.
Definition: src/bm_usb/fat_directory_entry.h:49
Archive.
Definition: src/bm_usb/fat_directory_entry.h:51
_fat_directory_attributes
FAT filesystem directory entry attributes.
Definition: src/bm_usb/fat_directory_entry.h:44
Hidden.
Definition: src/bm_usb/fat_directory_entry.h:47
Marker flag for long name entry order field to indicate the final long name entry.
Definition: src/bm_usb/fat_directory_entry.h:57