diff --git a/bin/dmesg_filter.exe b/bin/dmesg_filter.exe new file mode 100644 index 0000000..e3f13e4 Binary files /dev/null and b/bin/dmesg_filter.exe differ diff --git a/compile b/compile index e7b40c5..d2c258f 100644 --- a/compile +++ b/compile @@ -1,55 +1,45 @@ #!/bin/bash #use codesourcery toolchain -TOOLCHAIN_PREFIX=arm-none-eabi- +TOOLCHAIN_PREFIX="arm-none-eabi-" export TOOLCHAIN_PREFIX if [ "$1" = "clean" ]; then - rm -rf lk/build-htcleo - rm bin/nbfix - rm bin/lk.bin - rm bin/tinboot - rm tinboot/tinboot - rm tinboot/tinboot.o - rm bin/os.nb.payload - rm bin/os.nb - rm bin/RUU_signed.nbh + cd lk + make htcleo clean + cd .. + rm bin/nbfix fi +rm bin/lk.bin +rm bin/tinboot +rm bin/os.nb.payload +rm bin/os.nb +rm bin/RUU_signed.nbh + -TOOLCHAIN_PREFIX="arm-none-eabi-" -export TOOLCHAIN_PREFIX if [ ! -f bin/nbfix ]; then gcc nbfix.c -o bin/nbfix fi -if [ ! -f bin/lk.bin ]; then - cd lk - make htcleo EMMC_BOOT=0 DEBUG=1 - [ $? -eq 0 ] || exit 1 - cp build-htcleo/lk.bin ../bin/ - cd .. -fi - -if [ ! -f bin/tinboot ]; then - cd tinboot - ${TOOLCHAIN_PREFIX}as tinboot.S -o tinboot.o - ${TOOLCHAIN_PREFIX}objcopy tinboot.o -O binary tinboot - cp tinboot ../bin/ - cd .. -fi - -if [ ! -f bin/RUU_signed.nbh ]; then - cd bin - cp template_os.nb.payload os.nb.payload - wine osnbtool.exe -c os.nb.payload 0 tinboot - mv os.nb.payload.NEW os.nb.payload - ./nbfix - wine NBMerge.exe -kaiser os.nb - wine yang.exe -F RUU_signed.nbh -f os.nb -t 0x400 -s 64 -d PB8110000 -c 11111111 -v CLK1.1 -l WWE - - cd .. -fi +cd lk +make htcleo DEBUG=1 +[ $? -eq 0 ] || exit 1 +cp build-htcleo/lk.bin ../bin/ +cp build-htcleo/tinboot ../bin/ +cd .. + + + +cd bin +cp template_os.nb.payload os.nb.payload +wine osnbtool.exe -c os.nb.payload 0 tinboot +mv os.nb.payload.NEW os.nb.payload +./nbfix +wine NBMerge.exe -kaiser os.nb +wine yang.exe -F RUU_signed.nbh -f os.nb -t 0x400 -s 64 -d PB8110000 -c 11111111 -v CLK1.1 -l WWE +cd .. + diff --git a/dmesg_filter.c b/dmesg_filter.c new file mode 100644 index 0000000..71e5e77 --- /dev/null +++ b/dmesg_filter.c @@ -0,0 +1,24 @@ +#include +#include + +int main() { + char buff[0x40000]; + + char* ptr = buff; + while(!feof(stdin) && fgetc(stdin)!='\n'); + + while(!feof(stdin)) + { + *ptr++=fgetc(stdin);*ptr=0; + + if(ptr-buff>=5 && memcmp(ptr-5,"\nINFO",5)==0) + { + ptr[-5]=0; + if(ptr-buff>=6 && ptr[-6]=='\r' ) ptr[-6]=0; + printf("%s", buff); + ptr=buff; + + } + } + printf("%s", buff); +} diff --git a/gau_flash.cfg b/gau_flash.cfg new file mode 100644 index 0000000..feadaff --- /dev/null +++ b/gau_flash.cfg @@ -0,0 +1,4 @@ +clk_recovery raw|ro 5M +clk_boot raw|ro 5M +system ya|boot|ro filesize system.bin +userdata ya|asize allsize \ No newline at end of file diff --git a/lk/app/aboot/aboot.c b/lk/app/aboot/aboot.c index 0835fe1..cba83c6 100644 --- a/lk/app/aboot/aboot.c +++ b/lk/app/aboot/aboot.c @@ -61,7 +61,9 @@ #define FASTBOOT_MODE 0x77665500 static const char *emmc_cmdline = " androidboot.emmc=true"; -static const char *battchg_pause = " androidboot.battchg_pause=true"; +//static const char *battchg_pause = " androidboot.battchg_pause=true"; +static const char *battchg_pause = " androidboot.mode=offmode_charging"; + static struct udc_device surf_udc_device = { .vendor_id = 0x18d1, @@ -199,37 +201,15 @@ void boot_linux(void *kernel, unsigned *tags, dprintf(INFO, "cmdline: %s\n", cmdline); enter_critical_section(); - //cedesmith: this will hang - //platform_uninit_timer(); + platform_uninit_timer(); arch_disable_cache(UCACHE); arch_disable_mmu(); #if DISPLAY_SPLASH_SCREEN display_shutdown(); #endif - __asm__ volatile ( - "dsb \n" - "isb \n" - ); - - //cedesmith: cotulla's code so kernel will not crash. aux control register - __asm__ volatile ( - "MRC p15, 0, r0, c1, c0, 1 \n" - "BIC r0, r0, #0x40 \n" // (1<<6) Instruction cache reload on a parity error disabled - "BIC r0, r0, #0x200000 \n" // (1<<21) undocumented bit ? - "MCR p15, 0, r0, c1, c0, 1 \n" - ); - - /* - // flash on to see we get here - __asm__ volatile ( - "ldr r4, =0xa9000864 @ bank6_in (phys) \n" - "ldr r5, =0xa9000814 @ bank6_out (phys) \n" - "orr r6, r4, #0x200000 @ 22nd bit for flash \n" - "str r6, [r5, #0] @ store in out (enables bright for 500ms, limited by hardware) \n" - ); - */ - entry(0, machtype, tags); + htcleo_boot(kernel, machtype, tags); + //entry(0, machtype, tags); } unsigned page_size = 0; diff --git a/lk/app/aboot/fastboot.c b/lk/app/aboot/fastboot.c index 6752dde..0e0bde6 100644 --- a/lk/app/aboot/fastboot.c +++ b/lk/app/aboot/fastboot.c @@ -232,6 +232,19 @@ static void cmd_getvar(const char *arg, void *data, unsigned sz) { struct fastboot_var *var; + if(!strcmp(arg,"dmesg")) + { + char response[64]; + for(char* c=(char*) 0x2FFC0000; c<(char*)(0x2FFC0000+0x00040000); c+=59) + { + memcpy(response, "INFO",4);memcpy(response+4, c, 59); response[63]=0; + //snprintf(response, 64, "%s%s", "INFO", c); + usb_write(response, 64); + } + fastboot_okay(""); + return; + } + for (var = varlist; var; var = var->next) { if (!strcmp(var->name, arg)) { fastboot_okay(var->value); diff --git a/lk/platform/msm_shared/timer.c b/lk/platform/msm_shared/timer.c index 9f98ffa..c264bc1 100644 --- a/lk/platform/msm_shared/timer.c +++ b/lk/platform/msm_shared/timer.c @@ -159,7 +159,8 @@ void platform_init_timer(void) static void wait_for_timer_op(void) { -#if PLATFORM_QSD8K || PLATFORM_MSM7X30 || PLATFORM_MSM8X60 + //cedesmith: this will hang on htcleo so removed PLATFORM_QSD8K +#if PLATFORM_MSM7X30 || PLATFORM_MSM8X60 while(readl(SPSS_TIMER_STATUS)) ; #endif } diff --git a/lk/platform/qsd8k/rules.mk b/lk/platform/qsd8k/rules.mk index e49e05d..88ddd40 100644 --- a/lk/platform/qsd8k/rules.mk +++ b/lk/platform/qsd8k/rules.mk @@ -6,7 +6,7 @@ ARM_CPU := cortex-a8 CPU := generic #DEFINES += WITH_CPU_EARLY_INIT=1 WITH_CPU_WARM_BOOT=1 MEMBASE=0 -DEFINES += WITH_CPU_EARLY_INIT=1 +#DEFINES += WITH_CPU_EARLY_INIT=1 INCLUDES += -I$(LOCAL_DIR)/include diff --git a/lk/target/htcleo/atags.c b/lk/target/htcleo/atags.c index 2c87b94..9d8adae 100644 --- a/lk/target/htcleo/atags.c +++ b/lk/target/htcleo/atags.c @@ -8,10 +8,21 @@ unsigned* target_atag_mem(unsigned* ptr) { + + //MEM TAG *ptr++ = 4; *ptr++ = 0x54410002; - *ptr++ = MSM_EBI1_BANK0_SIZE; - *ptr++ = MSM_EBI1_BANK0_BASE; + //*ptr++ = 0x1e400000; //mem size from haret + //*ptr++ = 0x1E7C0000; //mem size from kernel config + *ptr++ = 0x1CFC0000; //mem size from kernel config with bravo dsp + *ptr++ = 0x11800000; //mem base + + + //add atag to notify nand boot + *ptr++ = 4; + *ptr++ = 0x4C47414D; + *ptr++ = 0; + *ptr++ = 0; return ptr; } diff --git a/lk/target/htcleo/htcleo_boot.c b/lk/target/htcleo/htcleo_boot.c new file mode 100644 index 0000000..96564ea --- /dev/null +++ b/lk/target/htcleo/htcleo_boot.c @@ -0,0 +1,30 @@ +#include +#include + +// cedesmith: we need to stop interrupts or kernel will receive dex interrupt to early and crash +#define VIC_REG(off) (MSM_VIC_BASE + (off)) +#define VIC_INT_EN0 VIC_REG(0x0010) +#define VIC_INT_EN1 VIC_REG(0x0014) +#define VIC_INT_CLEAR0 VIC_REG(0x00B0) +#define VIC_INT_CLEAR1 VIC_REG(0x00B4) +#define VIC_INT_MASTEREN VIC_REG(0x0068) /* 1: IRQ, 2: FIQ */ + +void htcleo_disable_interrupts(void) +{ + //clear current pending interrupts + writel(0xffffffff, VIC_INT_CLEAR0); + writel(0xffffffff, VIC_INT_CLEAR1); + + //disable all + writel(0, VIC_INT_EN0); + writel(0, VIC_INT_EN1); + //disable interrupts + writel(0, VIC_INT_MASTEREN); +} + +void htcleo_boot_s(void* kernel,unsigned machtype,void* tags); +void htcleo_boot(void* kernel,unsigned machtype,void* tags) +{ + htcleo_disable_interrupts(); + htcleo_boot_s(kernel, machtype, tags); +} diff --git a/lk/target/htcleo/htcleo_boot_s.S b/lk/target/htcleo/htcleo_boot_s.S new file mode 100644 index 0000000..1469898 --- /dev/null +++ b/lk/target/htcleo/htcleo_boot_s.S @@ -0,0 +1,24 @@ +.text +.code 32 + +.globl htcleo_boot_s +htcleo_boot_s: + // save registers + MOV r9, r0 + + //cedesmith: cotulla's code so kernel will not crash. aux control register + MRC p15, 0, r0, c1, c0, 1 + BIC r0, r0, #0x40 // (1<<6) Instruction cache reload on a parity error disabled + BIC r0, r0, #0x200000 // (1<<21) undocumented bit ? + MCR p15, 0, r0, c1, c0, 1 + + //flashlight to see we get here + //ldr r4, =0xa9000864 @ bank6_in (phys) + //ldr r5, =0xa9000814 @ bank6_out (phys) + //orr r6, r4, #0x200000 @ 22nd bit for flash + //str r6, [r5, #0] @ store in out (enables bright for 500ms, limited by hardware) + + MOV R0, #0 + BLX R9 + +.ltorg diff --git a/lk/target/htcleo/init.c b/lk/target/htcleo/init.c index 606529c..1a66f7a 100644 --- a/lk/target/htcleo/init.c +++ b/lk/target/htcleo/init.c @@ -9,6 +9,9 @@ #include #include #include +#include +#include +#include #define LINUX_MACHTYPE 2524 #define HTCLEO_FLASH_OFFSET 0x219 @@ -43,30 +46,31 @@ static struct ptentry board_part_list[MAX_PTABLE_PARTS] __attribute__ ((aligned }, }; #else -// partition table matching cotulla's build +// partition table matching gau desire hd on my (cedesmith) phone +// allows me to just swap bootloader from magldr to clk and viceversa static struct ptentry board_part_list[MAX_PTABLE_PARTS] __attribute__ ((aligned (512))) = { { .name = "PTABLE-BLK", // or PTABLE-MB for len in MB }, { - .name = "boot", + .name = "recovery", .start = 0x219, - .length = 0x25 /* In blocks */, + .length = 0x28 /* In blocks */, + }, + { + .name = "boot", + .start = 0x241, + .length = 0x28 /* In blocks */, }, { .name = "system", - .start = 0x23E, - .length = 0x831 /* In blocks */, - }, - { - .name = "cache", - .start = 0xA70, - .length = 0x140 /* In blocks */, + .start = 0x269, + .length = 0x68B /* In blocks */, }, { .name = "userdata", - .start = 0xBB0, - .length = 0x390, + .start = 0x8F4, + .length = 0x64C, }, }; #endif @@ -81,6 +85,7 @@ void htcleo_ptable_dump(struct ptable *ptable); void cmd_dmesg(const char *arg, void *data, unsigned sz); void reboot(unsigned reboot_reason); void target_display_init(); +unsigned get_boot_reason(void); void target_init(void) { struct flash_info *flash_info; @@ -88,27 +93,27 @@ void target_init(void) unsigned blocks_per_plen = 1; //blocks per partition length unsigned nand_num_blocks; + keys_init(); keypad_init(); + + uint16_t keys[] = {KEY_VOLUMEUP, KEY_VOLUMEDOWN, KEY_SOFT1, KEY_SEND, KEY_CLEAR, KEY_BACK, KEY_HOME}; for(unsigned i=0; i< sizeof(keys)/sizeof(uint16_t); i++) if (keys_get_state(keys[i]) != 0) { display_init(); _dputs("cedesmith's LK (CLK) v1.1\n"); + dprintf(ALWAYS,"key %d pressed\n", i); break; } dprintf(INFO, "htcleo_init\n"); - // SPL seams to pass something somehow to kernel. - // Without this it hangs on 1st boot and when battery charger is pluged - // with this it just auto restarts - char* cold_boot=(char*)(MEMBASE-1); - if(*cold_boot==0) + // When boot mode is 1 it hangs + if(/*get_boot_reason()==1 ||*/ get_boot_reason()==2) { - *cold_boot=1; - dprintf(INFO, "cold boot detected... reboot\n"); + dprintf(INFO, "reboot needed... \n"); reboot(0); } @@ -181,6 +186,22 @@ void reboot_device(unsigned reboot_reason) reboot(reboot_reason); } +unsigned boot_reason = 0xFFFFFFFF; +unsigned get_boot_reason(void) +{ + if(boot_reason==0xFFFFFFFF) + { + boot_reason = readl(MSM_SHARED_BASE+0xef244); + dprintf(INFO, "boot reason %x\n", boot_reason); + } + return boot_reason; +} +unsigned target_pause_for_battery_charge(void) +{ + if (get_boot_reason() == 2) return 1; + return 0; +} + int target_is_emmc_boot(void) { return 0; diff --git a/lk/target/htcleo/keypad.c b/lk/target/htcleo/keypad.c index a402c3a..5127ca9 100644 --- a/lk/target/htcleo/keypad.c +++ b/lk/target/htcleo/keypad.c @@ -34,25 +34,16 @@ #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0])) - -/* Keypad */ -#define HTCLEO_GPIO_KP_MKOUT0 33 -#define HTCLEO_GPIO_KP_MKOUT1 32 -#define HTCLEO_GPIO_KP_MKOUT2 31 -#define HTCLEO_GPIO_KP_MPIN0 42 -#define HTCLEO_GPIO_KP_MPIN1 41 -#define HTCLEO_GPIO_KP_MPIN2 40 - /* * cedesmith - * NOTE: htcleo kernel differs by havin row swaped to col + * NOTE: htcleo kernel differs by having row swapped to col */ -static unsigned int halibut_row_gpios[] = { 33, 32, 31 }; -static unsigned int halibut_col_gpios[] = { 42, 41, 40 }; +static unsigned int htcleo_row_gpios[] = { 33, 32, 31 }; +static unsigned int htcleo_col_gpios[] = { 42, 41, 40 }; -#define KEYMAP_INDEX(row, col) ((row)*ARRAY_SIZE(halibut_col_gpios) + (col)) +#define KEYMAP_INDEX(row, col) ((row)*ARRAY_SIZE(htcleo_col_gpios) + (col)) -static const unsigned short halibut_keymap[ARRAY_SIZE(halibut_col_gpios) * ARRAY_SIZE(halibut_row_gpios)] = { +static const unsigned short htcleo_keymap[ARRAY_SIZE(htcleo_col_gpios) * ARRAY_SIZE(htcleo_row_gpios)] = { [KEYMAP_INDEX(0, 0)] = KEY_VOLUMEUP, // Volume Up [KEYMAP_INDEX(0, 1)] = KEY_VOLUMEDOWN, // Volume Down [KEYMAP_INDEX(1, 0)] = KEY_SOFT1, // Windows Button @@ -63,11 +54,11 @@ static const unsigned short halibut_keymap[ARRAY_SIZE(halibut_col_gpios) * ARRAY }; static struct gpio_keypad_info halibut_keypad_info = { - .keymap = halibut_keymap, - .output_gpios = halibut_row_gpios, - .input_gpios = halibut_col_gpios, - .noutputs = ARRAY_SIZE(halibut_row_gpios), - .ninputs = ARRAY_SIZE(halibut_col_gpios), + .keymap = htcleo_keymap, + .output_gpios = htcleo_row_gpios, + .input_gpios = htcleo_col_gpios, + .noutputs = ARRAY_SIZE(htcleo_row_gpios), + .ninputs = ARRAY_SIZE(htcleo_col_gpios), .settle_time = 40 /* msec */, .poll_time = 20 /* msec */, .flags = GPIOKPF_DRIVE_INACTIVE, diff --git a/lk/target/htcleo/nand.c b/lk/target/htcleo/nand.c index 9baef2e..15b529a 100644 --- a/lk/target/htcleo/nand.c +++ b/lk/target/htcleo/nand.c @@ -33,8 +33,7 @@ #include #include #include -//#include -#include "nand.h" +#include #include "dmov.h" diff --git a/lk/target/htcleo/rules.mk b/lk/target/htcleo/rules.mk index caf4bda..fbf8d21 100644 --- a/lk/target/htcleo/rules.mk +++ b/lk/target/htcleo/rules.mk @@ -33,7 +33,7 @@ KEYS_USE_GPIO_KEYPAD := 1 #DEFINES += DISPLAY_SPLASH_SCREEN=1 DEFINES += DISPLAY_TYPE_LCDC=1 -CFLAGS += -mlittle-endian +CFLAGS += -mlittle-endian -mfpu=neon LDFLAGS += -EL MODULES += \ @@ -53,3 +53,6 @@ OBJS += \ $(LOCAL_DIR)/nand.o \ $(LOCAL_DIR)/keypad.o \ $(LOCAL_DIR)/atags.o + +OBJS += $(LOCAL_DIR)/htcleo_boot.o \ + $(LOCAL_DIR)/htcleo_boot_s.o \ No newline at end of file diff --git a/lk/target/htcleo/tools/makefile b/lk/target/htcleo/tools/makefile index 9d3897d..21d4a35 100644 --- a/lk/target/htcleo/tools/makefile +++ b/lk/target/htcleo/tools/makefile @@ -1,30 +1,17 @@ -#Makefile to generate appsboot.mbn - -ifeq ($(BOOTLOADER_OUT),.) -APPSBOOTHEADER_DIR := $(BUILDDIR) -else -APPSBOOTHEADER_DIR := $(BOOTLOADER_OUT)/../../ -endif +#Makefile to generate tinboot SRC_DIR := target/$(TARGET)/tools -COMPILER := gcc +EXTRA_CLEANDEPS += tinboot_clean -ifeq ($(BUILD_NANDWRITE), 1) - APPSBOOTHDR_FILES := -else - APPSBOOTHDR_FILES := appsboot.mbn -endif +APPSBOOTHEADER: $(BUILDDIR)/tinboot -APPSBOOTHEADER: $(APPSBOOTHDR_FILES) +$(BUILDDIR)/tinboot.o: $(SRC_DIR)/tinboot.S $(OUTBIN) + $(TOOLCHAIN_PREFIX)as $(SRC_DIR)/tinboot.S -I "$(BUILDDIR)" -o $(BUILDDIR)/tinboot.o + +$(BUILDDIR)/tinboot: $(BUILDDIR)/tinboot.o + $(OBJCOPY) $(BUILDDIR)/tinboot.o -O binary $(BUILDDIR)/tinboot -appsboot.mbn: appsboothd.mbn $(OUTBIN) - cat $(APPSBOOTHEADER_DIR)/appsboothd.mbn $(OUTBIN) > $(APPSBOOTHEADER_DIR)/appsboot.mbn - rm -rf $(APPSBOOTHEADER_DIR)/appsboothd.mbn - -appsboothd.mbn: mkheader $(OUTBIN) - $(SRC_DIR)/mkheader $(OUTBIN) $(APPSBOOTHEADER_DIR)/appsboothd.mbn - -mkheader: $(SRC_DIR)/mkheader.c - ${COMPILER} $(SRC_DIR)/mkheader.c -o $(SRC_DIR)/mkheader - + +tinboot_clean: + rm -f $(BUILDDIR)/tinboot.o $(BUILDDIR)/tinboot \ No newline at end of file diff --git a/lk/target/htcleo/tools/tinboot.S b/lk/target/htcleo/tools/tinboot.S new file mode 100644 index 0000000..3a39552 --- /dev/null +++ b/lk/target/htcleo/tools/tinboot.S @@ -0,0 +1,44 @@ +@ author: cedesmith +@ license: GPL +@ version 1.0 +@ tiny bootloader wrapper for HTC WM6 phones +@ inspired by Martin Johnson Tinboot for htc vogue + + .org 0 + b boot + + .org 0x40 + .word 0x43454345 + .word romhdr+0x80000000 @ location of wince romhdr + .word romhdr + + + .org 0x00000900 + romhdr: @ 23E6F0 in original rom file + .word 0x0 @ dllfirst FD 01 F9 01 + .word 0x0 @ dlllast 00 00 00 02 + .word 0x80000000 @ physfirst 00 00 00 80 + .word 0x80000000+fin+0x100 @ physlast 48 B4 4D 80 + .word 0 @ nummods 29 00 00 00 + .word 0x80000000+fin+0x200 @ ulRAMStart 00 C0 4D 80 + .word 0x80000000+fin+0x300 @ ulRAMFree 00 B0 5C 80 + .word 0x8E600000 @ ulRAMEnd 00 00 60 8E + .word 0 @ ulCopyEntries 07 00 00 00 + .word 0x80000000+fin+0x400 @ ulCopyOffset DC 24 24 80 + .word 0 @ ulProfileLen 00 00 00 00 + .word 0 @ ulProfileOffset 00 00 00 00 + .word 0 @ numfiles 0E 00 00 00 + .word 0 @ ulKernelFlags 02 00 00 00 + .word 0x04 @ ulFSRamPercent 04 00 00 00 + .word 0 @ ulDrivglobStart 00 00 00 00 + .word 0 @ ulDrivglobLen 00 00 00 00 + .word 0x201c2 @ usCPUType and usMiscFlags (2 shorts) + .word 0x80000000+fin+0x500 @ pExtensions EC 2A 00 80 + .word 0 @ ulTrackingStart 00 00 00 00 + .word 0 @ ulTrackingLen 00 00 00 00 + + .org 0x00001000 +boot: + .incbin "lk.bin" + +fin: diff --git a/readme_boot.img.txt b/readme_boot.img.txt index 678ec95..e492d5a 100644 --- a/readme_boot.img.txt +++ b/readme_boot.img.txt @@ -1,2 +1,2 @@ #make ARCH=arm CROSS_COMPILE=arm-none-eabi- -mkbootimg --kernel zImage --ramdisk initrd.gz --cmdline "console=null" --base 0x11800000 -o android_boot.img +mkbootimg --kernel zImage --ramdisk initrd.gz --cmdline "" --base 0x11800000 -o android_boot.img