Author: evb
Date: Mon Feb 1 19:29:19 2010
New Revision: 45371
URL:
http://svn.reactos.org/svn/reactos?rev=45371&view=rev
Log:
- NANDFlash tool for building OMAP3 FLASH Images for DevBoard and QEMU-Maemo.
Added:
trunk/reactos/tools/nandflash/
trunk/reactos/tools/nandflash/main.c (with props)
trunk/reactos/tools/nandflash/nandflash.h (with props)
trunk/reactos/tools/nandflash/nandflash.rbuild (with props)
Modified:
trunk/reactos/tools/tools.rbuild
Added: trunk/reactos/tools/nandflash/main.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/nandflash/main.c?rev…
==============================================================================
--- trunk/reactos/tools/nandflash/main.c (added)
+++ trunk/reactos/tools/nandflash/main.c [iso-8859-1] Mon Feb 1 19:29:19 2010
@@ -1,0 +1,154 @@
+/*
+ * PROJECT: OMAP3 NAND Flashing Utility
+ * LICENSE: BSD - See COPYING.ARM in the top level directory
+ * FILE: tools/nandflash/main.c
+ * PURPOSE: Flashes OmapLDR, FreeLDR and a Root FS into a NAND image
+ * PROGRAMMERS: ReactOS Portable Systems Group
+ */
+
+/* INCLUDES *******************************************************************/
+
+#include "nandflash.h"
+
+/* GLOBALS ********************************************************************/
+
+/* File Names */
+PCHAR NandImageName = "reactos.bin";
+PCHAR LlbImageName = "./output-arm/boot/armllb/armllb.bin";
+PCHAR BootLdrImageName = "./output-arm/boot/freeldr/freeldr.sys";
+PCHAR FsImageName = "ReactOS.img";
+
+/* NAND On-Disk Memory Map */
+ULONG LlbStart = 0x00000000, LlbEnd = 0x00080000;
+ULONG BootLdrStart = 0x00280000, BootLdrEnd = 0x00680000;
+ULONG FsStart = 0x00300000, FsEnd = 0x10000000;
+
+/* FUNCTIONS ******************************************************************/
+
+ULONG
+NTAPI
+CreateFlashFile(VOID)
+{
+ ULONG FileDescriptor, i;
+ CHAR Buffer[NAND_PAGE_SIZE + NAND_OOB_SIZE];
+
+ /* Try open NAND image */
+ FileDescriptor = open(NandImageName, O_RDWR);
+ if (!FileDescriptor)
+ {
+ /* Create NAND image */
+ FileDescriptor = open(NandImageName, O_RDWR | O_CREAT);
+ if (!FileDescriptor) return (-1);
+
+ /* Create zero buffer */
+ memset(Buffer, 0xff, sizeof(Buffer));
+
+ /* Write zero buffer */
+ for (i = 0; i < NAND_PAGES; i++) write(FileDescriptor, Buffer,
sizeof(Buffer));
+ }
+
+ /* Return NAND descriptor */
+ return FileDescriptor;
+}
+
+VOID
+NTAPI
+WriteToFlash(IN ULONG NandImageFile,
+ IN ULONG ImageFile,
+ IN ULONG ImageStart,
+ IN ULONG ImageEnd)
+{
+ CHAR Data[NAND_PAGE_SIZE], Oob[NAND_OOB_SIZE];
+ ULONG StartPage, EndPage, i;
+ BOOLEAN KeepGoing = TRUE;
+
+ /* Offset to NAND Page convert */
+ StartPage = ImageStart / NAND_PAGE_SIZE;
+ EndPage = ImageEnd / NAND_PAGE_SIZE;
+
+ /* Jump to NAND offset */
+ lseek(NandImageFile, StartPage * (NAND_PAGE_SIZE + NAND_OOB_SIZE), SEEK_SET);
+
+ /* Set input image offset */
+ lseek(ImageFile, 0, SEEK_SET);
+
+ /* Create zero buffer */
+ memset(Data, 0xff, NAND_PAGE_SIZE);
+ memset(Oob, 0xff, NAND_OOB_SIZE);
+
+ /* Parse NAND Pages */
+ for (i = StartPage; i < EndPage; i++)
+ {
+ /* Read NAND page from input image */
+ if (read(ImageFile, Data, NAND_PAGE_SIZE) < NAND_PAGE_SIZE)
+ {
+ /* Do last write and quit after */
+ KeepGoing = FALSE;
+ }
+
+ /* Write OOB and NAND Data */
+ write(NandImageFile, Data, NAND_PAGE_SIZE);
+ write(NandImageFile, Oob, NAND_OOB_SIZE);
+
+ /* Next page if data continues */
+ if (!KeepGoing) break;
+ }
+}
+
+VOID
+NTAPI
+WriteLlb(IN ULONG NandImageFile)
+{
+ ULONG FileDescriptor;
+
+ /* Open LLB and write it */
+ FileDescriptor = open(LlbImageName, O_RDWR);
+ WriteToFlash(NandImageFile, FileDescriptor, LlbStart, LlbEnd);
+ close(FileDescriptor);
+}
+
+VOID
+NTAPI
+WriteBootLdr(IN ULONG NandImageFile)
+{
+ ULONG FileDescriptor;
+
+ /* Open FreeLDR and write it */
+ FileDescriptor = open(BootLdrImageName, O_RDWR);
+ WriteToFlash(NandImageFile, FileDescriptor, BootLdrStart, BootLdrEnd);
+ close(FileDescriptor);
+}
+
+VOID
+NTAPI
+WriteFileSystem(IN ULONG NandImageFile)
+{
+ ULONG FileDescriptor;
+
+ /* Open FS image and write it */
+ FileDescriptor = open(FsImageName, O_RDWR);
+ WriteToFlash(NandImageFile, FileDescriptor, FsStart, FsEnd);
+ close(FileDescriptor);
+}
+
+int
+main(ULONG argc,
+ char **argv)
+{
+ ULONG NandImageFile;
+
+ /* Open or create NAND Image File */
+ NandImageFile = CreateFlashFile();
+ if (!NandImageFile) exit(-1);
+
+ /* Write components */
+ WriteLlb(NandImageFile);
+ WriteBootLdr(NandImageFile);
+ WriteFileSystem(NandImageFile);
+
+ /* Close and return */
+ close(NandImageFile);
+ return 0;
+}
+
+/* EOF */
Propchange: trunk/reactos/tools/nandflash/main.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/reactos/tools/nandflash/nandflash.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/nandflash/nandflash.…
==============================================================================
--- trunk/reactos/tools/nandflash/nandflash.h (added)
+++ trunk/reactos/tools/nandflash/nandflash.h [iso-8859-1] Mon Feb 1 19:29:19 2010
@@ -1,0 +1,21 @@
+/*
+ * PROJECT: OMAP3 NAND Flashing Utility
+ * LICENSE: BSD - See COPYING.ARM in the top level directory
+ * FILE: tools/nandflash/nandflash.h
+ * PURPOSE: Flashes OmapLDR, FreeLDR and a Root FS into a NAND image
+ * PROGRAMMERS: ReactOS Portable Systems Group
+ */
+
+/* INCLUDES *******************************************************************/
+
+#include <string.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <host/typedefs.h>
+
+/* NAND Image Sizes */
+#define NAND_PAGE_SIZE (2 * 1024) // 2 KB
+#define NAND_OOB_SIZE 64 // 64 bytes
+#define NAND_PAGES ((256 * 1024 * 1024) / NAND_PAGE_SIZE) // 256 MB
+
+/* EOF */
Propchange: trunk/reactos/tools/nandflash/nandflash.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/reactos/tools/nandflash/nandflash.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/nandflash/nandflash.…
==============================================================================
--- trunk/reactos/tools/nandflash/nandflash.rbuild (added)
+++ trunk/reactos/tools/nandflash/nandflash.rbuild [iso-8859-1] Mon Feb 1 19:29:19 2010
@@ -1,0 +1,5 @@
+<?xml version="1.0"?>
+<!DOCTYPE module SYSTEM "../../tools/rbuild/project.dtd">
+<module name="nandflash" type="buildtool">
+ <file>main.c</file>
+</module>
Propchange: trunk/reactos/tools/nandflash/nandflash.rbuild
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/reactos/tools/tools.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/tools.rbuild?rev=453…
==============================================================================
--- trunk/reactos/tools/tools.rbuild [iso-8859-1] (original)
+++ trunk/reactos/tools/tools.rbuild [iso-8859-1] Mon Feb 1 19:29:19 2010
@@ -9,6 +9,9 @@
</directory>
<directory name="kbdtool">
<xi:include href="kbdtool/kbdtool.rbuild" />
+</directory>
+<directory name="nandflash">
+ <xi:include href="nandflash/nandflash.rbuild" />
</directory>
<directory name="mkhive">
<xi:include href="mkhive/mkhive.rbuild" />