ReactOS  0.4.14-dev-358-gbef841c
main.c File Reference
#include "nandflash.h"
Include dependency graph for main.c:

Go to the source code of this file.

Functions

INT NTAPI CreateFlashFile (VOID)
 
VOID NTAPI WriteToFlash (IN INT NandImageFile, IN INT ImageFile, IN ULONG ImageStart, IN ULONG ImageEnd)
 
VOID NTAPI WriteLlb (IN INT NandImageFile)
 
VOID NTAPI WriteBootLdr (IN INT NandImageFile)
 
VOID NTAPI WriteFileSystem (IN INT NandImageFile)
 
VOID NTAPI WriteRamDisk (IN INT RamDiskFile)
 
int main (ULONG argc, char **argv)
 

Variables

PCHAR NandImageName = "reactos.bin"
 
PCHAR LlbImageName = "./output-arm/boot/armllb/armllb.bin"
 
PCHAR BootLdrImageName = "./output-arm/boot/freeldr/freeldr/freeldr.sys"
 
PCHAR FsImageName = "ramdisk.img"
 
PCHAR RamImageName = "ramdisk.bin"
 
ULONG LlbStart = 0x00000000
 
ULONG LlbEnd = 0x00010000
 
ULONG BootLdrStart = 0x00010000
 
ULONG BootLdrEnd = 0x00090000
 
ULONG FsStart = 0x00090000
 
ULONG FsEnd = 0x10000000
 
ULONG NeedsOob = TRUE
 

Function Documentation

◆ CreateFlashFile()

INT NTAPI CreateFlashFile ( VOID  )

Definition at line 34 of file main.c.

35 {
36  INT FileDescriptor, i;
38 
39  /* Try open NAND image */
40  FileDescriptor = open(NandImageName, O_RDWR);
41  if (FileDescriptor)
42  {
43  /* Create NAND image */
44  FileDescriptor = open(NandImageName, O_RDWR | O_CREAT);
45  if (FileDescriptor) return FileDescriptor;
46 
47  /* Create zero buffer */
48  memset(Buffer, 0xff, sizeof(Buffer));
49 
50  /* Write zero buffer */
51  for (i = 0; i < NAND_PAGES; i++) write(FileDescriptor, Buffer, sizeof(Buffer));
52  }
53 
54  /* Return NAND descriptor */
55  return FileDescriptor;
56 }
#define NAND_PAGE_SIZE
Definition: nandflash.h:17
#define open
Definition: acwin.h:95
char CHAR
Definition: xmlstorage.h:175
int32_t INT
Definition: typedefs.h:56
#define NAND_OOB_SIZE
Definition: nandflash.h:18
#define write
Definition: acwin.h:97
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
Definition: bufpool.h:45
#define NAND_PAGES
Definition: nandflash.h:19
#define O_RDWR
Definition: fcntl.h:36
#define memset(x, y, z)
Definition: compat.h:39
PCHAR NandImageName
Definition: main.c:16
#define O_CREAT
Definition: acwin.h:110

Referenced by main().

◆ main()

int main ( ULONG argc  ,
char **  argv 
)

Definition at line 152 of file main.c.

154 {
155  INT NandImageFile, RamDiskFile;
156 
157  /* Flat NAND, no OOB */
158  if (argc == 2) NeedsOob = FALSE;
159 
160  /* Open or create NAND Image File */
161  NandImageFile = CreateFlashFile();
162  if (!NandImageFile) exit(-1);
163 
164  /* Write components */
165  WriteLlb(NandImageFile);
166  WriteBootLdr(NandImageFile);
167  if (NeedsOob)
168  {
169  /* Write the ramdisk normaly */
170  WriteFileSystem(NandImageFile);
171  }
172  else
173  {
174  /* Open a new file for the ramdisk */
175  RamDiskFile = open(RamImageName, O_RDWR | O_CREAT);
176  if (!RamDiskFile) exit(-1);
177 
178  /* Write it */
179  WriteRamDisk(RamDiskFile);
180 
181  /* Close */
182  close(RamDiskFile);
183  }
184 
185 
186  /* Close and return */
187  close(NandImageFile);
188  return 0;
189 }
static int argc
Definition: ServiceArgs.c:12
INT NTAPI CreateFlashFile(VOID)
Definition: main.c:34
#define open
Definition: acwin.h:95
int32_t INT
Definition: typedefs.h:56
PCHAR RamImageName
Definition: main.c:20
VOID NTAPI WriteFileSystem(IN INT NandImageFile)
Definition: main.c:129
ULONG NeedsOob
Definition: main.c:28
#define close
Definition: acwin.h:98
VOID NTAPI WriteLlb(IN INT NandImageFile)
Definition: main.c:105
#define O_RDWR
Definition: fcntl.h:36
void exit(int exitcode)
Definition: _exit.c:33
VOID NTAPI WriteBootLdr(IN INT NandImageFile)
Definition: main.c:117
#define O_CREAT
Definition: acwin.h:110
VOID NTAPI WriteRamDisk(IN INT RamDiskFile)
Definition: main.c:141

◆ WriteBootLdr()

VOID NTAPI WriteBootLdr ( IN INT  NandImageFile)

Definition at line 117 of file main.c.

118 {
119  INT FileDescriptor;
120 
121  /* Open FreeLDR and write it */
122  FileDescriptor = open(BootLdrImageName, O_RDWR);
123  WriteToFlash(NandImageFile, FileDescriptor, BootLdrStart, BootLdrEnd);
124  close(FileDescriptor);
125 }
#define open
Definition: acwin.h:95
PCHAR BootLdrImageName
Definition: main.c:18
int32_t INT
Definition: typedefs.h:56
#define close
Definition: acwin.h:98
ULONG BootLdrEnd
Definition: main.c:24
#define O_RDWR
Definition: fcntl.h:36
VOID NTAPI WriteToFlash(IN INT NandImageFile, IN INT ImageFile, IN ULONG ImageStart, IN ULONG ImageEnd)
Definition: main.c:60
ULONG BootLdrStart
Definition: main.c:24

Referenced by main().

◆ WriteFileSystem()

VOID NTAPI WriteFileSystem ( IN INT  NandImageFile)

Definition at line 129 of file main.c.

130 {
131  INT FileDescriptor;
132 
133  /* Open FS image and write it */
134  FileDescriptor = open(FsImageName, O_RDWR);
135  WriteToFlash(NandImageFile, FileDescriptor, FsStart, FsEnd);
136  close(FileDescriptor);
137 }
#define open
Definition: acwin.h:95
int32_t INT
Definition: typedefs.h:56
ULONG FsEnd
Definition: main.c:25
PCHAR FsImageName
Definition: main.c:19
ULONG FsStart
Definition: main.c:25
#define close
Definition: acwin.h:98
#define O_RDWR
Definition: fcntl.h:36
VOID NTAPI WriteToFlash(IN INT NandImageFile, IN INT ImageFile, IN ULONG ImageStart, IN ULONG ImageEnd)
Definition: main.c:60

Referenced by main().

◆ WriteLlb()

VOID NTAPI WriteLlb ( IN INT  NandImageFile)

Definition at line 105 of file main.c.

106 {
107  INT FileDescriptor;
108 
109  /* Open LLB and write it */
110  FileDescriptor = open(LlbImageName, O_RDWR);
111  WriteToFlash(NandImageFile, FileDescriptor, LlbStart, LlbEnd);
112  close(FileDescriptor);
113 }
#define open
Definition: acwin.h:95
int32_t INT
Definition: typedefs.h:56
ULONG LlbStart
Definition: main.c:23
PCHAR LlbImageName
Definition: main.c:17
#define close
Definition: acwin.h:98
ULONG LlbEnd
Definition: main.c:23
#define O_RDWR
Definition: fcntl.h:36
VOID NTAPI WriteToFlash(IN INT NandImageFile, IN INT ImageFile, IN ULONG ImageStart, IN ULONG ImageEnd)
Definition: main.c:60

Referenced by main().

◆ WriteRamDisk()

VOID NTAPI WriteRamDisk ( IN INT  RamDiskFile)

Definition at line 141 of file main.c.

142 {
143  INT FileDescriptor;
144 
145  /* Open FS image and write it 16MB later */
146  FileDescriptor = open(FsImageName, O_RDWR);
147  WriteToFlash(RamDiskFile, FileDescriptor, 16 * 1024 * 1024, (32 + 16) * 1024 * 1024);
148  close(FileDescriptor);
149 }
#define open
Definition: acwin.h:95
int32_t INT
Definition: typedefs.h:56
PCHAR FsImageName
Definition: main.c:19
#define close
Definition: acwin.h:98
#define O_RDWR
Definition: fcntl.h:36
VOID NTAPI WriteToFlash(IN INT NandImageFile, IN INT ImageFile, IN ULONG ImageStart, IN ULONG ImageEnd)
Definition: main.c:60

Referenced by main().

◆ WriteToFlash()

VOID NTAPI WriteToFlash ( IN INT  NandImageFile,
IN INT  ImageFile,
IN ULONG  ImageStart,
IN ULONG  ImageEnd 
)

Definition at line 60 of file main.c.

64 {
66  ULONG StartPage, EndPage, i, OobSize = 0;
67  BOOLEAN KeepGoing = TRUE;
68 
69  /* Offset to NAND Page convert */
70  StartPage = ImageStart / NAND_PAGE_SIZE;
71  EndPage = ImageEnd / NAND_PAGE_SIZE;
72 
73  /* Jump to NAND offset */
74  if (NeedsOob) OobSize = NAND_OOB_SIZE;
75  lseek(NandImageFile, StartPage * (NAND_PAGE_SIZE + OobSize), SEEK_SET);
76 
77  /* Set input image offset */
79 
80  /* Create zero buffer */
81  memset(Data, 0xff, NAND_PAGE_SIZE);
82  memset(Oob, 0xff, NAND_OOB_SIZE);
83 
84  /* Parse NAND Pages */
85  for (i = StartPage; i < EndPage; i++)
86  {
87  /* Read NAND page from input image */
89  {
90  /* Do last write and quit after */
91  KeepGoing = FALSE;
92  }
93 
94  /* Write OOB and NAND Data */
95  write(NandImageFile, Data, NAND_PAGE_SIZE);
96  if (NeedsOob) write(NandImageFile, Oob, NAND_OOB_SIZE);
97 
98  /* Next page if data continues */
99  if (!KeepGoing) break;
100  }
101 }
static PWSTR ImageFile
Definition: imagefile.c:10
#define TRUE
Definition: types.h:120
#define NAND_PAGE_SIZE
Definition: nandflash.h:17
char CHAR
Definition: xmlstorage.h:175
_Check_return_opt_ _CRTIMP long __cdecl lseek(_In_ int _FileHandle, _In_ long _Offset, _In_ int _Origin)
int WINAPI EndPage(_In_ HDC)
int WINAPI StartPage(_In_ HDC)
#define NAND_OOB_SIZE
Definition: nandflash.h:18
#define write
Definition: acwin.h:97
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned char BOOLEAN
#define SEEK_SET
Definition: jmemansi.c:26
ULONG NeedsOob
Definition: main.c:28
unsigned int ULONG
Definition: retypes.h:1
#define memset(x, y, z)
Definition: compat.h:39
_CRTIMP int __cdecl read(_In_ int _FileHandle, _Out_writes_bytes_(_MaxCharCount) void *_DstBuf, _In_ unsigned int _MaxCharCount)

Referenced by WriteBootLdr(), WriteFileSystem(), WriteLlb(), and WriteRamDisk().

Variable Documentation

◆ BootLdrEnd

ULONG BootLdrEnd = 0x00090000

Definition at line 24 of file main.c.

Referenced by WriteBootLdr().

◆ BootLdrImageName

PCHAR BootLdrImageName = "./output-arm/boot/freeldr/freeldr/freeldr.sys"

Definition at line 18 of file main.c.

Referenced by WriteBootLdr().

◆ BootLdrStart

ULONG BootLdrStart = 0x00010000

Definition at line 24 of file main.c.

Referenced by WriteBootLdr().

◆ FsEnd

ULONG FsEnd = 0x10000000

Definition at line 25 of file main.c.

Referenced by WriteFileSystem().

◆ FsImageName

PCHAR FsImageName = "ramdisk.img"

Definition at line 19 of file main.c.

Referenced by WriteFileSystem(), and WriteRamDisk().

◆ FsStart

ULONG FsStart = 0x00090000

Definition at line 25 of file main.c.

Referenced by WriteFileSystem().

◆ LlbEnd

ULONG LlbEnd = 0x00010000

Definition at line 23 of file main.c.

Referenced by WriteLlb().

◆ LlbImageName

PCHAR LlbImageName = "./output-arm/boot/armllb/armllb.bin"

Definition at line 17 of file main.c.

Referenced by WriteLlb().

◆ LlbStart

ULONG LlbStart = 0x00000000

Definition at line 23 of file main.c.

Referenced by WriteLlb().

◆ NandImageName

PCHAR NandImageName = "reactos.bin"

Definition at line 16 of file main.c.

Referenced by CreateFlashFile().

◆ NeedsOob

ULONG NeedsOob = TRUE

Definition at line 28 of file main.c.

Referenced by main(), and WriteToFlash().

◆ RamImageName

PCHAR RamImageName = "ramdisk.bin"

Definition at line 20 of file main.c.

Referenced by main().