{"id":300,"date":"2018-03-13T13:44:10","date_gmt":"2018-03-13T05:44:10","guid":{"rendered":"http:\/\/www.max-shu.com\/blog\/?p=300"},"modified":"2018-03-13T13:44:10","modified_gmt":"2018-03-13T05:44:10","slug":"mini6410%e6%9d%bfuboot%e7%9a%84board-c","status":"publish","type":"post","link":"http:\/\/www.max-shu.com\/blog\/?p=300","title":{"rendered":"mini6410\u677fuboot\u7684Board.c"},"content":{"rendered":"<div>\/*<br \/>\n* To match the U-Boot user interface on ARM platforms to the U-Boot<br \/>\n* standard (as on PPC platforms), some messages with debug character<br \/>\n* are removed from the default U-Boot build.<br \/>\n*<br \/>\n* Define DEBUG here if you want additional info as shown below<br \/>\n* printed upon startup:<br \/>\n*<br \/>\n* U-Boot code: 00F00000 -&gt; 00F3C774\u00a0 BSS: -&gt; 00FC3274<br \/>\n* IRQ Stack: 00ebff7c<br \/>\n* FIQ Stack: 00ebef7c<br \/>\n*\/<\/p>\n<p>#include &lt;common.h&gt;<br \/>\n#include &lt;command.h&gt;<br \/>\n#include &lt;malloc.h&gt;<br \/>\n#include &lt;devices.h&gt;<br \/>\n#include &lt;version.h&gt;<br \/>\n#include &lt;net.h&gt;<br \/>\n#include &lt;asm\/io.h&gt;<\/p>\n<p>#if defined(CONFIG_BOOT_MOVINAND)<br \/>\n#include &lt;movi.h&gt;<br \/>\n#endif<\/p>\n<p>#ifdef CONFIG_DRIVER_SMC91111<br \/>\n#include &#8220;..\/drivers\/smc91111.h&#8221;<br \/>\n#endif<br \/>\n#ifdef CONFIG_DRIVER_LAN91C96<br \/>\n#include &#8220;..\/drivers\/lan91c96.h&#8221;<br \/>\n#endif<\/p>\n<p>\/* Note: volatile register variable is *NOT* volatile in gcc 4.5.1+ *\/<br \/>\n#if\u00a0\u00a0\u00a0\u00a0 0<br \/>\nDECLARE_GLOBAL_DATA_PTR;<br \/>\n#else<br \/>\ngd_t *gd;<br \/>\n#endif<\/p>\n<p>#if (CONFIG_COMMANDS &amp; CFG_CMD_NAND)<br \/>\nvoid nand_init (void);<br \/>\n#endif<\/p>\n<p>#ifdef CONFIG_ONENAND<br \/>\nvoid onenand_init(void);<br \/>\n#endif<\/p>\n<p>ulong monitor_flash_len;<\/p>\n<p>#ifdef CONFIG_HAS_DATAFLASH<br \/>\nextern int\u00a0 AT91F_DataflashInit(void);<br \/>\nextern void dataflash_print_info(void);<br \/>\n#endif<\/p>\n<p>#ifndef CONFIG_IDENT_STRING<br \/>\n#define CONFIG_IDENT_STRING &#8220;&#8221;<br \/>\n#endif<\/p>\n<p>const char version_string[] =<br \/>\nU_BOOT_VERSION&#8221; (&#8221; __DATE__ &#8221; &#8211; &#8221; __TIME__ &#8220;)&#8221;CONFIG_IDENT_STRING;<\/p>\n<p>#ifdef CONFIG_DRIVER_CS8900<br \/>\nextern void cs8900_get_enetaddr (uchar * addr);<br \/>\n#endif<\/p>\n<p>#ifdef CONFIG_DRIVER_RTL8019<br \/>\nextern void rtl8019_get_enetaddr (uchar * addr);<br \/>\n#endif<\/p>\n<p>\/*<br \/>\n* Begin and End of memory area for malloc(), and current &#8220;brk&#8221;<br \/>\n*\/<br \/>\nstatic ulong mem_malloc_start = 0;<br \/>\nstatic ulong mem_malloc_end = 0;<br \/>\nstatic ulong mem_malloc_brk = 0;<\/p>\n<p>static<br \/>\nvoid mem_malloc_init (ulong dest_addr)<br \/>\n{<br \/>\nmem_malloc_start = dest_addr;<br \/>\nmem_malloc_end = dest_addr + CFG_MALLOC_LEN;<br \/>\nmem_malloc_brk = mem_malloc_start;<\/p>\n<p>\/* memset ((void *) mem_malloc_start, 0,<br \/>\nmem_malloc_end &#8211; mem_malloc_start); *\/<br \/>\n}<\/p>\n<p>void *sbrk (ptrdiff_t increment)<br \/>\n{<br \/>\nulong old = mem_malloc_brk;<br \/>\nulong new = old + increment;<\/p>\n<p>if ((new &lt; mem_malloc_start) || (new &gt; mem_malloc_end)) {<br \/>\nreturn (NULL);<br \/>\n}<br \/>\nmem_malloc_brk = new;<\/p>\n<p>return ((void *) old);<br \/>\n}<\/p>\n<p>\/************************************************************************<br \/>\n* Init Utilities\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 *<br \/>\n************************************************************************<br \/>\n* Some of this code should be moved into the core functions,<br \/>\n* or dropped completely,<br \/>\n* but let&#8217;s get it working (again) first&#8230;<br \/>\n*\/<\/p>\n<p>static int init_baudrate (void)<br \/>\n{<br \/>\nchar tmp[64];\u00a0\u00a0\u00a0\u00a0 \/* long enough for environment variables *\/<br \/>\nint i = getenv_r (&#8220;baudrate&#8221;, tmp, sizeof (tmp));<br \/>\ngd-&gt;bd-&gt;bi_baudrate = gd-&gt;baudrate = (i &gt; 0)<br \/>\n? (int) simple_strtoul (tmp, NULL, 10)<br \/>\n: CONFIG_BAUDRATE;<\/p>\n<p>return (0);<br \/>\n}<\/p>\n<p>static int display_banner (void)<br \/>\n{<br \/>\nprintf (&#8220;\\n\\n%s\\n\\n&#8221;, version_string);<br \/>\ndebug (&#8220;U-Boot code: %08lX -&gt; %08lX\u00a0 BSS: -&gt; %08lX\\n&#8221;,<br \/>\n_armboot_start, _bss_start, _bss_end);<br \/>\n#ifdef CONFIG_MEMORY_UPPER_CODE \/* by scsuh *\/<br \/>\ndebug(&#8220;\\t\\bMalloc and Stack is above the U-Boot Code.\\n&#8221;);<br \/>\n#else<br \/>\ndebug(&#8220;\\t\\bMalloc and Stack is below the U-Boot Code.\\n&#8221;);<br \/>\n#endif<br \/>\n#ifdef CONFIG_MODEM_SUPPORT<br \/>\ndebug (&#8220;Modem Support enabled\\n&#8221;);<br \/>\n#endif<br \/>\n#ifdef CONFIG_USE_IRQ<br \/>\ndebug (&#8220;IRQ Stack: %08lx\\n&#8221;, IRQ_STACK_START);<br \/>\ndebug (&#8220;FIQ Stack: %08lx\\n&#8221;, FIQ_STACK_START);<br \/>\n#endif<\/p>\n<p>return (0);<br \/>\n}<\/p>\n<p>\/*<br \/>\n* WARNING: this code looks &#8220;cleaner&#8221; than the PowerPC version, but<br \/>\n* has the disadvantage that you either get nothing, or everything.<br \/>\n* On PowerPC, you might see &#8220;DRAM: &#8221; before the system hangs &#8211; which<br \/>\n* gives a simple yet clear indication which part of the<br \/>\n* initialization if failing.<br \/>\n*\/<br \/>\nstatic int display_dram_config (void)<br \/>\n{<br \/>\nint i;<\/p>\n<p>#ifdef DEBUG<br \/>\nputs (&#8220;RAM Configuration:\\n&#8221;);<\/p>\n<p>for(i=0; i&lt;CONFIG_NR_DRAM_BANKS; i++) {<br \/>\nprintf (&#8220;Bank #%d: %08lx &#8220;, i, gd-&gt;bd-&gt;bi_dram[i].start);<br \/>\nprint_size (gd-&gt;bd-&gt;bi_dram[i].size, &#8220;\\n&#8221;);<br \/>\n}<br \/>\n#else<br \/>\nulong size = 0;<\/p>\n<p>for (i=0; i&lt;CONFIG_NR_DRAM_BANKS; i++) {<br \/>\nsize += gd-&gt;bd-&gt;bi_dram[i].size;<br \/>\n}<\/p>\n<p>puts(&#8220;DRAM:\u00a0\u00a0\u00a0 &#8220;);<br \/>\nprint_size(size, &#8220;\\n&#8221;);<br \/>\n#endif<\/p>\n<p>return (0);<br \/>\n}<\/p>\n<p>#ifndef CFG_NO_FLASH<br \/>\nstatic void display_flash_config (ulong size)<br \/>\n{<br \/>\nputs (&#8220;Flash:\u00a0 &#8220;);<br \/>\nprint_size (size, &#8220;\\n&#8221;);<br \/>\n}<br \/>\n#endif \/* CFG_NO_FLASH *\/<\/p>\n<p>\/*<br \/>\n* Breathe some life into the board&#8230;<br \/>\n*<br \/>\n* Initialize a serial port as console, and carry out some hardware<br \/>\n* tests.<br \/>\n*<br \/>\n* The first part of initialization is running from Flash memory;<br \/>\n* its main purpose is to initialize the RAM so that we<br \/>\n* can relocate the monitor code to RAM.<br \/>\n*\/<\/p>\n<p>\/*<br \/>\n* All attempts to come up with a &#8220;common&#8221; initialization sequence<br \/>\n* that works for all boards and architectures failed: some of the<br \/>\n* requirements are just _too_ different. To get rid of the resulting<br \/>\n* mess of board dependent #ifdef&#8217;ed code we now make the whole<br \/>\n* initialization sequence configurable to the user.<br \/>\n*<br \/>\n* The requirements for any new initalization function is simple: it<br \/>\n* receives a pointer to the &#8220;global data&#8221; structure as it&#8217;s only<br \/>\n* argument, and returns an integer return code, where 0 means<br \/>\n* &#8220;continue&#8221; and != 0 means &#8220;fatal error, hang the system&#8221;.<br \/>\n*\/<br \/>\ntypedef int (init_fnc_t) (void);<\/p>\n<p>int print_cpuinfo (void); \/* test-only *\/<\/p>\n<p>init_fnc_t *init_sequence[] = {<br \/>\ncpu_init,\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/* basic cpu dependent setup *\/ \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u8bbe\u7f6e\u6808\u5730\u5740<br \/>\nboard_init,\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/* basic board dependent setup *\/ \u00a0 \u00a0 \u521d\u59cb\u5316\u603b\u7ebf\uff0c\u4e3aLCD\u8bbe\u7f6eGPIO\uff0c\u8bbe\u7f6e\u67b6\u6784\u7c7b\u578b\uff0c\u542f\u52a8\u53c2\u6570\u4fdd\u5b58\u4f4d\u7f6e0x50000000+0x100<br \/>\ninterrupt_init,\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/* set up exceptions *\/<br \/>\nenv_init,\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/* initialize environment *\/<br \/>\ninit_baudrate,\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/* initialze baudrate settings *\/<br \/>\nserial_init,\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/* serial communications setup *\/<br \/>\nconsole_init_f,\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/* stage 1 init of console *\/<br \/>\ndisplay_banner,\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/* say that we are here *\/<br \/>\n#if defined(CONFIG_DISPLAY_CPUINFO)<br \/>\nprint_cpuinfo,\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/* display cpu info (and speed) *\/<br \/>\n#endif<br \/>\n#if defined(CONFIG_DISPLAY_BOARDINFO)<br \/>\ncheckboard,\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/* display board info *\/<br \/>\n#endif<br \/>\ndram_init,\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/* configure available RAM banks *\/<br \/>\ndisplay_dram_config,<br \/>\nNULL,<br \/>\n};<\/p>\n<p>void start_armboot (void) \u00a0 \u00a0 \/*################################# \u6c47\u7f16\u4ee3\u7801\u6267\u884c\u5b8c\u4e4b\u540e\u7b2c\u4e00\u4e2a\u6267\u884c\u7684c\u51fd\u6570 ###################################*\/<br \/>\n{<br \/>\ninit_fnc_t **init_fnc_ptr;<br \/>\nchar *s;<br \/>\n#ifndef CFG_NO_FLASH<br \/>\nulong size;<br \/>\n#endif<\/p>\n<p>#if defined(CONFIG_VFD) || defined(CONFIG_LCD)<br \/>\nunsigned long addr;<br \/>\n#endif<\/p>\n<p>#if defined(CONFIG_BOOT_MOVINAND)<br \/>\nuint *magic = (uint *) (PHYS_SDRAM_1);<br \/>\n#endif<\/p>\n<p>\/* Pointer is writable since we allocated a register for it *\/<br \/>\n#ifdef CONFIG_MEMORY_UPPER_CODE \/* by scsuh *\/ \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/* \u6808\u914d\u7f6e\u5230\u4ee3\u7801\u7684\u4e0a\u9762*\/<br \/>\nulong gd_base;<\/p>\n<p>gd_base = CFG_UBOOT_BASE + CFG_UBOOT_SIZE &#8211; CFG_MALLOC_LEN &#8211; CFG_STACK_SIZE &#8211; sizeof(gd_t); \u00a0\/*\u57fa\u5730\u57400xc7e00000\u52a0\u4e0a\u6574\u4e2a\u4e3auboot\u9884\u7559\u7684\u5927\u5c0f\uff0c\u53bb\u6389malloc\u5206\u914d\u7528\u7684\u5185\u5b58\uff0c\u53bb\u6389\u6808\u5927\u5c0f\uff0c\u53bb\u6389\u5168\u5c40\u6570\u636e\u5927\u5c0f*\/<br \/>\n#ifdef CONFIG_USE_IRQ<br \/>\ngd_base -= (CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\/*\u53bb\u6389IRQ\u548cFIQ\u6808\u5927\u5c0f*\/<br \/>\n#endif<br \/>\ngd = (gd_t*)gd_base; \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/*\u5728\u8fd9\u4e2a\u4f4d\u7f6e\u4fdd\u5b58\u5168\u5c40\u914d\u7f6e\u6570\u636e*\/<br \/>\n#else<br \/>\ngd = (gd_t*)(_armboot_start &#8211; CFG_MALLOC_LEN &#8211; sizeof(gd_t)); \u00a0 \u00a0 \u00a0 \u00a0 \/*\u5982\u679c\u6808\u5728\u4ee3\u7801\u4e0b\u9762\uff0c\u5219\u75280xc7e00000\u53bb\u6389malloc\u5206\u914d\u7528\u5185\u5b58\uff0c\u53bb\u6389\u5168\u5c40\u6570\u636e\u5927\u5c0f\uff0c\u8bbe\u7f6e\u4e3a\u5168\u5c40\u914d\u7f6e\u6570\u636e\u4f4d\u7f6e\u3002*\/<br \/>\n#endif<\/p>\n<p>\/* compiler optimization barrier needed for GCC &gt;= 3.4 *\/ \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\/*\u544a\u8bc9\u7f16\u8bd1\u5668\uff0c\u4e0b\u9762\u7684\u4ee3\u7801\u4e0d\u8981\u4f18\u5316\u3002*\/<br \/>\n__asm__ __volatile__(&#8220;&#8221;: : :&#8221;memory&#8221;);<\/p>\n<p>memset ((void*)gd, 0, sizeof (gd_t));<br \/>\ngd-&gt;bd = (bd_t*)((char*)gd &#8211; sizeof(bd_t)); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\/*gd\u4e0b\u9762\u5b58\u653e\u7684\u662fbd_t\u3002*\/<br \/>\nmemset (gd-&gt;bd, 0, sizeof (bd_t));<\/p>\n<p>monitor_flash_len = _bss_start &#8211; _armboot_start; \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\/*\u4ee3\u7801\u957f\u5ea6*\/<\/p>\n<p>for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) { \/*\u6309\u7167\u987a\u5e8f\u521d\u59cb\u5316\u5404\u79cd\u786c\u4ef6\u8d44\u6e90\uff0c\u89c1\u4e0a\u9762\u5b9a\u4e49\u7684init_sequence\u51fd\u6570\u8868\u3002*\/<\/p><\/div>\n<div>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if ((*init_fnc_ptr)() != 0) {<br \/>\nhang ();<br \/>\n}<br \/>\n}<\/p>\n<p>#ifndef CFG_NO_FLASH<br \/>\n\/* configure available FLASH banks *\/<br \/>\nsize = flash_init ();<br \/>\ndisplay_flash_config (size);<br \/>\n#endif \/* CFG_NO_FLASH *\/<\/p>\n<p>#ifdef CONFIG_VFD<br \/>\n#\u00a0\u00a0\u00a0\u00a0 ifndef PAGE_SIZE<br \/>\n#\u00a0\u00a0\u00a0\u00a0 \u00a0 define PAGE_SIZE 4096<br \/>\n#\u00a0\u00a0\u00a0\u00a0 endif<br \/>\n\/*<br \/>\n* reserve memory for VFD display (always full pages)<br \/>\n*\/<br \/>\n\/* bss_end is defined in the board-specific linker script *\/<br \/>\naddr = (_bss_end + (PAGE_SIZE &#8211; 1)) &amp; ~(PAGE_SIZE &#8211; 1);<br \/>\nsize = vfd_setmem (addr);<br \/>\ngd-&gt;fb_base = addr;<br \/>\n#endif \/* CONFIG_VFD *\/<\/p>\n<p>#ifdef CONFIG_LCD<br \/>\n#\u00a0\u00a0\u00a0\u00a0 ifndef PAGE_SIZE<br \/>\n#\u00a0\u00a0\u00a0\u00a0 \u00a0 define PAGE_SIZE 4096<br \/>\n#\u00a0\u00a0\u00a0\u00a0 endif<br \/>\n\/*<br \/>\n* reserve memory for LCD display (always full pages)<br \/>\n*\/<br \/>\n\/* bss_end is defined in the board-specific linker script *\/<br \/>\naddr = (_bss_end + (PAGE_SIZE &#8211; 1)) &amp; ~(PAGE_SIZE &#8211; 1);<br \/>\nsize = lcd_setmem (addr);<br \/>\ngd-&gt;fb_base = addr;<br \/>\n#endif \/* CONFIG_LCD *\/<\/p>\n<p>\/* armboot_start is defined in the board-specific linker script *\/<br \/>\n#ifdef CONFIG_MEMORY_UPPER_CODE \/* by scsuh *\/<br \/>\nmem_malloc_init (CFG_UBOOT_BASE + CFG_UBOOT_SIZE &#8211; CFG_MALLOC_LEN &#8211; CFG_STACK_SIZE);<br \/>\n#else<br \/>\nmem_malloc_init (_armboot_start &#8211; CFG_MALLOC_LEN);<br \/>\n#endif<\/p>\n<p>#if defined(CONFIG_SMDK6400) || defined(CONFIG_SMDK6410) || defined(CONFIG_SMDK6430) || defined(CONFIG_SMDK2450) || defined(CONFIG_SMDK2416) || \\<br \/>\ndefined(CONFIG_MINI6410)<\/p>\n<p>#if defined(CONFIG_NAND)<br \/>\nputs (&#8220;NAND:\u00a0\u00a0\u00a0 &#8220;);<br \/>\nnand_init();\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/* go init the NAND *\/<br \/>\n#endif<\/p>\n<p>#if defined(CONFIG_ONENAND)<br \/>\nputs (&#8220;OneNAND: &#8220;);<br \/>\nonenand_init();\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/* go init the One-NAND *\/<br \/>\n#endif<\/p>\n<p>#if defined(CONFIG_BOOT_MOVINAND)<br \/>\nputs (&#8220;MMC:\u00a0\u00a0\u00a0\u00a0 &#8220;);<\/p>\n<p>if ((0x24564236 == magic[0]) &amp;&amp; (0x20764316 == magic[1])) {<br \/>\nprintf(&#8220;Boot up for burning\\n&#8221;);<br \/>\n} else {<br \/>\nmovi_set_capacity();<br \/>\nmovi_set_ofs(MOVI_TOTAL_BLKCNT);<br \/>\nmovi_init();<br \/>\n}<br \/>\n#endif<\/p>\n<p>#else<\/p>\n<p>#if (CONFIG_COMMANDS &amp; CFG_CMD_NAND)<br \/>\nputs (&#8220;NAND:\u00a0\u00a0\u00a0 &#8220;);<br \/>\nnand_init();\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/* go init the NAND *\/<br \/>\n#endif<\/p>\n<p>#endif<\/p>\n<p>#ifdef CONFIG_HAS_DATAFLASH<br \/>\nAT91F_DataflashInit();<br \/>\ndataflash_print_info();<br \/>\n#endif<\/p>\n<p>\/* initialize environment *\/<br \/>\nenv_relocate ();<\/p>\n<p>#ifdef CONFIG_VFD<br \/>\n\/* must do this after the framebuffer is allocated *\/<br \/>\ndrv_vfd_init();<br \/>\n#endif \/* CONFIG_VFD *\/<\/p>\n<p>\/* IP Address *\/<br \/>\ngd-&gt;bd-&gt;bi_ip_addr = getenv_IPaddr (&#8220;ipaddr&#8221;);<\/p>\n<p>\/* MAC Address *\/<br \/>\n{<br \/>\nint i;<br \/>\nulong reg;<br \/>\nchar *s, *e;<br \/>\nchar tmp[64];<\/p>\n<p>i = getenv_r (&#8220;ethaddr&#8221;, tmp, sizeof (tmp));<br \/>\ns = (i &gt; 0) ? tmp : NULL;<\/p>\n<p>for (reg = 0; reg &lt; 6; ++reg) {<br \/>\ngd-&gt;bd-&gt;bi_enetaddr[reg] = s ? simple_strtoul (s, &amp;e, 16) : 0;<br \/>\nif (s)<br \/>\ns = (*e) ? e + 1 : e;<br \/>\n}<\/p>\n<p>#ifdef CONFIG_HAS_ETH1<br \/>\ni = getenv_r (&#8220;eth1addr&#8221;, tmp, sizeof (tmp));<br \/>\ns = (i &gt; 0) ? tmp : NULL;<\/p>\n<p>for (reg = 0; reg &lt; 6; ++reg) {<br \/>\ngd-&gt;bd-&gt;bi_enet1addr[reg] = s ? simple_strtoul (s, &amp;e, 16) : 0;<br \/>\nif (s)<br \/>\ns = (*e) ? e + 1 : e;<br \/>\n}<br \/>\n#endif<br \/>\n}<\/p>\n<p>devices_init ();\u00a0\u00a0\u00a0\u00a0 \/* get the devices list going. *\/<\/p>\n<p>#ifdef CONFIG_CMC_PU2<br \/>\nload_sernum_ethaddr ();<br \/>\n#endif \/* CONFIG_CMC_PU2 *\/<\/p>\n<p>jumptable_init ();<\/p>\n<p>console_init_r ();\u00a0\u00a0\u00a0\u00a0 \/* fully init console as a device *\/<\/p>\n<p>#if defined(CONFIG_MISC_INIT_R)<br \/>\n\/* miscellaneous platform dependent initialisations *\/<br \/>\nmisc_init_r ();<br \/>\n#endif<\/p>\n<p>\/* enable exceptions *\/<br \/>\nenable_interrupts ();<\/p>\n<p>\/* Perform network card initialisation if necessary *\/<br \/>\n#if defined(CONFIG_DRIVER_DM9000) &amp;&amp; defined(CONFIG_DRIVER_DM9000_NO_EEPROM)<br \/>\nextern int eth_set_mac(bd_t * bd);<br \/>\nif (getenv (&#8220;ethaddr&#8221;)) {<br \/>\neth_set_mac(gd-&gt;bd);<br \/>\n}<br \/>\n#endif<\/p>\n<p>#ifdef CONFIG_DRIVER_CS8900<br \/>\ncs8900_get_enetaddr (gd-&gt;bd-&gt;bi_enetaddr);<br \/>\n#endif<\/p>\n<p>#if defined(CONFIG_DRIVER_SMC91111) || defined (CONFIG_DRIVER_LAN91C96)<br \/>\nif (getenv (&#8220;ethaddr&#8221;)) {<br \/>\nsmc_set_mac_addr(gd-&gt;bd-&gt;bi_enetaddr);<br \/>\n}<br \/>\n#endif \/* CONFIG_DRIVER_SMC91111 || CONFIG_DRIVER_LAN91C96 *\/<\/p>\n<p>\/* Initialize from environment *\/<br \/>\nif ((s = getenv (&#8220;loadaddr&#8221;)) != NULL) {<br \/>\nload_addr = simple_strtoul (s, NULL, 16);<br \/>\n}<br \/>\n#if (CONFIG_COMMANDS &amp; CFG_CMD_NET)<br \/>\nif ((s = getenv (&#8220;bootfile&#8221;)) != NULL) {<br \/>\ncopy_filename (BootFile, s, sizeof (BootFile));<br \/>\n}<br \/>\n#endif\u00a0\u00a0\u00a0\u00a0 \/* CFG_CMD_NET *\/<\/p>\n<p>#ifdef BOARD_LATE_INIT<br \/>\nboard_late_init ();<br \/>\n#endif<br \/>\n#if (CONFIG_COMMANDS &amp; CFG_CMD_NET)<br \/>\n#if defined(CONFIG_NET_MULTI)<br \/>\nputs (&#8220;Net:\u00a0\u00a0\u00a0\u00a0 &#8220;);<br \/>\n#endif<br \/>\neth_initialize(gd-&gt;bd);<br \/>\n#endif<br \/>\n\/* main_loop() can return to retry autoboot, if so just run it again. *\/ \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\/*\u8fdb\u5165\u4e3b\u5faa\u73af\uff0c\u6267\u884c\u4e00\u6761\u4e00\u6761\u7684\u547d\u4ee4\uff0c\u5b9a\u4e49\u5728Main.C\u91cc\u9762*\/<br \/>\nfor (;;) {<br \/>\nmain_loop ();<br \/>\n}<\/p>\n<p>\/* NOTREACHED &#8211; no way out of command loop except booting *\/<br \/>\n}<\/p>\n<p>void hang (void)<br \/>\n{<br \/>\nputs (&#8220;### ERROR ### Please RESET the board ###\\n&#8221;);<br \/>\nfor (;;);<br \/>\n}<\/p>\n<p>#ifdef CONFIG_MODEM_SUPPORT<br \/>\nstatic inline void mdm_readline(char *buf, int bufsiz);<\/p>\n<p>\/* called from main loop (common\/main.c) *\/<br \/>\nextern void\u00a0 dbg(const char *fmt, &#8230;);<br \/>\nint mdm_init (void)<br \/>\n{<br \/>\nchar env_str[16];<br \/>\nchar *init_str;<br \/>\nint i;<br \/>\nextern char console_buffer[];<br \/>\nextern void enable_putc(void);<br \/>\nextern int hwflow_onoff(int);<\/p>\n<p>enable_putc(); \/* enable serial_putc() *\/<\/p>\n<p>#ifdef CONFIG_HWFLOW<br \/>\ninit_str = getenv(&#8220;mdm_flow_control&#8221;);<br \/>\nif (init_str &amp;&amp; (strcmp(init_str, &#8220;rts\/cts&#8221;) == 0))<br \/>\nhwflow_onoff (1);<br \/>\nelse<br \/>\nhwflow_onoff(-1);<br \/>\n#endif<\/p>\n<p>for (i = 1;;i++) {<br \/>\nsprintf(env_str, &#8220;mdm_init%d&#8221;, i);<br \/>\nif ((init_str = getenv(env_str)) != NULL) {<br \/>\nserial_puts(init_str);<br \/>\nserial_puts(&#8220;\\n&#8221;);<br \/>\nfor(;;) {<br \/>\nmdm_readline(console_buffer, CFG_CBSIZE);<br \/>\ndbg(&#8220;ini%d: [%s]&#8221;, i, console_buffer);<\/p>\n<p>if ((strcmp(console_buffer, &#8220;OK&#8221;) == 0) ||<br \/>\n(strcmp(console_buffer, &#8220;ERROR&#8221;) == 0)) {<br \/>\ndbg(&#8220;ini%d: cmd done&#8221;, i);<br \/>\nbreak;<br \/>\n} else \/* in case we are originating call &#8230; *\/<br \/>\nif (strncmp(console_buffer, &#8220;CONNECT&#8221;, 7) == 0) {<br \/>\ndbg(&#8220;ini%d: connect&#8221;, i);<br \/>\nreturn 0;<br \/>\n}<br \/>\n}<br \/>\n} else<br \/>\nbreak; \/* no init string &#8211; stop modem init *\/<\/p>\n<p>udelay(100000);<br \/>\n}<\/p>\n<p>udelay(100000);<\/p>\n<p>\/* final stage &#8211; wait for connect *\/<br \/>\nfor(;i &gt; 1;) { \/* if &#8216;i&#8217; &gt; 1 &#8211; wait for connection<br \/>\nmessage from modem *\/<br \/>\nmdm_readline(console_buffer, CFG_CBSIZE);<br \/>\ndbg(&#8220;ini_f: [%s]&#8221;, console_buffer);<br \/>\nif (strncmp(console_buffer, &#8220;CONNECT&#8221;, 7) == 0) {<br \/>\ndbg(&#8220;ini_f: connected&#8221;);<br \/>\nreturn 0;<br \/>\n}<br \/>\n}<\/p>\n<p>return 0;<br \/>\n}<\/p>\n<p>\/* &#8216;inline&#8217; &#8211; We have to do it fast *\/<br \/>\nstatic inline void mdm_readline(char *buf, int bufsiz)<br \/>\n{<br \/>\nchar c;<br \/>\nchar *p;<br \/>\nint n;<\/p>\n<p>n = 0;<br \/>\np = buf;<br \/>\nfor(;;) {<br \/>\nc = serial_getc();<\/p>\n<p>\/*\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 dbg(&#8220;(%c)&#8221;, c); *\/<\/p>\n<p>switch(c) {<br \/>\ncase &#8216;\\r&#8217;:<br \/>\nbreak;<br \/>\ncase &#8216;\\n&#8217;:<br \/>\n*p = &#8216;\\0&#8217;;<br \/>\nreturn;<\/p>\n<p>default:<br \/>\nif(n++ &gt; bufsiz) {<br \/>\n*p = &#8216;\\0&#8217;;<br \/>\nreturn; \/* sanity check *\/<br \/>\n}<br \/>\n*p = c;<br \/>\np++;<br \/>\nbreak;<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\n#endif\u00a0\u00a0\u00a0\u00a0 \/* CONFIG_MODEM_SUPPORT *\/<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\/* * To match the U-Boot user interface on ARM platform &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[237,48,49],"class_list":["post-300","post","type-post","status-publish","format-standard","hentry","category-6","tag-board-c","tag-mini6410","tag-uboot"],"views":1539,"_links":{"self":[{"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/300","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=300"}],"version-history":[{"count":1,"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/300\/revisions"}],"predecessor-version":[{"id":301,"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/300\/revisions\/301"}],"wp:attachment":[{"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=300"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}