freemyipod r469 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r468‎ | r469 | r470 >
Date:02:02, 22 January 2011
Author:theseven
Status:new
Tags:
Comment:
emCORE: Allow libraries to not have an initialization functionAdd emCORE Booting Library (for now it just contains verify_rockbox_checksum)
Modified paths:
  • /libs (added) (history)
  • /libs/boot (added) (history)
  • /libs/boot/Makefile (added) (history)
  • /libs/boot/SOURCES (added) (history)
  • /libs/boot/export (added) (history)
  • /libs/boot/export/libboot.h (added) (history)
  • /libs/boot/ls.x (added) (history)
  • /libs/boot/main.c (added) (history)
  • /libs/boot/version.h (added) (history)

Diff [purge]

Index: libs/boot/export/libboot.h
@@ -0,0 +1,52 @@
 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 __LIBBOOT_H__
 26+#define __LIBBOOT_H__
 27+
 28+#include "emcorelib.h"
 29+
 30+
 31+int verify_rockbox_checksum(void* image, size_t size);
 32+
 33+
 34+/* increase this every time the api struct changes */
 35+#define LIBBOOT_API_VERSION 1
 36+
 37+/* update this to latest version if a change to the api struct breaks
 38+ backwards compatibility (and please take the opportunity to sort in any
 39+ new function which are "waiting" at the end of the function table) */
 40+#define LIBBOOT_MIN_API_VERSION 1
 41+
 42+/* NOTE: To support backwards compatibility, only add new functions at
 43+ the end of the structure. Every time you add a new function,
 44+ remember to increase LIBBOOT_API_VERSION. If you make changes to the
 45+ existing APIs, also update LIBBOOT_MIN_API_VERSION to current version */
 46+
 47+struct libboot_api
 48+{
 49+ typeof(verify_rockbox_checksum)* verify_rockbox_checksum;
 50+};
 51+
 52+
 53+#endif
Property changes on: libs/boot/export/libboot.h
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
 54+*
\ No newline at end of property
Index: libs/boot/SOURCES
@@ -0,0 +1 @@
 2+main.c
Property changes on: libs/boot/SOURCES
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
 3+*
\ No newline at end of property
Index: libs/boot/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(0x4);
 22+ } > VIRTUAL
 23+
 24+ .data :
 25+ {
 26+ *(.rodata*)
 27+ . = ALIGN(0x4);
 28+ *(.data*)
 29+ . = ALIGN(0x4);
 30+ } > VIRTUAL
 31+
 32+ .bss (NOLOAD) :
 33+ {
 34+ *(.bss*)
 35+ *(COMMON)
 36+ } > VIRTUAL
 37+
 38+ /DISCARD/ :
 39+ {
 40+ *(.eh_frame)
 41+ }
 42+
 43+}
Property changes on: libs/boot/ls.x
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
 44+*
\ No newline at end of property
Index: libs/boot/main.c
@@ -0,0 +1,64 @@
 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/libboot.h"
 27+
 28+
 29+struct libboot_api apitable =
 30+{
 31+ .verify_rockbox_checksum = verify_rockbox_checksum
 32+};
 33+
 34+
 35+EMCORE_LIB_HEADER(0x4c424365, LIBBOOT_API_VERSION, LIBBOOT_MIN_API_VERSION, NULL, NULL, apitable)
 36+
 37+
 38+int verify_rockbox_checksum(void* image, size_t size)
 39+{
 40+ int i;
 41+ uint8_t* data = (uint8_t*)image;
 42+ uint32_t checksum = data[3] | (data[2] << 8) | (data[1] << 16) | (data[0] << 24);
 43+ uint32_t platform;
 44+ switch (get_platform_id())
 45+ {
 46+ case 0x47324e49: // IN2G
 47+ checksum -= 62;
 48+ platform = 0x67326e6e; // nn2g
 49+ break;
 50+ case 0x4c435049: // IPCL
 51+ checksum -= 71;
 52+ platform = 0x67367069; // ip6g
 53+ break;
 54+ default:
 55+ return -3;
 56+ }
 57+ if (*((uint32_t*)&data[4]) != platform) return -2;
 58+ for (i = 0; i < size - 8; i++)
 59+ {
 60+ data[i] = data[i + 8];
 61+ checksum -= data[i + 8];
 62+ }
 63+ if (checksum) return -1;
 64+ return 0;
 65+}
Property changes on: libs/boot/main.c
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
 66+*
\ No newline at end of property
Index: libs/boot/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
Property changes on: libs/boot/version.h
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
 38+*
\ No newline at end of property
Index: libs/boot/Makefile
@@ -0,0 +1,109 @@
 2+NAME := boot
 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
 21+LDFLAGS += "$(shell $(CC) -print-libgcc-file-name)" -d -r --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/%.S
 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/version.h: version.h .svn/entries build
 97+ @echo [PP] $<
 98+ifeq ($(shell uname),WindowsNT)
 99+ @sed -e "s/\$$REVISION\$$/$(REVISION)/" -e "s/\$$REVISIONINT\$$/$(REVISIONINT)/" < $< > $@
 100+else
 101+ @sed -e 's/\$$REVISION\$$/$(REVISION)/' -e 's/\$$REVISIONINT\$$/$(REVISIONINT)/' < $< > $@
 102+endif
 103+
 104+build:
 105+ @mkdir $@
 106+
 107+clean:
 108+ rm -rf build
 109+
 110+.PHONY: all clean $(NAME)
Property changes on: libs/boot/Makefile
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
 111+*
\ No newline at end of property
Index: libs/boot
Property changes on: libs/boot
___________________________________________________________________
Added: svn:ignore
## -0,0 +1 ##
 112+build