Changeset 12310


Ignore:
Timestamp:
06/17/09 22:22:05 (4 years ago)
Author:
BrainSlayer
Message:

use printf rather than puts (includes printf implementation), add nvram functions to check system variables, this allows to boot always redboot if configured from dd-wrt itself

Location:
ar5315_microredboot/microredboot/boot/src
Files:
5 added
4 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • ar5315_microredboot/microredboot/boot/src/Makefile

    r12303 r12310  
    2727LD = /xfs/toolchains/staging_dir_mips/bin/mips-linux-ld 
    2828OBJCOPY = /xfs/toolchains/staging_dir_mips/bin/mips-linux-objcopy  
    29 CFLAGS = -Os -G 0 -mabi=32 -mno-abicalls -fno-pic -pipe -msoft-float -ffreestanding -march=mips32 -Iinclude -Iinclude/asm-mips/mach-atheros -Iinclude/asm/mach-generic -DMIPSEB -D_MIPSEB -D__MIPSEB -D__MIPSEB__ -U_MIPS_ISA -D_MIPS_ISA=_MIPS_ISA_MIPS32 -D__KERNEL__ 
     29CFLAGS = -Os -G 0 -mabi=32 -mno-abicalls -fno-pic -pipe -msoft-float -ffreestanding -march=mips32 -Iinclude -I. -Iinclude/asm-mips/mach-atheros -Iinclude/asm/mach-generic -DMIPSEB -D_MIPSEB -D__MIPSEB -D__MIPSEB__ -U_MIPS_ISA -D_MIPS_ISA=_MIPS_ISA_MIPS32 -D__KERNEL__ 
    3030CFLAGS+= -DCONFIG_MIPS_L1_CACHE_SHIFT=5 -DCONFIG_PAGE_SIZE_4KB -DCONFIG_32BIT -DCONFIG_BOOTLOADER 
    3131AFLAGS = -Os -D__ASSEMBLY__ -G 0 -mabi=32 -mno-abicalls -fno-pic -pipe -msoft-float -ffreestanding -march=mips32 -Iinclude -Iinclude/asm-mips/mach-atheros -Iinclude/asm/mach-generic -DMIPSEB -D_MIPSEB -D__MIPSEB -D__MIPSEB__ -U_MIPS_ISA -D_MIPS_ISA=_MIPS_ISA_MIPS32 
     
    4646 
    4747HEAD             = head.o 
    48 OBJS             = misc_lzma.o 
     48OBJS             = misc_lzma.o lib/lib.o lib/print.o lib/printf.o 
    4949MEMCPY           = memcpy.o memset.o 
    5050# CFLAGS         = $(CPPFLAGS) -O2 -DSTDC_HEADERS $(CFLAGS_BOOT) 
  • ar5315_microredboot/microredboot/boot/src/head-ar5315.S

    r12281 r12310  
    11/* 
    2  * lzma_misc.c 
     2 * head-ar5315.S 
    33 * originally written for xscale based linux kernel decompression 
    44 * now adapted for AR531X based redboot stub and kernel loader 
  • ar5315_microredboot/microredboot/boot/src/head-ar531x.S

    r12281 r12310  
    11/* 
    2  *  linux/arch/mips/boot/compressed/head-ar531x.S 
     2 *  head-ar531x.S 
    33 * 
     4 *  Copyright (C) 2009 NewMedia-NET GmbH (derived from linux boot code) 
    45 *  Copyright (C) 2003 Instant802 Networks, Inc. 
    56 *  Copyright (C) 2001 Atheros Communications, Inc.,  All Rights Reserved. 
    67 * 
    7  *  License:  
     8 *  originally written for xscale based linux kernel decompression 
     9 *  now adapted for AR531X based redboot stub and kernel loader 
     10 *  copyright 2009 Sebastian Gottschall / NewMedia-NET GmbH / DD-WRT.COM 
     11 *  licensed under GPL conditions 
     12 *  based on Vxworks sources from Atheros Communications, Inc. 
     13 * 
     14 * 
     15 *  License: GPL 
    816 */ 
    917 
     
    2432#include "mips4Kx.h" 
    2533#include "ar531xreg.h" 
     34#include "ar531xSio.h" 
    2635 
    2736/* 
     
    217226 
    218227        /* Want this fairly early in output file */ 
    219         .asciz "Copyright 2009 DD-WRT.COM" 
     228        .asciz "MicroRedBoot Copyright 2009 NewMedia-NET GmbH / DD-WRT.COM" 
    220229        .align 4 
    221230 
     
    627636        mtc0    zero, CP0_COMPARE 
    628637 
     638        li      a0, KSEG1|AR531X_RESET 
     639        lw      t0, 0(a0) 
     640        and     t0, ~RESET_APB 
     641        or      t0, RESET_UART0 
     642        sw      t0, 0(a0) 
     643        lw      zero, 0(a0)             # flush 
     644 
     645        and     t0, ~RESET_UART0 
     646        sw      t0, 0(a0) 
     647        lw      zero, 0(a0)             # flush 
     648 
     6491:      /* Use internal clocking */ 
     650        li      a0, KSEG1|AR531X_CLOCKCTL 
     651        lw      t0, 0(a0) 
     652        and     t0, ~CLOCKCTL_UART0 
     653        sw      t0, 0(a0) 
     654 
     655        /* put UART CLOCK RATE into a0 */ 
     656        li      a0, KSEG1|AR5312_SCRATCH 
     657        lw      a0, 0(a0) 
     658        bnez    a0, 3f                  # CPU Clock freq specified? 
     659        li      a0, 180000000           # No: assume 180MHz 
     6603:      srl     a0, 2                   # derive UART freq 
     661        div     a0, 115200 
     662        div     a0, 16 
     663        srl     t2, a0, 8 
     664        andi    t1, a0, 0xff            # AR531X_NS16550_DLL_VALUE 
     665        andi    t2, 0xff                # AR531X_NS16550_DLM_VALUE 
     666         
     6672: 
     668 
     669        /* Init UART @ 115200 baud */ 
     670        li      a0, KSEG1|AR531X_UART0 
     671        li      t0, LCR_DLAB            # access divisor latch 
     672        sw      t0, LCR<<2(a0) 
     673        sw      t1, DLL<<2(a0)          # divisor low 
     674        sw      t2, DLM<<2(a0)          # divisor high 
     675        li      t0, CHAR_LEN_8          # 8b mode 
     676        sw      t0, LCR<<2(a0) 
     677        sw      zero, IER<<2(a0)        # disable interrupts 
     678        li      t0, FCR_EN|FCR_RXCLR|FCR_TXCLR 
     679 
     680        sw      t0, FCR<<2(a0)          # reset and enable fifos 
     681 
     682 
     683 
    629684        /* Set watchpoint for low memory to debug null pointers */ 
    630685        li      t0, 0x40000ff8          # G + Ignore 11:3 in check 
     
    661716        bal     romCacheInit            # init/invalidate cache tags 
    662717 
     718        nop 
     719        la      t0,_text               # dest addr 
     720#       la      t1,_text          # source addr 
     721#       lar     t1,__AR531X_start 
     722        la      t1,_text-0x80400000+BOOTBASE          # source addr 
     723        la      t3,_text+0x10000       # end dest addr 
     7243:       
     725        lw      v0,0(t1)                # get word 
     726        sw      v0,0(t0)                # write word 
     727        addiu   t1,t1,4 
     728        addiu   t0,t0,4 
     729        bne     t0,t3,3b 
     730        nop 
     731        la      v0,4f                   # RAM address to go to 
     732        jr      v0 
     733        nop 
     7344:        
     735        nop 
     736 
    663737        /* Want to switch to cached segment now... */ 
    664738 
     
    721795        nop 
    722796        bal     ramCacheInit            # init/invalidate cache tags 
     797        nop 
     798 
     799        la      t0,_text               # dest addr 
     800#       la      t1,_text          # source addr 
     801#       lar     t1,__AR531X_start 
     802        la      t1,_text-0x80400000+BOOTBASE          # source addr 
     803        la      t3,_text+0x10000       # end dest addr 
     8043:       
     805        lw      v0,0(t1)                # get word 
     806        sw      v0,0(t0)                # write word 
     807        addiu   t1,t1,4 
     808        addiu   t0,t0,4 
     809        bne     t0,t3,3b 
     810        nop 
     811        la      v0,4f                   # RAM address to go to 
     812        jr      v0 
     813        nop 
     8144:        
    723815        nop 
    724816 
  • ar5315_microredboot/microredboot/boot/src/head.S

    r12281 r12310  
    6868 
    6969        /* Jump to the kernel's entry point */ 
    70         la      t1, bootoffset 
     70        la      t1, bootoffset   
    7171        nop 
    7272        lw      t0, 0(t1) 
  • ar5315_microredboot/microredboot/boot/src/misc_lzma.c

    r12303 r12310  
    6666 * Do the lzma decompression 
    6767 */ 
    68  
    69 static void print_hex(int val) 
    70 { 
    71         static char *xlate = "0123456789abcdef"; 
    72         int i; 
    73  
    74         puts("0x"); 
    75  
    76         for (i = 28; i >= 0; i -= 4) { 
    77                 putc(xlate[(val >> i) & 0xf]); 
    78         } 
    79 } 
    8068 
    8169static int disaster = 0; 
     
    10694                if (disaster) { 
    10795                        error 
    108                             ("\r\ndata corrupted in recovery RedBoot too, this is a disaster condition. please re-jtag\r\n"); 
     96                            ("\ndata corrupted in recovery RedBoot too, this is a disaster condition. please re-jtag\n"); 
    10997                } 
    11098                disaster = 1; 
    111                 puts("\r\ndata corrupted!\r\nswitching to recovery RedBoot\r\nloading"); 
     99                puts("\ndata corrupted!\nswitching to recovery RedBoot\nloading"); 
    112100                inbuf = input_data; 
    113101                insize = &input_data_end[0] - &input_data[0]; 
     
    129117                        if (disaster) { 
    130118                                error 
    131                                     ("data corrupted in recovery RedBoot too, this is a disaster condition. please re-jtag\r\n"); 
     119                                    ("data corrupted in recovery RedBoot too, this is a disaster condition. please re-jtag\n"); 
    132120                        } 
    133121                        disaster = 1; 
    134                         puts("\r\ndata corrupted!\r\nswitching to recovery RedBoot\r\nloading"); 
     122                        puts("\ndata corrupted!\nswitching to recovery RedBoot\nloading"); 
    135123                        inbuf = input_data; 
    136124                        insize = &input_data_end[0] - &input_data[0]; 
     
    168156        *buffer = &val; 
    169157        if (icnt++ % (1024 * 10) == 0) 
    170                 puts("."); 
     158                putc('.'); 
    171159        return LZMA_RESULT_OK; 
    172160} 
     
    201189                    || !strncmp(fis->name, "vmlinux", 7) 
    202190                    || !strcmp(fis->name, "kernel")) { 
    203                         puts("found bootable image: "); 
    204                         puts(fis->name); 
    205                         puts(" at "); 
    206                         print_hex(fis->flash_base); 
    207                         puts(" entrypoint "); 
    208                         print_hex(fis->entry_point); 
    209                         puts("\r\n"); 
     191                        printf 
     192                            ("found bootable image: [%s] at [0x%08X] EP [0x%08X]\n", 
     193                             fis->name, fis->flash_base, fis->entry_point); 
    210194                        bootoffset = fis->entry_point; 
    211195                        output_data = (uch *) fis->mem_base; 
     
    219203                count++; 
    220204        } 
    221         puts("no bootable image found, try default location 0xbfc10000\r\n"); 
     205        puts("no bootable image found, try default location 0xbfc10000\n"); 
    222206        bootoffset = 0x80041000; 
    223207        output_data = (uch *) 0x80041000; 
     
    260244        arch_error(x); 
    261245 
    262         puts("\r\n\r\n"); 
    263         puts(x); 
    264         puts("\r\n\r\n -- System halted"); 
     246        printf("\n\n%s\n\n -- System halted", x); 
    265247 
    266248        while (1) ;             /* Halt */ 
     
    336318 
    337319/* 
    338  *  
     320 * udelay implementation based on cpu cycle counter 
    339321 */ 
    340322static void udelay(int us) 
     
    498480        __u32 cs_addrmask; 
    499481} static flashconfig_tbl[MAX_FLASH] = { 
    500         { 
    501          0, 0, 0, 0}, { 
    502                        STM_1MB_BYTE_COUNT, STM_1MB_SECTOR_COUNT, 
    503                        STM_1MB_SECTOR_SIZE, 0x0}, 
    504         { 
    505          STM_2MB_BYTE_COUNT, STM_2MB_SECTOR_COUNT, STM_2MB_SECTOR_SIZE, 0x0}, 
    506         { 
    507          STM_4MB_BYTE_COUNT, STM_4MB_SECTOR_COUNT, STM_4MB_SECTOR_SIZE, 0x0}, 
    508         { 
    509          STM_8MB_BYTE_COUNT, STM_8MB_SECTOR_COUNT, STM_8MB_SECTOR_SIZE, 0x0}, 
    510         { 
    511          STM_16MB_BYTE_COUNT, STM_16MB_SECTOR_COUNT, 
    512          STM_16MB_SECTOR_SIZE, 0x0} 
     482        {0, 0, 0, 0}, // 
     483        {STM_1MB_BYTE_COUNT, STM_1MB_SECTOR_COUNT,STM_1MB_SECTOR_SIZE, 0x0},// 
     484        {STM_2MB_BYTE_COUNT, STM_2MB_SECTOR_COUNT, STM_2MB_SECTOR_SIZE, 0x0},// 
     485        {STM_4MB_BYTE_COUNT, STM_4MB_SECTOR_COUNT, STM_4MB_SECTOR_SIZE, 0x0},// 
     486        {STM_8MB_BYTE_COUNT, STM_8MB_SECTOR_COUNT, STM_8MB_SECTOR_SIZE, 0x0},// 
     487        {STM_16MB_BYTE_COUNT, STM_16MB_SECTOR_COUNT,STM_16MB_SECTOR_SIZE, 0x0}// 
    513488}; 
    514489 
     
    518493        __s8 rx_cnt; 
    519494} static stm_opcodes[] = { 
    520         { 
    521          STM_OP_WR_ENABLE, 1, 0}, { 
    522                                    STM_OP_WR_DISABLE, 1, 0}, { 
    523                                                               STM_OP_RD_STATUS, 
    524                                                               1, 1}, { 
    525                                                                       STM_OP_WR_STATUS, 
    526                                                                       1, 0}, { 
    527                                                                               STM_OP_RD_DATA, 
    528                                                                               4, 
    529                                                                               4}, 
    530         { 
    531          STM_OP_FAST_RD_DATA, 5, 0}, { 
    532                                       STM_OP_PAGE_PGRM, 8, 0}, { 
    533                                                                 STM_OP_SECTOR_ERASE, 
    534                                                                 4, 0}, { 
    535                                                                         STM_OP_BULK_ERASE, 
    536                                                                         1, 0}, { 
    537                                                                                 STM_OP_DEEP_PWRDOWN, 
    538                                                                                 1, 
    539                                                                                 0}, 
    540         { 
    541          STM_OP_RD_SIG, 4, 1}, 
     495        {STM_OP_WR_ENABLE, 1, 0},       // 
     496        {STM_OP_WR_DISABLE, 1, 0},      // 
     497        {STM_OP_RD_STATUS, 1, 1},       // 
     498        {STM_OP_WR_STATUS, 1, 0},       // 
     499        {STM_OP_RD_DATA, 4, 4}, // 
     500        {STM_OP_FAST_RD_DATA, 5, 0},    // 
     501        {STM_OP_PAGE_PGRM, 8, 0},       // 
     502        {STM_OP_SECTOR_ERASE, 4, 0},    // 
     503        {STM_OP_BULK_ERASE, 1, 0},      // 
     504        {STM_OP_DEEP_PWRDOWN, 1, 0},    // 
     505        {STM_OP_RD_SIG, 4, 1},  // 
    542506}; 
    543507 
     
    634598                break; 
    635599        default: 
    636                 puts("Read of flash device signature failed!\r\n"); 
     600                puts("Read of flash device signature failed!\n"); 
    637601                return (0); 
    638602        } 
     
    647611        struct opcodes *ptr_opcode; 
    648612        __u32 temp, reg; 
    649         puts("erasing nvram at "); 
    650         print_hex(flashbase + offset); 
    651         puts("\r\n"); 
     613        printf("erasing nvram at [0x%08X]\n", flashbase + offset); 
    652614 
    653615        ptr_opcode = &stm_opcodes[SPI_SECTOR_ERASE]; 
     
    666628        busy_wait(spiflash_sendcmd(SPI_RD_STATUS, 0) & SPI_STATUS_WIP, 20); 
    667629 
    668         puts("done\r\n"); 
     630        puts("done\n"); 
    669631        return 0; 
    670632} 
    671633 
     634static int flashdetected = 0; 
    672635static int flashdetect(void) 
    673636{ 
     637        if (flashdetected) 
     638                return 0; 
    674639        flashsize = 8 * 1024 * 1024; 
    675640        flashbase = 0xa8000000; 
    676641        int index = 0; 
    677642        if (!(index = spiflash_probe_chip())) { 
    678                 puts("Found no serial flash device, cannot reset to factory defaults\r\n"); 
     643                puts("Found no serial flash device, cannot reset to factory defaults\n"); 
    679644                return -1; 
    680645        } else { 
    681646                flashsize = flashconfig_tbl[index].byte_cnt; 
    682647                sectorsize = flashconfig_tbl[index].sector_size; 
    683                 puts("Found Flash device SIZE="); 
    684                 print_hex(flashsize); 
    685                 puts(" SECTORSIZE="); 
    686                 print_hex(sectorsize); 
    687                 puts(" FLASHBASE="); 
    688648                if (flashsize == 8 * 1024 * 1024) 
    689649                        flashbase = 0xa8000000; 
    690650                else 
    691651                        flashbase = 0xbfc00000; 
    692                 print_hex(flashbase); 
    693                 puts("\r\n"); 
    694         } 
     652                printf 
     653                    ("Found Flash device SIZE=0x%08X SECTORSIZE=0x%08X FLASHBASE=0x%08X\n", 
     654                     flashsize, sectorsize, flashbase); 
     655        } 
     656        flashdetected = 1; 
    695657        return 0; 
    696658 
     659} 
     660 
     661struct nvram_header { 
     662        __u32 magic; 
     663        __u32 len; 
     664        __u32 crc_ver_init;     /* 0:7 crc, 8:15 ver, 16:27 init, mem. test 28, 29-31 reserved */ 
     665        __u32 config_refresh;   /* 0:15 config, 16:31 refresh */ 
     666        __u32 config_ncdl;      /* ncdl values for memc */ 
     667}; 
     668 
     669struct nvram_tuple { 
     670        char *name; 
     671        char *value; 
     672        struct nvram_tuple *next; 
     673}; 
     674 
     675#define NVRAM_SPACE 0x10000 
     676#define NVRAM_MAGIC                     0x48534C46      /* 'NVFL' */ 
     677 
     678static char nvram_buf[65536] __attribute__((aligned(4096))) = {0};// 
     679 
     680/* 
     681 * simple dd-wrt nvram implementation (read only) 
     682 */ 
     683static void nvram_init(void) 
     684{ 
     685        struct nvram_header *header; 
     686        __u32 off, lim; 
     687        int i; 
     688        flashdetect(); 
     689 
     690        header = 
     691            (struct nvram_header *)(flashbase + flashsize - (sectorsize * 3)); 
     692        if (header->magic == NVRAM_MAGIC && header->len > 0 
     693            && header->len <= NVRAM_SPACE) { 
     694                printf("DD-WRT nvram with size = %d found\n", header->len); 
     695                memcpy(nvram_buf, header, NVRAM_SPACE); 
     696        } 
     697} 
     698 
     699static char *nvram_get(const char *name) 
     700{ 
     701        char *var, *value, *end, *eq; 
     702 
     703        if (!name) 
     704                return NULL; 
     705 
     706        if (!nvram_buf[0]) 
     707                nvram_init(); 
     708 
     709        /* Look for name=value and return value */ 
     710        var = &nvram_buf[sizeof(struct nvram_header)]; 
     711        end = nvram_buf + sizeof(nvram_buf) - 2; 
     712        end[0] = end[1] = '\0'; 
     713        for (; *var; var = value + strlen(value) + 1) { 
     714                if (!(eq = strchr(var, '='))) 
     715                        break; 
     716                value = eq + 1; 
     717                if ((eq - var) == strlen(name) 
     718                    && strncmp(var, name, (eq - var)) == 0) 
     719                        return value; 
     720        } 
     721 
     722        return NULL; 
    697723} 
    698724 
     
    705731 
    706732        arch_decomp_setup(); 
    707  
    708         puts("MicroRedBoot v1.2, (c) 2009 DD-WRT.COM ("); 
    709         puts(__DATE__); 
    710         puts(")\r\n"); 
    711         if (resetTouched()) { 
    712                 puts("Reset Button triggered\r\nBooting Recovery RedBoot\r\n"); 
     733        printf("MicroRedBoot v1.2, (c) 2009 DD-WRT.COM (%s)\n", __DATE__); 
     734        nvram_init(); 
     735        char *resetbutton = nvram_get("resetbutton_enable"); 
     736        if (resetTouched() || (resetbutton && !strcmp(resetbutton, "1"))) { 
     737                puts("Reset Button triggered\nBooting Recovery RedBoot\n"); 
    713738                int count = 5; 
    714739                while (count--) { 
     
    718743                } 
    719744                if (count <= 0) { 
    720                         puts("reset button 5 seconds pushed, erasing nvram\r\n"); 
     745                        puts("reset button 5 seconds pushed, erasing nvram\n"); 
    721746                        if (!flashdetect()) 
    722747                                flash_erase_nvram(flashsize, sectorsize); 
     
    728753                flashdetect(); 
    729754                linuxaddr = getLinux(); 
    730                 puts("Booting Linux\r\n"); 
     755                puts("Booting Linux\n"); 
    731756                resettrigger = 1; 
    732757                /* initialize clock */ 
     
    759784        puts("loading"); 
    760785        lzma_unzip(); 
    761         puts("\r\n\r\n\r\n"); 
     786        puts("\n\n\n"); 
    762787 
    763788        return output_ptr; 
  • ar5315_microredboot/microredboot/boot/src/uncompress-ar531x.h

    r12281 r12310  
    7676 
    7777        while ((c = *s++)) { 
     78                if (c=='\n') 
     79                    putc('\r'); 
    7880                putc(c); 
    7981        } 
Note: See TracChangeset for help on using the changeset viewer.