| Index: libs/mkfat32/export/libmkfat32.h |
| — | — | @@ -0,0 +1,57 @@ |
| | 2 | +//
|
| | 3 | +//
|
| | 4 | +// Copyright 2010 TheSeven
|
| | 5 | +//
|
| | 6 | +//
|
| | 7 | +// This file is part of emCORE.
|
| | 8 | +//
|
| | 9 | +// emCORE is free software: you can redistribute it and/or
|
| | 10 | +// modify it under the terms of the GNU General Public License as
|
| | 11 | +// published by the Free Software Foundation, either version 2 of the
|
| | 12 | +// License, or (at your option) any later version.
|
| | 13 | +//
|
| | 14 | +// emCORE is distributed in the hope that it will be useful,
|
| | 15 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| | 16 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
| | 17 | +// See the GNU General Public License for more details.
|
| | 18 | +//
|
| | 19 | +// You should have received a copy of the GNU General Public License along
|
| | 20 | +// with emCORE. If not, see <http://www.gnu.org/licenses/>.
|
| | 21 | +//
|
| | 22 | +//
|
| | 23 | +
|
| | 24 | +
|
| | 25 | +#ifndef __EXPORT_LIBMKFAT32_H__
|
| | 26 | +#define __EXPORT_LIBMKFAT32_H__
|
| | 27 | +
|
| | 28 | +#include "emcorelib.h"
|
| | 29 | +
|
| | 30 | +
|
| | 31 | +int mkfat32(int volume, int startsector, int totalsectors, int sectorsize, int secperclus,
|
| | 32 | + const char* label, void* statususer, void (*statusinit)(void* user, int max),
|
| | 33 | + void (*statuscallback)(void* user, int current));
|
| | 34 | +
|
| | 35 | +
|
| | 36 | +/* emCORE library identifier */
|
| | 37 | +#define LIBMKFAT32_IDENTIFIER 0x3233464d
|
| | 38 | +
|
| | 39 | +/* increase this every time the api struct changes */
|
| | 40 | +#define LIBMKFAT32_API_VERSION 1
|
| | 41 | +
|
| | 42 | +/* update this to latest version if a change to the api struct breaks
|
| | 43 | + backwards compatibility (and please take the opportunity to sort in any
|
| | 44 | + new function which are "waiting" at the end of the function table) */
|
| | 45 | +#define LIBMKFAT32_MIN_API_VERSION 1
|
| | 46 | +
|
| | 47 | +/* NOTE: To support backwards compatibility, only add new functions at
|
| | 48 | + the end of the structure. Every time you add a new function,
|
| | 49 | + remember to increase LIBMKFAT32_API_VERSION. If you make changes to the
|
| | 50 | + existing APIs, also update LIBMKFAT32_MIN_API_VERSION to current version */
|
| | 51 | +
|
| | 52 | +struct libmkfat32_api
|
| | 53 | +{
|
| | 54 | + typeof(mkfat32)* mkfat32;
|
| | 55 | +};
|
| | 56 | +
|
| | 57 | +
|
| | 58 | +#endif
|
| Index: libs/mkfat32/SOURCES |
| — | — | @@ -0,0 +1 @@ |
| | 2 | +main.c
|
| Index: libs/mkfat32/ls.x |
| — | — | @@ -0,0 +1,42 @@ |
| | 2 | +ENTRY(__emcore_lib_header)
|
| | 3 | +OUTPUT_FORMAT(elf32-littlearm)
|
| | 4 | +OUTPUT_ARCH(arm)
|
| | 5 | +
|
| | 6 | +MEMORY
|
| | 7 | +{
|
| | 8 | + VIRTUAL : ORIGIN = 0x00000000, LENGTH = 0x10000000
|
| | 9 | +}
|
| | 10 | +
|
| | 11 | +SECTIONS
|
| | 12 | +{
|
| | 13 | + .text :
|
| | 14 | + {
|
| | 15 | + __emcore_lib_base = .;
|
| | 16 | + KEEP(.emcoreentrypoint*)
|
| | 17 | + *(.emcoreentrypoint*)
|
| | 18 | + *(.text*)
|
| | 19 | + *(.glue_7)
|
| | 20 | + *(.glue_7t)
|
| | 21 | + . = ALIGN(0x10);
|
| | 22 | + } > VIRTUAL
|
| | 23 | +
|
| | 24 | + .data :
|
| | 25 | + {
|
| | 26 | + *(.rodata*)
|
| | 27 | + . = ALIGN(0x4);
|
| | 28 | + *(.data*)
|
| | 29 | + . = ALIGN(0x10);
|
| | 30 | + } > VIRTUAL
|
| | 31 | +
|
| | 32 | + .bss (NOLOAD) :
|
| | 33 | + {
|
| | 34 | + *(.bss*)
|
| | 35 | + *(COMMON)
|
| | 36 | + } > VIRTUAL
|
| | 37 | +
|
| | 38 | + /DISCARD/ :
|
| | 39 | + {
|
| | 40 | + *(.eh_frame)
|
| | 41 | + }
|
| | 42 | +
|
| | 43 | +}
|
| Index: libs/mkfat32/main.c |
| — | — | @@ -0,0 +1,99 @@ |
| | 2 | +//
|
| | 3 | +//
|
| | 4 | +// Copyright 2010 TheSeven
|
| | 5 | +//
|
| | 6 | +//
|
| | 7 | +// This file is part of emCORE.
|
| | 8 | +//
|
| | 9 | +// emCORE is free software: you can redistribute it and/or
|
| | 10 | +// modify it under the terms of the GNU General Public License as
|
| | 11 | +// published by the Free Software Foundation, either version 2 of the
|
| | 12 | +// License, or (at your option) any later version.
|
| | 13 | +//
|
| | 14 | +// emCORE is distributed in the hope that it will be useful,
|
| | 15 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| | 16 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
| | 17 | +// See the GNU General Public License for more details.
|
| | 18 | +//
|
| | 19 | +// You should have received a copy of the GNU General Public License along
|
| | 20 | +// with emCORE. If not, see <http://www.gnu.org/licenses/>.
|
| | 21 | +//
|
| | 22 | +//
|
| | 23 | +
|
| | 24 | +
|
| | 25 | +#include "emcorelib.h"
|
| | 26 | +#include "export/libmkfat32.h"
|
| | 27 | +
|
| | 28 | +
|
| | 29 | +struct libmkfat32_api apitable =
|
| | 30 | +{
|
| | 31 | + .mkfat32 = mkfat32
|
| | 32 | +};
|
| | 33 | +
|
| | 34 | +
|
| | 35 | +EMCORE_LIB_HEADER(LIBMKFAT32_IDENTIFIER, LIBMKFAT32_API_VERSION, LIBMKFAT32_MIN_API_VERSION,
|
| | 36 | + NULL, NULL, apitable)
|
| | 37 | +
|
| | 38 | +
|
| | 39 | +int mkfat32(int volume, int startsector, int totalsectors, int sectorsize, int secperclus,
|
| | 40 | + const char* label, void* statususer, void (*statusinit)(void* user, int max),
|
| | 41 | + void (*statuscallback)(void* user, int current))
|
| | 42 | +{
|
| | 43 | + uint32_t i, j;
|
| | 44 | + uint32_t rootdirclus = 2;
|
| | 45 | + uint32_t fatsectors = 1;
|
| | 46 | + uint32_t oldfatsectors = 0;
|
| | 47 | + uint32_t clustercount;
|
| | 48 | + uint32_t reserved = 2;
|
| | 49 | + disk_unmount(volume);
|
| | 50 | + while (fatsectors != oldfatsectors)
|
| | 51 | + {
|
| | 52 | + oldfatsectors = fatsectors;
|
| | 53 | + clustercount = (totalsectors - fatsectors - reserved) / secperclus;
|
| | 54 | + fatsectors = (clustercount * 4 + sectorsize + 8) / sectorsize;
|
| | 55 | + }
|
| | 56 | + uint32_t database = fatsectors + reserved;
|
| | 57 | + uint32_t clusoffset = 0;
|
| | 58 | + uint32_t* buf = memalign(0x10, 32 * sectorsize);
|
| | 59 | + memset(buf, 0, sectorsize);
|
| | 60 | + memcpy(buf, "\xeb\x58\x00MSWIN5.0", 0xb);
|
| | 61 | + ((uint8_t*)buf)[0xb] = sectorsize & 0xff;
|
| | 62 | + ((uint8_t*)buf)[0xc] = sectorsize >> 8;
|
| | 63 | + ((uint8_t*)buf)[0xd] = secperclus;
|
| | 64 | + ((uint16_t*)buf)[7] = reserved;
|
| | 65 | + memcpy(&((uint8_t*)buf)[0x10], "\x01\0\0\0\0\xf8\0\0\x3f\0\xff", 0xb);
|
| | 66 | + buf[8] = startsector;
|
| | 67 | + buf[8] = totalsectors;
|
| | 68 | + buf[9] = fatsectors;
|
| | 69 | + buf[0xb] = rootdirclus + clusoffset;
|
| | 70 | + ((uint16_t*)buf)[0x18] = 1;
|
| | 71 | + ((uint8_t*)buf)[0x40] = 0x80;
|
| | 72 | + ((uint8_t*)buf)[0x42] = 0x29;
|
| | 73 | + memcpy(&((uint8_t*)buf)[0x47], label, 0xb);
|
| | 74 | + memcpy(&((uint8_t*)buf)[0x52], "FAT32 ", 8);
|
| | 75 | + ((uint16_t*)buf)[0xff] = 0xaa55;
|
| | 76 | + PASS_RC(storage_write_sectors_md(volume, startsector, 1, buf), 2, 0);
|
| | 77 | + memset(buf, 0, sectorsize);
|
| | 78 | + buf[0] = 0x41615252;
|
| | 79 | + buf[0x79] = 0x61417272;
|
| | 80 | + buf[0x7a] = clustercount - 1;
|
| | 81 | + buf[0x7b] = 2;
|
| | 82 | + buf[0x7f] = 0xaa550000;
|
| | 83 | + PASS_RC(storage_write_sectors_md(volume, startsector + 1, 1, buf), 2, 1);
|
| | 84 | + statusinit(statususer, fatsectors);
|
| | 85 | + uint32_t cursect = 0;
|
| | 86 | + for (i = 0; i < fatsectors; i += 32)
|
| | 87 | + {
|
| | 88 | + memset(buf, 0, 32 * sectorsize);
|
| | 89 | + if (!i) memcpy(buf, "\xf8\xff\xff\x0f\xff\xff\xff\xff\xff\xff\xff\x0f", 12);
|
| | 90 | + PASS_RC(storage_write_sectors_md(volume, startsector + reserved + i,
|
| | 91 | + MIN(fatsectors - i, 32), buf), 2, 2);
|
| | 92 | + statuscallback(statususer, i);
|
| | 93 | + }
|
| | 94 | + memset(buf, 0, secperclus * sectorsize);
|
| | 95 | + memcpy(buf, label, 11);
|
| | 96 | + ((uint8_t*)buf)[0xc] = 0x80;
|
| | 97 | + PASS_RC(storage_write_sectors_md(volume, startsector + database, secperclus, buf), 2, 3);
|
| | 98 | + free(buf);
|
| | 99 | + disk_mount(volume);
|
| | 100 | +}
|
| Index: libs/mkfat32/version.h |
| — | — | @@ -0,0 +1,36 @@ |
| | 2 | +//
|
| | 3 | +//
|
| | 4 | +// Copyright 2010 TheSeven
|
| | 5 | +//
|
| | 6 | +//
|
| | 7 | +// This file is part of emBIOS.
|
| | 8 | +//
|
| | 9 | +// emBIOS is free software: you can redistribute it and/or
|
| | 10 | +// modify it under the terms of the GNU General Public License as
|
| | 11 | +// published by the Free Software Foundation, either version 2 of the
|
| | 12 | +// License, or (at your option) any later version.
|
| | 13 | +//
|
| | 14 | +// emBIOS is distributed in the hope that it will be useful,
|
| | 15 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| | 16 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
| | 17 | +// See the GNU General Public License for more details.
|
| | 18 | +//
|
| | 19 | +// You should have received a copy of the GNU General Public License along
|
| | 20 | +// with emBIOS. If not, see <http://www.gnu.org/licenses/>.
|
| | 21 | +//
|
| | 22 | +//
|
| | 23 | +
|
| | 24 | +
|
| | 25 | +#ifndef __VERSION_H__
|
| | 26 | +#define __VERSION_H__
|
| | 27 | +
|
| | 28 | +
|
| | 29 | +#define VERSION "0.0.1pre"
|
| | 30 | +#define VERSION_MAJOR 0
|
| | 31 | +#define VERSION_MINOR 0
|
| | 32 | +#define VERSION_PATCH 1
|
| | 33 | +#define VERSION_SVN "$REVISION$"
|
| | 34 | +#define VERSION_SVN_INT $REVISIONINT$
|
| | 35 | +
|
| | 36 | +
|
| | 37 | +#endif |
| \ No newline at end of file |
| Index: libs/mkfat32/Makefile |
| — | — | @@ -0,0 +1,118 @@ |
| | 2 | +NAME := mkfat32
|
| | 3 | +COMPRESS := true
|
| | 4 | +
|
| | 5 | +EMCOREDIR ?= ../../emcore/trunk/
|
| | 6 | +
|
| | 7 | +ifeq ($(shell uname),WindowsNT)
|
| | 8 | +CCACHE :=
|
| | 9 | +else
|
| | 10 | +CCACHE := $(shell which ccache)
|
| | 11 | +endif
|
| | 12 | +
|
| | 13 | +CROSS ?= arm-elf-eabi-
|
| | 14 | +CC := $(CCACHE) $(CROSS)gcc
|
| | 15 | +AS := $(CROSS)as
|
| | 16 | +LD := $(CROSS)ld
|
| | 17 | +OBJCOPY := $(CROSS)objcopy
|
| | 18 | +ELF2ECA := $(CROSS)elf2emcoreapp
|
| | 19 | +
|
| | 20 | +CFLAGS += -Os -fno-pie -fno-stack-protector -fomit-frame-pointer -I. -I$(EMCOREDIR)/export -ffunction-sections -fdata-sections -mcpu=arm940t -DARM_ARCH=4
|
| | 21 | +LDFLAGS += "$(shell $(CC) -print-libgcc-file-name)" --emit-relocs --gc-sections
|
| | 22 | +
|
| | 23 | +preprocess = $(shell $(CC) $(PPCFLAGS) $(2) -E -P -x c $(1) | grep -v "^\#")
|
| | 24 | +preprocesspaths = $(shell $(CC) $(PPCFLAGS) $(2) -E -P -x c $(1) | grep -v "^\#" | sed -e "s:^..*:$(dir $(1))&:")
|
| | 25 | +
|
| | 26 | +REVISION := $(shell svnversion .)
|
| | 27 | +REVISIONINT := $(shell echo $(REVISION) | sed -e "s/[^0-9].*$$//")
|
| | 28 | +
|
| | 29 | +HELPERS := build/__emcore_armhelpers.o
|
| | 30 | +
|
| | 31 | +SRC := $(call preprocesspaths,SOURCES,-I. -I..)
|
| | 32 | +OBJ := $(SRC:%.c=build/%.o)
|
| | 33 | +OBJ := $(OBJ:%.S=build/%.o) $(HELPERS)
|
| | 34 | +
|
| | 35 | +all: $(NAME)
|
| | 36 | +
|
| | 37 | +-include $(OBJ:%=%.dep)
|
| | 38 | +
|
| | 39 | +$(NAME): build/$(NAME).emcorelib
|
| | 40 | +
|
| | 41 | +build/$(NAME).emcorelib: build/$(NAME).elf
|
| | 42 | + @echo [EMCLIB] $<
|
| | 43 | +ifeq ($(COMPRESS),true)
|
| | 44 | + @$(ELF2ECA) -l -z -s 0 -o $@ $^
|
| | 45 | +else
|
| | 46 | + @$(ELF2ECA) -l -s 0 -o $@ $^
|
| | 47 | +endif
|
| | 48 | +
|
| | 49 | +build/$(NAME).elf: ls.x $(OBJ)
|
| | 50 | + @echo [LD] $@
|
| | 51 | + @$(LD) $(LDFLAGS) -o $@ -T ls.x $(OBJ)
|
| | 52 | +
|
| | 53 | +build/%.o: %.c build/version.h
|
| | 54 | + @echo [CC] $<
|
| | 55 | +ifeq ($(shell uname),WindowsNT)
|
| | 56 | + @-if not exist $(subst /,\,$(dir $@)) md $(subst /,\,$(dir $@))
|
| | 57 | +else
|
| | 58 | + @-mkdir -p $(dir $@)
|
| | 59 | +endif
|
| | 60 | + @$(CC) -c $(CFLAGS) -o $@ $<
|
| | 61 | + @$(CC) -MM $(CFLAGS) $< > $@.dep.tmp
|
| | 62 | + @sed -e "s|.*:|$@:|" < $@.dep.tmp > $@.dep
|
| | 63 | +ifeq ($(shell uname),WindowsNT)
|
| | 64 | + @sed -e "s/.*://" -e "s/\\$$//" < $@.dep.tmp | fmt -1 | sed -e "s/^ *//" -e "s/$$/:/" >> $@.dep
|
| | 65 | +else
|
| | 66 | + @sed -e 's/.*://' -e 's/\\$$//' < $@.dep.tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $@.dep
|
| | 67 | +endif
|
| | 68 | + @rm -f $@.dep.tmp
|
| | 69 | +
|
| | 70 | +build/%.o: %.S build/version.h
|
| | 71 | + @echo [CC] $<
|
| | 72 | +ifeq ($(shell uname),WindowsNT)
|
| | 73 | + @-if not exist $(subst /,\,$(dir $@)) md $(subst /,\,$(dir $@))
|
| | 74 | +else
|
| | 75 | + @-mkdir -p $(dir $@)
|
| | 76 | +endif
|
| | 77 | + @$(CC) -c $(CFLAGS) -o $@ $<
|
| | 78 | + @$(CC) -MM $(CFLAGS) $< > $@.dep.tmp
|
| | 79 | + @sed -e "s|.*:|$@:|" < $@.dep.tmp > $@.dep
|
| | 80 | +ifeq ($(shell uname),WindowsNT)
|
| | 81 | + @sed -e "s/.*://" -e "s/\\$$//" < $@.dep.tmp | fmt -1 | sed -e "s/^ *//" -e "s/$$/:/" >> $@.dep
|
| | 82 | +else
|
| | 83 | + @sed -e 's/.*://' -e 's/\\$$//' < $@.dep.tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $@.dep
|
| | 84 | +endif
|
| | 85 | + @rm -f $@.dep.tmp
|
| | 86 | +
|
| | 87 | +build/__emcore_%.o: $(EMCOREDIR)/export/%.c
|
| | 88 | + @echo [CC] $<
|
| | 89 | +ifeq ($(shell uname),WindowsNT)
|
| | 90 | + @-if not exist $(subst /,\,$(dir $@)) md $(subst /,\,$(dir $@))
|
| | 91 | +else
|
| | 92 | + @-mkdir -p $(dir $@)
|
| | 93 | +endif
|
| | 94 | + @$(CC) -c $(CFLAGS) -o $@ $<
|
| | 95 | +
|
| | 96 | +build/__emcore_%.o: $(EMCOREDIR)/export/%.S
|
| | 97 | + @echo [CC] $<
|
| | 98 | +ifeq ($(shell uname),WindowsNT)
|
| | 99 | + @-if not exist $(subst /,\,$(dir $@)) md $(subst /,\,$(dir $@))
|
| | 100 | +else
|
| | 101 | + @-mkdir -p $(dir $@)
|
| | 102 | +endif
|
| | 103 | + @$(CC) -c $(CFLAGS) -o $@ $<
|
| | 104 | +
|
| | 105 | +build/version.h: version.h .svn/entries build
|
| | 106 | + @echo [PP] $<
|
| | 107 | +ifeq ($(shell uname),WindowsNT)
|
| | 108 | + @sed -e "s/\$$REVISION\$$/$(REVISION)/" -e "s/\$$REVISIONINT\$$/$(REVISIONINT)/" < $< > $@
|
| | 109 | +else
|
| | 110 | + @sed -e 's/\$$REVISION\$$/$(REVISION)/' -e 's/\$$REVISIONINT\$$/$(REVISIONINT)/' < $< > $@
|
| | 111 | +endif
|
| | 112 | +
|
| | 113 | +build:
|
| | 114 | + @mkdir $@
|
| | 115 | +
|
| | 116 | +clean:
|
| | 117 | + rm -rf build
|
| | 118 | +
|
| | 119 | +.PHONY: all clean $(NAME)
|
| Index: libs/mkfat32 |
| Property changes on: libs/mkfat32 |
| ___________________________________________________________________ |
| Added: svn:ignore |
| ## -0,0 +1 ## |
| | 120 | +build |