freemyipod r383 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r382‎ | r383 | r384 >
Date:22:33, 23 December 2010
Author:theseven
Status:new
Tags:
Comment:
Add uninstaller for iPod Classic
Modified paths:
  • /apps/installer-classic/Makefile (modified) (history)
  • /apps/installer-classic/flashfiles/iloader.conf (modified) (history)
  • /apps/installer-classic/oobe/oobe.psd (modified) (history)
  • /apps/installer-classic/oobe/warning.bmp (modified) (history)
  • /apps/installer-classic/tools/geninstaller.py (modified) (history)
  • /apps/uninstaller-classic (added) (history)
  • /apps/uninstaller-classic/Makefile (added) (history)
  • /apps/uninstaller-classic/SOURCES (added) (history)
  • /apps/uninstaller-classic/ls.x (added) (history)
  • /apps/uninstaller-classic/main.c (added) (history)
  • /apps/uninstaller-classic/version.h (added) (history)

Diff [purge]

Index: apps/uninstaller-classic/SOURCES
@@ -0,0 +1 @@
 2+main.c
Index: apps/uninstaller-classic/ls.x
@@ -0,0 +1,40 @@
 2+ENTRY(__embios_executable_hdr)
 3+OUTPUT_FORMAT(elf32-littlearm)
 4+OUTPUT_ARCH(arm)
 5+
 6+MEMORY
 7+{
 8+ RAM : ORIGIN = 0x08000000, LENGTH = 0x01000000
 9+}
 10+
 11+SECTIONS
 12+{
 13+ .text :
 14+ {
 15+ KEEP(.execheader*)
 16+ *(.execheader*)
 17+ *(.text*)
 18+ *(.glue_7)
 19+ *(.glue_7t)
 20+ . = ALIGN(0x4);
 21+ *(.rodata*)
 22+ . = ALIGN(0x4);
 23+ *(.data*)
 24+ . = ALIGN(0x4);
 25+ } > RAM
 26+
 27+ .bss (NOLOAD) :
 28+ {
 29+ __bss_start = .;
 30+ *(.bss*)
 31+ *(COMMON)
 32+ __bss_end = .;
 33+ *(.stack*)
 34+ } > RAM
 35+
 36+ /DISCARD/ :
 37+ {
 38+ *(.eh_frame)
 39+ }
 40+
 41+}
Index: apps/uninstaller-classic/main.c
@@ -0,0 +1,106 @@
 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+#include "embiosapp.h"
 26+#include "build/version.h"
 27+
 28+
 29+void main();
 30+EMBIOS_APP_HEADER("Uninstaller thread", 0x1000, main, 127)
 31+
 32+
 33+uint16_t lcdbuffer[320 * 240];
 34+
 35+struct wakeup eventwakeup;
 36+volatile int button;
 37+
 38+uint8_t norbuf[0x100000] __attribute__((aligned(16)));
 39+#define norbufword ((uint32_t*)norbuf)
 40+
 41+void handler(enum button_event eventtype, int which, int value)
 42+{
 43+ if (eventtype == BUTTON_PRESS) button |= 1 << which;
 44+ wakeup_signal(&eventwakeup);
 45+}
 46+
 47+void main(void)
 48+{
 49+ uint32_t i, j, k;
 50+ struct progressbar_state progressbar;
 51+
 52+ wakeup_init(&eventwakeup);
 53+ button_register_handler(handler);
 54+
 55+ memset(lcdbuffer, 0xff, 320 * 240 * 2);
 56+ memset(norbuf, 0xff, 0x100000);
 57+ bootflash_readraw(norbuf, 0x1000, 0x1000);
 58+ if (norbufword[0] != 0x53436667)
 59+ {
 60+ cputs(1, "Boot flash contents are damaged! (No SYSCFG found)\n\nPlease ask for help.\n");
 61+ return;
 62+ }
 63+
 64+ rendertext(&lcdbuffer[320 * 10 + 10], 0, 0xffff, "Uninstaller v" VERSION " r" VERSION_SVN, 320);
 65+ rendertext(&lcdbuffer[320 * 26 + 10], 0, 0xffff, "To restore your iPod to factory state,", 320);
 66+ rendertext(&lcdbuffer[320 * 42 + 10], 0, 0xffff, "you need to first run this program and", 320);
 67+ rendertext(&lcdbuffer[320 * 50 + 10], 0, 0xffff, "then restore your iPod using iTunes.", 320);
 68+ rendertext(&lcdbuffer[320 * 74 + 10], 0, 0xffff, "Please note that after running this", 320);
 69+ rendertext(&lcdbuffer[320 * 82 + 10], 0, 0xffff, "program, the screen of your iPod will", 320);
 70+ rendertext(&lcdbuffer[320 * 90 + 10], 0, 0xffff, "power off, and it will appear to be", 320);
 71+ rendertext(&lcdbuffer[320 * 98 + 10], 0, 0xffff, "completely dead until it is restored", 320);
 72+ rendertext(&lcdbuffer[320 * 106 + 10], 0, 0xffff, "by iTunes. Even though the screen is", 320);
 73+ rendertext(&lcdbuffer[320 * 114 + 10], 0, 0xffff, "dark, your iPod will still be powered", 320);
 74+ rendertext(&lcdbuffer[320 * 122 + 10], 0, 0xffff, "on (and you can't power it off until", 320);
 75+ rendertext(&lcdbuffer[320 * 130 + 10], 0, 0xffff, "you restore) after this step, so the", 320);
 76+ rendertext(&lcdbuffer[320 * 138 + 10], 0, 0xffff, "battery will be discharging.", 320);
 77+ rendertext(&lcdbuffer[320 * 154 + 10], 0, 0xffff, "Press skip forward to continue", 320);
 78+ rendertext(&lcdbuffer[320 * 162 + 10], 0, 0xffff, "or skip backward to cancel.", 320);
 79+ displaylcd(0, 319, 0, 239, lcdbuffer, 0);
 80+ button = 0;
 81+ while (true)
 82+ {
 83+ wakeup_wait(&eventwakeup, TIMEOUT_BLOCK);
 84+ if (button == 2) break;
 85+ else if (button == 4)
 86+ {
 87+ shutdown(false);
 88+ reset();
 89+ }
 90+ button = 0;
 91+ }
 92+ rendertext(&lcdbuffer[320 * 178 + 10], 0, 0xffff, "Preparing...", 320);
 93+ displaylcd(0, 319, 0, 239, lcdbuffer, 0);
 94+ progressbar_init(&progressbar, 1, 318, 187, 194, 0, lcd_translate_color(0, 0xcf, 0xcf, 0xcf),
 95+ lcd_translate_color(0, 0, 0, 0xcf), 0, 256);
 96+ for (i = 0; i < 256; i++)
 97+ {
 98+ bootflash_writeraw(&norbuf[i * 0x1000], i * 0x1000, 0x1000);
 99+ progressbar_setpos(&progressbar, i, false);
 100+ }
 101+ rendertext(&lcdbuffer[320 * 194 + 10], 0, 0xffff, "Will enter DFU mode in 5 seconds...", 320);
 102+ displaylcd(0, 319, 0, 239, lcdbuffer, 0);
 103+ sleep(5000000);
 104+ backlight_on(false);
 105+ shutdown(true);
 106+ reset();
 107+}
Index: apps/uninstaller-classic/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.1"
 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: apps/uninstaller-classic/Makefile
@@ -0,0 +1,101 @@
 2+NAME := uninstaller-classic
 3+
 4+EMBIOSDIR ?= ../../embios/trunk/
 5+
 6+CROSS ?= arm-none-eabi-
 7+CC := $(CROSS)gcc
 8+AS := $(CROSS)as
 9+LD := $(CROSS)ld
 10+OBJCOPY := $(CROSS)objcopy
 11+UCLPACK := ucl2e10singleblk
 12+
 13+CFLAGS += -Os -fno-pie -fno-stack-protector -fomit-frame-pointer -I. -I$(EMBIOSDIR)/export -ffunction-sections -fdata-sections -mcpu=arm940t
 14+LDFLAGS += "$(shell $(CC) -print-libgcc-file-name)" --gc-sections
 15+
 16+preprocess = $(shell $(CC) $(PPCFLAGS) $(2) -E -P -x c $(1) | grep -v "^\#")
 17+preprocesspaths = $(shell $(CC) $(PPCFLAGS) $(2) -E -P -x c $(1) | grep -v "^\#" | sed -e "s:^..*:$(dir $(1))&:")
 18+
 19+REVISION := $(shell svnversion .)
 20+REVISIONINT := $(shell echo $(REVISION) | sed -e "s/[^0-9].*$$//")
 21+
 22+HELPERS := build/__embios_armhelpers.o
 23+
 24+SRC := $(call preprocesspaths,SOURCES,-I. -I..)
 25+OBJ := $(SRC:%.c=build/%.o)
 26+OBJ := $(OBJ:%.S=build/%.o) $(HELPERS)
 27+
 28+all: $(NAME)
 29+
 30+-include $(OBJ:%=%.dep)
 31+
 32+$(NAME): build/$(NAME).embiosapp.ucl
 33+
 34+build/$(NAME).embiosapp.ucl: build/$(NAME).embiosapp
 35+ @echo [UCL] $<
 36+ @$(UCLPACK) $^ $@
 37+
 38+build/$(NAME).embiosapp: build/$(NAME).elf
 39+ @echo [OC] $<
 40+ @$(OBJCOPY) -O binary $^ $@
 41+
 42+build/$(NAME).elf: ls.x $(OBJ)
 43+ @echo [LD] $@
 44+ @$(LD) $(LDFLAGS) -o $@ -T ls.x $(OBJ)
 45+
 46+build/%.o: %.c build/version.h
 47+ @echo [CC] $<
 48+ifeq ($(shell uname),WindowsNT)
 49+ @-if not exist $(subst /,\,$(dir $@)) md $(subst /,\,$(dir $@))
 50+else
 51+ @-mkdir -p $(dir $@)
 52+endif
 53+ @$(CC) -c $(CFLAGS) -o $@ $<
 54+ @$(CC) -MM $(CFLAGS) $< > $@.dep.tmp
 55+ @sed -e "s|.*:|$@:|" < $@.dep.tmp > $@.dep
 56+ifeq ($(shell uname),WindowsNT)
 57+ @sed -e "s/.*://" -e "s/\\$$//" < $@.dep.tmp | fmt -1 | sed -e "s/^ *//" -e "s/$$/:/" >> $@.dep
 58+else
 59+ @sed -e 's/.*://' -e 's/\\$$//' < $@.dep.tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $@.dep
 60+endif
 61+ @rm -f $@.dep.tmp
 62+
 63+build/%.o: %.S build/version.h
 64+ @echo [CC] $<
 65+ifeq ($(shell uname),WindowsNT)
 66+ @-if not exist $(subst /,\,$(dir $@)) md $(subst /,\,$(dir $@))
 67+else
 68+ @-mkdir -p $(dir $@)
 69+endif
 70+ @$(CC) -c $(CFLAGS) -o $@ $<
 71+ @$(CC) -MM $(CFLAGS) $< > $@.dep.tmp
 72+ @sed -e "s|.*:|$@:|" < $@.dep.tmp > $@.dep
 73+ifeq ($(shell uname),WindowsNT)
 74+ @sed -e "s/.*://" -e "s/\\$$//" < $@.dep.tmp | fmt -1 | sed -e "s/^ *//" -e "s/$$/:/" >> $@.dep
 75+else
 76+ @sed -e 's/.*://' -e 's/\\$$//' < $@.dep.tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $@.dep
 77+endif
 78+ @rm -f $@.dep.tmp
 79+
 80+build/__embios_%.o: $(EMBIOSDIR)/export/%.S
 81+ @echo [CC] $<
 82+ifeq ($(shell uname),WindowsNT)
 83+ @-if not exist $(subst /,\,$(dir $@)) md $(subst /,\,$(dir $@))
 84+else
 85+ @-mkdir -p $(dir $@)
 86+endif
 87+ @$(CC) -c $(CFLAGS) -o $@ $<
 88+
 89+build/version.h: version.h .svn/entries
 90+ @echo [PP] $<
 91+ifeq ($(shell uname),WindowsNT)
 92+ @-if not exist build md build
 93+ @sed -e "s/\$$REVISION\$$/$(REVISION)/" -e "s/\$$REVISIONINT\$$/$(REVISIONINT)/" < $< > $@
 94+else
 95+ @-mkdir -p build
 96+ @sed -e 's/\$$REVISION\$$/$(REVISION)/' -e 's/\$$REVISIONINT\$$/$(REVISIONINT)/' < $< > $@
 97+endif
 98+
 99+clean:
 100+ @rm -rf build
 101+
 102+.PHONY: all clean $(NAME)
Index: apps/uninstaller-classic
Property changes on: apps/uninstaller-classic
___________________________________________________________________
Added: svn:ignore
## -0,0 +1 ##
 103+build
Index: apps/installer-classic/flashfiles/iloader.conf
@@ -18,18 +18,12 @@
1919 menu(nothememenu, 0, 0xffffffff, 0xfffffffe, 0xffffffff, 0xfffffffe, 0)
2020
2121 nothememenu:
22 - .menuentry(" Enter disk mode \0", 16, 64, 0x0000, 0xffff, 0xffff, 0x001f, diskmode)
23 - .menuentry(" Run UMSboot \0", 16, 72, 0x0000, 0xffff, 0xffff, 0x001f, umsboot)
24 - .menuentry(" Quit iLoader \0", 16, 80, 0x0000, 0xffff, 0xffff, 0x001f, quit)
25 - .menuentry(" Power off \0", 16, 88, 0x0000, 0xffff, 0xffff, 0x001f, off)
 22+ .menuentry(" Uninstall iLoader \0", 16, 56, 0x0000, 0xffff, 0xffff, 0x001f, uninstall)
 23+ .menuentry(" Run UMSboot \0", 16, 64, 0x0000, 0xffff, 0xffff, 0x001f, umsboot)
 24+ .menuentry(" Quit iLoader \0", 16, 72, 0x0000, 0xffff, 0xffff, 0x001f, quit)
 25+ .menuentry(" Power off \0", 16, 80, 0x0000, 0xffff, 0xffff, 0x001f, off)
2626 .word(0)
2727
28 -diskmode:
29 - readflash(0x08000000, "diskmode")
30 - sleep(200000)
31 - backlight(1, 55, 10)
32 - exec(0x08000000)
33 -
3428 umsboot:
3529 readflash(0x08000000, "umsboot ")
3630 backlight(1, 55, 10)
@@ -38,5 +32,9 @@
3933 quit:
4034 terminate()
4135
 36+uninstall:
 37+ readflash(0x08000000, "uninst ")
 38+ execembiosapp(0x08000000, 1)
 39+
4240 off:
4341 poweroff()
Index: apps/installer-classic/tools/geninstaller.py
@@ -32,10 +32,12 @@
3333 flashfiles = [("ildrcfg ", 2, 0, 0, "iloader.cfg.ucl"), \
3434 ("iloader ", 2, 0, 0, "iloader.embiosapp.ucl"), \
3535 ("umsboot ", 2, 0, 0, "umsboot-ipodclassic.ucl"), \
 36+ ("uninst ", 2, 0, 0, "uninstaller-classic.embiosapp.ucl"), \
3637 ("embiosldr", 12, 8, 0, "embiosldr-ipodclassic.bin"), \
3738 ("embios ", 2, 0, 0, "embios-ipodclassic.ucl")]
3839
39 -firstinstfiles = [(2, "/iLoader/iLoader.cfg", "../iloader/themes/ipodclassic-default/iLoader/iloader.cfg", 1), \
 40+firstinstfiles = [(1, "/iLoader", 1), \
 41+ (2, "/iLoader/iLoader.cfg", "../iloader/themes/ipodclassic-default/iLoader/iloader.cfg", 1), \
4042 (2, "/iLoader/theme.ucl", "../iloader/themes/ipodclassic-default/iLoader/theme.ucl", 2)]
4143
4244 commonfiles = [(2, "/iLoader/NORFlash.bak", -2, 10)]
@@ -54,13 +56,13 @@
5557 file = open(sys.argv[1], "rb")
5658 installer = file.read()
5759 file.close()
58 -installer = installer.ljust((len(installer) + 3) & ~3)
 60+installer = installer.ljust((len(installer) + 3) & ~3, '\0')
5961
6062 for f in bitmaps:
6163 file = open("build/" + f, "rb")
6264 fdata = file.read()
6365 file.close()
64 - fdata = fdata.ljust((len(fdata) + 3) & ~3)
 66+ fdata = fdata.ljust((len(fdata) + 3) & ~3, '\0')
6567 installer = installer + struct.pack("<I", len(fdata)) + fdata
6668
6769 statusfirst = 0
@@ -91,7 +93,7 @@
9294 fdata = file.read()
9395 file.close()
9496 flash = flash + struct.pack("<II", scriptsize + len(filedata), len(fdata))
95 - filedata = filedata + fdata.ljust((len(fdata) + 15) & ~15)
 97+ filedata = filedata + fdata.ljust((len(fdata) + 15) & ~15, '\0')
9698 if (f[1] & 4) == 0: flash = flash + f[0]
9799
98100 firstinstall = ""
@@ -98,7 +100,7 @@
99101 for f in firstinstfiles:
100102 size = 0
101103 nameptr = scriptsize + len(filedata)
102 - filedata = filedata + (f[1] + "\0").ljust((len(f[1]) + 16) & ~15)
 104+ filedata = filedata + (f[1] + "\0").ljust((len(f[1]) + 16) & ~15, '\0')
103105 if f[0] == 1:
104106 firstinstall = firstinstall + struct.pack("<III", f[0], nameptr, f[2])
105107 statusfirst = statusfirst + f[2]
@@ -109,7 +111,7 @@
110112 file.close()
111113 ptr = scriptsize + len(filedata)
112114 size = len(fdata)
113 - filedata = filedata + fdata.ljust((len(fdata) + 15) & ~15)
 115+ filedata = filedata + fdata.ljust((len(fdata) + 15) & ~15, '\0')
114116 else:
115117 ptr = f[2]
116118 firstinstall = firstinstall + struct.pack("<IIiII", f[0], nameptr, ptr, size, f[3])
@@ -119,7 +121,7 @@
120122 for f in commonfiles:
121123 size = 0
122124 nameptr = scriptsize + len(filedata)
123 - filedata = filedata + (f[1] + "\0").ljust((len(f[1]) + 16) & ~15)
 125+ filedata = filedata + (f[1] + "\0").ljust((len(f[1]) + 16) & ~15, '\0')
124126 if f[0] == 1:
125127 common = common + struct.pack("<III", f[0], nameptr, f[2])
126128 statuscommon = statuscommon + f[2]
@@ -130,7 +132,7 @@
131133 file.close()
132134 ptr = scriptsize + len(filedata)
133135 size = len(fdata)
134 - filedata = filedata + fdata.ljust((len(fdata) + 15) & ~15)
 136+ filedata = filedata + fdata.ljust((len(fdata) + 15) & ~15, '\0')
135137 else:
136138 ptr = f[2]
137139 common = common + struct.pack("<IIiII", f[0], nameptr, ptr, size, f[3])
@@ -140,5 +142,5 @@
141143 statusfirst, statusfirst + statuscommon) \
142144 + firstinstall + common + struct.pack("<I", 0)
143145 file = open(sys.argv[2], "wb")
144 -file.write(installer + script.ljust(scriptsize) + filedata)
 146+file.write(installer + script.ljust(scriptsize, '\0') + filedata)
145147 file.close()
Index: apps/installer-classic/oobe/warning.bmp
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: apps/installer-classic/oobe/oobe.psd
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: apps/installer-classic/Makefile
@@ -2,12 +2,13 @@
33
44 EMBIOSDIR ?= ../../embios/trunk/
55 ILOADERDIR ?= ../iloader/
 6+UNINSTDIR ?= ../uninstaller-classic/
67 UMSBOOTDIR ?= ../../umsboot/
78 TOOLSDIR ?= ../../tools/
89
910 BITMAPS = build/sidepane.ucl build/warning.ucl build/installing.ucl build/formatting.ucl build/copying.ucl build/flashing.ucl
1011
11 -FLASHFILES = flashfiles/iloader.cfg.ucl flashfiles/iloader.embiosapp.ucl \
 12+FLASHFILES = flashfiles/uninstaller-classic.embiosapp.ucl flashfiles/iloader.cfg.ucl flashfiles/iloader.embiosapp.ucl \
1213 flashfiles/embiosldr-ipodclassic.bin flashfiles/embios-ipodclassic.ucl flashfiles/umsboot-ipodclassic.ucl
1314
1415 CROSS ?= arm-none-eabi-
@@ -145,6 +146,12 @@
146147 flashfiles: $(FLASHFILES)
147148 @touch flashfiles.built
148149
 150+$(UNINSTDIR)/build/uninstaller-classic.embiosapp.ucl: uninstaller-classic
 151+
 152+flashfiles/uninstaller-classic.embiosapp.ucl: $(UNINSTDIR)/build/uninstaller-classic.embiosapp.ucl uninstaller-classic
 153+ @echo [CP] $@
 154+ @cp $< $@
 155+
149156 $(UMSBOOTDIR)/build/ipodclassic/umsboot-ipodclassic.ucl: umsboot
150157
151158 flashfiles/umsboot-ipodclassic.ucl: $(UMSBOOTDIR)/build/ipodclassic/umsboot-ipodclassic.ucl umsboot
@@ -191,6 +198,9 @@
192199 iloader:
193200 @make -C $(ILOADERDIR)
194201
 202+uninstaller-classic:
 203+ @make -C $(UNINSTDIR)
 204+
195205 $(UMSBOOTDIR)/build/ipodclassic/umsboot.bin: umsboot
196206
197207 umsboot:
@@ -199,4 +209,4 @@
200210 clean:
201211 @rm -rf build
202212
203 -.PHONY: all clean iloader embios embiosldr-ipodclassic umsboot libucl flashfiles $(NAME)
 213+.PHONY: all clean uninstaller-classic iloader embios embiosldr-ipodclassic umsboot libucl flashfiles $(NAME)