···134134 will override "Default kernel command string".135135 Say N if you are unsure.136136137137+config NIOS2_BOOT_LINK_OFFSET138138+ hex "Link address offset for booting"139139+ default "0x00500000"140140+ help141141+ This option allows you to set the link address offset of the zImage.142142+ This can be useful if you are on a board which has a small amount of143143+ memory.144144+137145endmenu138146139147menu "Advanced setup"
+7
arch/nios2/boot/Makefile
···2424 $(call if_changed,uimage)2525 @$(kecho) 'Kernel: $@ is ready'26262727+$(obj)/zImage: $(obj)/compressed/vmlinux FORCE2828+ $(call if_changed,objcopy)2929+ @$(kecho) 'Kernel: $@ is ready'3030+3131+$(obj)/compressed/vmlinux: $(obj)/vmlinux.gz FORCE3232+ $(Q)$(MAKE) $(build)=$(obj)/compressed $@3333+2734# Rule to build device tree blobs2835DTB_SRC := $(patsubst "%",%,$(CONFIG_NIOS2_DTB_SOURCE))2936
···11+/*22+ * Copyright (C) 2008-2010 Thomas Chou <thomas@wytron.com.tw>33+ *44+ * This program is free software; you can redistribute it and/or modify55+ * it under the terms of the GNU General Public License as published by66+ * the Free Software Foundation; either version 2 of the License, or77+ * (at your option) any later version.88+ *99+ * This program is distributed in the hope that it will be useful,1010+ * but WITHOUT ANY WARRANTY; without even the implied warranty of1111+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1212+ * GNU General Public License for more details.1313+ *1414+ * You should have received a copy of the GNU General Public License1515+ * along with this program. If not, see <http://www.gnu.org/licenses/>.1616+ *1717+ */1818+1919+#include <linux/io.h>2020+2121+#if (defined(CONFIG_SERIAL_ALTERA_JTAGUART_CONSOLE) && defined(JTAG_UART_BASE))\2222+ || (defined(CONFIG_SERIAL_ALTERA_UART_CONSOLE) && defined(UART0_BASE))2323+static void *my_ioremap(unsigned long physaddr)2424+{2525+ return (void *)(physaddr | CONFIG_NIOS2_IO_REGION_BASE);2626+}2727+#endif2828+2929+#if defined(CONFIG_SERIAL_ALTERA_JTAGUART_CONSOLE) && defined(JTAG_UART_BASE)3030+3131+#define ALTERA_JTAGUART_SIZE 83232+#define ALTERA_JTAGUART_DATA_REG 03333+#define ALTERA_JTAGUART_CONTROL_REG 43434+#define ALTERA_JTAGUART_CONTROL_AC_MSK (0x00000400)3535+#define ALTERA_JTAGUART_CONTROL_WSPACE_MSK (0xFFFF0000)3636+static void *uartbase;3737+3838+#if defined(CONFIG_SERIAL_ALTERA_JTAGUART_CONSOLE_BYPASS)3939+static void jtag_putc(int ch)4040+{4141+ if (readl(uartbase + ALTERA_JTAGUART_CONTROL_REG) &4242+ ALTERA_JTAGUART_CONTROL_WSPACE_MSK)4343+ writeb(ch, uartbase + ALTERA_JTAGUART_DATA_REG);4444+}4545+#else4646+static void jtag_putc(int ch)4747+{4848+ while ((readl(uartbase + ALTERA_JTAGUART_CONTROL_REG) &4949+ ALTERA_JTAGUART_CONTROL_WSPACE_MSK) == 0)5050+ ;5151+ writeb(ch, uartbase + ALTERA_JTAGUART_DATA_REG);5252+}5353+#endif5454+5555+static int putchar(int ch)5656+{5757+ jtag_putc(ch);5858+ return ch;5959+}6060+6161+static void console_init(void)6262+{6363+ uartbase = my_ioremap((unsigned long) JTAG_UART_BASE);6464+ writel(ALTERA_JTAGUART_CONTROL_AC_MSK,6565+ uartbase + ALTERA_JTAGUART_CONTROL_REG);6666+}6767+6868+#elif defined(CONFIG_SERIAL_ALTERA_UART_CONSOLE) && defined(UART0_BASE)6969+7070+#define ALTERA_UART_SIZE 327171+#define ALTERA_UART_TXDATA_REG 47272+#define ALTERA_UART_STATUS_REG 87373+#define ALTERA_UART_DIVISOR_REG 167474+#define ALTERA_UART_STATUS_TRDY_MSK (0x40)7575+static unsigned uartbase;7676+7777+static void uart_putc(int ch)7878+{7979+ int i;8080+8181+ for (i = 0; (i < 0x10000); i++) {8282+ if (readw(uartbase + ALTERA_UART_STATUS_REG) &8383+ ALTERA_UART_STATUS_TRDY_MSK)8484+ break;8585+ }8686+ writeb(ch, uartbase + ALTERA_UART_TXDATA_REG);8787+}8888+8989+static int putchar(int ch)9090+{9191+ uart_putc(ch);9292+ if (ch == '\n')9393+ uart_putc('\r');9494+ return ch;9595+}9696+9797+static void console_init(void)9898+{9999+ unsigned int baud, baudclk;100100+101101+ uartbase = (unsigned long) my_ioremap((unsigned long) UART0_BASE);102102+ baud = CONFIG_SERIAL_ALTERA_UART_BAUDRATE;103103+ baudclk = UART0_FREQ / baud;104104+ writew(baudclk, uartbase + ALTERA_UART_DIVISOR_REG);105105+}106106+107107+#else108108+109109+static int putchar(int ch)110110+{111111+ return ch;112112+}113113+114114+static void console_init(void)115115+{116116+}117117+118118+#endif119119+120120+static int puts(const char *s)121121+{122122+ while (*s)123123+ putchar(*s++);124124+ return 0;125125+}
+117
arch/nios2/boot/compressed/head.S
···11+/*22+ * Copyright (C) 2009 Thomas Chou <thomas@wytron.com.tw>33+ *44+ * Based on arch/nios2/kernel/head.S55+ *66+ * This file is subject to the terms and conditions of the GNU General Public77+ * License. See the file "COPYING" in the main directory of this archive88+ * for more details.99+ *1010+ */1111+1212+/*1313+ * This code can be loaded anywhere, eg FLASH ROM as reset vector,1414+ * as long as output does not overlap it.1515+ */1616+1717+#include <linux/linkage.h>1818+#include <asm/cache.h>1919+2020+ .text2121+ .set noat2222+ENTRY(_start)2323+ wrctl status, r0 /* disable interrupt */2424+ /* invalidate all instruction cache */2525+ movia r1, NIOS2_ICACHE_SIZE2626+ movui r2, NIOS2_ICACHE_LINE_SIZE2727+1: initi r12828+ sub r1, r1, r22929+ bgt r1, r0, 1b3030+ /* invalidate all data cache */3131+ movia r1, NIOS2_DCACHE_SIZE3232+ movui r2, NIOS2_DCACHE_LINE_SIZE3333+1: initd 0(r1)3434+ sub r1, r1, r23535+ bgt r1, r0, 1b3636+3737+ nextpc r1 /* Find out where we are */3838+chkadr:3939+ movia r2, chkadr4040+ beq r1, r2, finish_move /* We are running in correct address,4141+ done */4242+ /* move code, r1: src, r2: dest, r3: last dest */4343+ addi r1, r1, (_start - chkadr) /* Source */4444+ movia r2, _start /* Destination */4545+ movia r3, __bss_start /* End of copy */4646+1: ldw r8, 0(r1) /* load a word from [r1] */4747+ stw r8, 0(r2) /* stort a word to dest [r2] */4848+ addi r1, r1, 4 /* inc the src addr */4949+ addi r2, r2, 4 /* inc the dest addr */5050+ blt r2, r3, 1b5151+ /* flush the data cache after moving */5252+ movia r1, NIOS2_DCACHE_SIZE5353+ movui r2, NIOS2_DCACHE_LINE_SIZE5454+1: flushd 0(r1)5555+ sub r1, r1, r25656+ bgt r1, r0, 1b5757+ movia r1, finish_move5858+ jmp r1 /* jmp to linked address */5959+6060+finish_move:6161+ /* zero out the .bss segment (uninitialized common data) */6262+ movia r2, __bss_start /* presume nothing is between */6363+ movia r1, _end /* the .bss and _end. */6464+1: stb r0, 0(r2)6565+ addi r2, r2, 16666+ bne r1, r2, 1b6767+ /*6868+ * set up the stack pointer, some where higher than _end.6969+ * The stack space must be greater than 32K for decompress.7070+ */7171+ movia sp, 0x100007272+ add sp, sp, r17373+ /* save args passed from u-boot, maybe */7474+ addi sp, sp, -167575+ stw r4, 0(sp)7676+ stw r5, 4(sp)7777+ stw r6, 8(sp)7878+ stw r7, 12(sp)7979+ /* decompress the kernel */8080+ call decompress_kernel8181+ /* pass saved args to kernel */8282+ ldw r4, 0(sp)8383+ ldw r5, 4(sp)8484+ ldw r6, 8(sp)8585+ ldw r7, 12(sp)8686+8787+ /* flush all data cache after decompressing */8888+ movia r1, NIOS2_DCACHE_SIZE8989+ movui r2, NIOS2_DCACHE_LINE_SIZE9090+1: flushd 0(r1)9191+ sub r1, r1, r29292+ bgt r1, r0, 1b9393+ /* flush all instruction cache */9494+ movia r1, NIOS2_ICACHE_SIZE9595+ movui r2, NIOS2_ICACHE_LINE_SIZE9696+1: flushi r19797+ sub r1, r1, r29898+ bgt r1, r0, 1b9999+ flushp100100+ /* jump to start real kernel */101101+ movia r1, (CONFIG_NIOS2_MEM_BASE | CONFIG_NIOS2_KERNEL_REGION_BASE)102102+ jmp r1103103+104104+ .balign 512105105+fake_headers_as_bzImage:106106+ .short 0107107+ .ascii "HdrS"108108+ .short 0x0202109109+ .short 0110110+ .short 0111111+ .byte 0x00, 0x10112112+ .short 0113113+ .byte 0114114+ .byte 1115115+ .byte 0x00, 0x80116116+ .long 0117117+ .long 0
+187
arch/nios2/boot/compressed/misc.c
···11+/*22+ * Copyright (C) 2009 Thomas Chou <thomas@wytron.com.tw>33+ *44+ * This is a collection of several routines from gzip-1.0.355+ * adapted for Linux.66+ *77+ * malloc by Hannu Savolainen 1993 and Matthias Urlichs 199488+ *99+ * Adapted for SH by Stuart Menefy, Aug 19991010+ *1111+ * Modified to use standard LinuxSH BIOS by Greg Banks 7Jul20001212+ *1313+ * Based on arch/sh/boot/compressed/misc.c1414+ *1515+ * This program is free software; you can redistribute it and/or modify1616+ * it under the terms of the GNU General Public License as published by1717+ * the Free Software Foundation; either version 2 of the License, or1818+ * (at your option) any later version.1919+ *2020+ * This program is distributed in the hope that it will be useful,2121+ * but WITHOUT ANY WARRANTY; without even the implied warranty of2222+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the2323+ * GNU General Public License for more details.2424+ *2525+ * You should have received a copy of the GNU General Public License2626+ * along with this program. If not, see <http://www.gnu.org/licenses/>.2727+ *2828+ */2929+3030+#include <linux/string.h>3131+3232+/*3333+ * gzip declarations3434+ */3535+#define OF(args) args3636+#define STATIC static3737+3838+#undef memset3939+#undef memcpy4040+#define memzero(s, n) memset((s), 0, (n))4141+4242+typedef unsigned char uch;4343+typedef unsigned short ush;4444+typedef unsigned long ulg;4545+#define WSIZE 0x8000 /* Window size must be at least 32k, */4646+ /* and a power of two */4747+4848+static uch *inbuf; /* input buffer */4949+static uch window[WSIZE]; /* Sliding window buffer */5050+5151+static unsigned insize; /* valid bytes in inbuf */5252+static unsigned inptr; /* index of next byte to be processed in inbuf */5353+static unsigned outcnt; /* bytes in output buffer */5454+5555+/* gzip flag byte */5656+#define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */5757+#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip5858+ file */5959+#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */6060+#define ORIG_NAME 0x08 /* bit 3 set: original file name present */6161+#define COMMENT 0x10 /* bit 4 set: file comment present */6262+#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */6363+#define RESERVED 0xC0 /* bit 6,7: reserved */6464+6565+#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())6666+6767+#ifdef DEBUG6868+# define Assert(cond, msg) {if (!(cond)) error(msg); }6969+# define Trace(x) fprintf x7070+# define Tracev(x) {if (verbose) fprintf x ; }7171+# define Tracevv(x) {if (verbose > 1) fprintf x ; }7272+# define Tracec(c, x) {if (verbose && (c)) fprintf x ; }7373+# define Tracecv(c, x) {if (verbose > 1 && (c)) fprintf x ; }7474+#else7575+# define Assert(cond, msg)7676+# define Trace(x)7777+# define Tracev(x)7878+# define Tracevv(x)7979+# define Tracec(c, x)8080+# define Tracecv(c, x)8181+#endif8282+static int fill_inbuf(void);8383+static void flush_window(void);8484+static void error(char *m);8585+8686+extern char input_data[];8787+extern int input_len;8888+8989+static long bytes_out;9090+static uch *output_data;9191+static unsigned long output_ptr;9292+9393+#include "console.c"9494+9595+static void error(char *m);9696+9797+int puts(const char *);9898+9999+extern int _end;100100+static unsigned long free_mem_ptr;101101+static unsigned long free_mem_end_ptr;102102+103103+#define HEAP_SIZE 0x10000104104+105105+#include "../../../../lib/inflate.c"106106+107107+void *memset(void *s, int c, size_t n)108108+{109109+ int i;110110+ char *ss = (char *)s;111111+112112+ for (i = 0; i < n; i++)113113+ ss[i] = c;114114+ return s;115115+}116116+117117+void *memcpy(void *__dest, __const void *__src, size_t __n)118118+{119119+ int i;120120+ char *d = (char *)__dest, *s = (char *)__src;121121+122122+ for (i = 0; i < __n; i++)123123+ d[i] = s[i];124124+ return __dest;125125+}126126+127127+/*128128+ * Fill the input buffer. This is called only when the buffer is empty129129+ * and at least one byte is really needed.130130+ */131131+static int fill_inbuf(void)132132+{133133+ if (insize != 0)134134+ error("ran out of input data");135135+136136+ inbuf = input_data;137137+ insize = input_len;138138+ inptr = 1;139139+ return inbuf[0];140140+}141141+142142+/*143143+ * Write the output window window[0..outcnt-1] and update crc and bytes_out.144144+ * (Used for the decompressed data only.)145145+ */146146+static void flush_window(void)147147+{148148+ ulg c = crc; /* temporary variable */149149+ unsigned n;150150+ uch *in, *out, ch;151151+152152+ in = window;153153+ out = &output_data[output_ptr];154154+ for (n = 0; n < outcnt; n++) {155155+ ch = *out++ = *in++;156156+ c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);157157+ }158158+ crc = c;159159+ bytes_out += (ulg)outcnt;160160+ output_ptr += (ulg)outcnt;161161+ outcnt = 0;162162+}163163+164164+static void error(char *x)165165+{166166+ puts("\nERROR\n");167167+ puts(x);168168+ puts("\n\n -- System halted");169169+170170+ while (1) /* Halt */171171+ ;172172+}173173+174174+void decompress_kernel(void)175175+{176176+ output_data = (void *) (CONFIG_NIOS2_MEM_BASE |177177+ CONFIG_NIOS2_KERNEL_REGION_BASE);178178+ output_ptr = 0;179179+ free_mem_ptr = (unsigned long)&_end;180180+ free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;181181+182182+ console_init();183183+ makecrc();184184+ puts("Uncompressing Linux... ");185185+ gunzip();186186+ puts("Ok, booting the kernel.\n");187187+}
+58
arch/nios2/boot/compressed/vmlinux.lds.S
···11+/*22+ * Copyright (C) 2009 Thomas Chou <thomas@wytron.com.tw>33+ *44+ * This program is free software; you can redistribute it and/or modify55+ * it under the terms of the GNU General Public License as published by66+ * the Free Software Foundation; either version 2 of the License, or77+ * (at your option) any later version.88+ *99+ * This program is distributed in the hope that it will be useful,1010+ * but WITHOUT ANY WARRANTY; without even the implied warranty of1111+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1212+ * GNU General Public License for more details.1313+ *1414+ * You should have received a copy of the GNU General Public License1515+ * along with this program. If not, see <http://www.gnu.org/licenses/>.1616+ *1717+ */1818+1919+#include <asm-generic/vmlinux.lds.h>2020+2121+OUTPUT_FORMAT("elf32-littlenios2", "elf32-littlenios2", "elf32-littlenios2")2222+2323+OUTPUT_ARCH(nios)2424+ENTRY(_start) /* Defined in head.S */2525+2626+SECTIONS2727+{2828+ . = (CONFIG_NIOS2_MEM_BASE + CONFIG_NIOS2_BOOT_LINK_OFFSET) | \2929+ CONFIG_NIOS2_KERNEL_REGION_BASE;3030+3131+ _text = .;3232+ .text : { *(.text) } = 03333+ .rodata : { *(.rodata) *(.rodata.*) }3434+ _etext = .;3535+3636+ . = ALIGN(32 / 8);3737+ .data : { *(.data) }3838+ . = ALIGN(32 / 8);3939+ _got = .;4040+ .got : {4141+ *(.got.plt)4242+ *(.igot.plt)4343+ *(.got)4444+ *(.igot)4545+ }4646+ _egot = .;4747+ _edata = .;4848+4949+ . = ALIGN(32 / 8);5050+ __bss_start = .;5151+ .bss : { *(.bss) *(.sbss) }5252+ . = ALIGN(32 / 8);5353+ _ebss = .;5454+ end = . ;5555+ _end = . ;5656+5757+ got_len = (_egot - _got);5858+}
+28
arch/nios2/boot/compressed/vmlinux.scr
···11+/*22+ * Copyright (C) 2009 Thomas Chou <thomas@wytron.com.tw>33+ *44+ * This program is free software; you can redistribute it and/or modify55+ * it under the terms of the GNU General Public License as published by66+ * the Free Software Foundation; either version 2 of the License, or77+ * (at your option) any later version.88+ *99+ * This program is distributed in the hope that it will be useful,1010+ * but WITHOUT ANY WARRANTY; without even the implied warranty of1111+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1212+ * GNU General Public License for more details.1313+ *1414+ * You should have received a copy of the GNU General Public License1515+ * along with this program. If not, see <http://www.gnu.org/licenses/>.1616+ *1717+ */1818+1919+SECTIONS2020+{2121+ .data : {2222+ input_len = .;2323+ LONG(input_data_end - input_data) input_data = .;2424+ *(.data)2525+ . = ALIGN(4);2626+ input_data_end = .;2727+ }2828+}