根据u-boot-1.1.6启动流程来划分,u-boot功能主要划分为四个部分
1,硬件初始化 -->start.S init.c
2,从 flash 拷贝内核到 ram -->main.c
3,设置 tag 参数 -->tag.c tag.h
4,跳到内核,执行内核代码 --> main.c
start.s源码:
.extern main .text
.global _start
_start:
bl disable_watchdog
bl clock_init
bl open_icache
bl sdram_init
bl uart0_init
bl nand_init ldr sp, =0x34000000
ldr r0,=
ldr r1,=_start
ldr r2,=__bss_start @0x33f80000
sub r2,r2,r1
bl copy_uboot_to_sdram
ldr pc,=on_sdram on_sdram:
bl clean_bss
ldr lr,=main_return
ldr pc,=main
main_return:
b main_return
init.c源码:
//watchdog
#define WTCON (*(volatile unsigned long *)0x53000000) //clock
#define CLOCKTIME (*(volatile unsigned long *)0x4c000000)
#define MPLLCON (*(volatile unsigned long *)0x4c000004)
#define CLKDIVN (*(volatile unsigned long *)0x4c000014)
#define CAMDIVN (*(volatile unsigned long *)0x4c000018) //sdram
#define BWSCON (*(volatile unsigned long *)0x48000000)
#define BANKCON0 (*(volatile unsigned long *)0x48000004)
#define BANKCON1 (*(volatile unsigned long *)0x48000008)
#define BANKCON2 (*(volatile unsigned long *)0x4800000c)
#define BANKCON3 (*(volatile unsigned long *)0x48000010)
#define BANKCON4 (*(volatile unsigned long *)0x48000014)
#define BANKCON5 (*(volatile unsigned long *)0x48000018)
#define BANKCON6 (*(volatile unsigned long *)0x4800001c)
#define BANKCON7 (*(volatile unsigned long *)0x48000020)
#define REFRESH (*(volatile unsigned long *)0x48000024)
#define BANKSIZE (*(volatile unsigned long *)0x48000028)
#define MRSRB6 (*(volatile unsigned long *)0x4800002c)
#define MRSRB7 (*(volatile unsigned long *)0x48000030) //nand
#define NFCONF (*(volatile unsigned long *)0x4e000000)
#define NFCONT (*(volatile unsigned long *)0x4e000004)
#define NFCMMD (*(volatile unsigned char *)0x4e000008)
#define NFADDR (*(volatile unsigned char *)0x4e00000C)
#define NFDATA (*(volatile unsigned char *)0x4e000010)
#define NFSTAT (*(volatile unsigned char *)0x4e000020) //uart
#define ULCON0 (*(volatile unsigned long *)0x50000000)
#define UCON0 (*(volatile unsigned long *)0x50000004)
#define UFCON0 (*(volatile unsigned long *)0x50000008)
#define UMCON0 (*(volatile unsigned long *)0x5000000c)
#define UTRSTAT0 (*(volatile unsigned long *)0x50000010)
#define UERSTAT0 (*(volatile unsigned long *)0x50000014)
#define UTXH0 (*(volatile unsigned char *)0x50000020)
#define URXH0 (*(volatile unsigned char *)0x50000024)
#define UBRDIV0 (*(volatile unsigned long *)0x50000028) //GPH
#define GPHCON (*(volatile unsigned long *)0x56000070)
#define GPHDAT (*(volatile unsigned long *)0x56000074)
#define GPHUP (*(volatile unsigned long *)0x56000078) /**************************************** watchdog_init ********************************************/
void disable_watchdog(void)
{
WTCON=;
} /****************************************** colck_init ********************************************/
void clock_init(void)
{
MPLLCON = ((0x5c<<)|(0x01<<)|(0x02));
CLKDIVN = ((<<)|(<<)); //200 MHZ
// CAMDIVN = ((1<<1)|(1<<0)); //1:2:4 200M:100M:50M __asm__
(
" mrc p15,0,r1,c1,c0,0 \n"
" orr r1, r1,#0xc0000000 \n"
" mcr p15,0,r1,c1,c0,0 \n"
); } void open_icache(void)
{
__asm__
(
" mrc p15, 0, r0, c1, c0, 0 \n"
" orr r0, r0, #(1<<12) \n"
" mcr p15, 0, r0, c1, c0, 0 \n"
);
} /****************************************** sdram_init *******************************************/ void sdram_init(void)
{
BWSCON = 0x22011110 ; //BWSCON
BANKCON0 = 0x00000700; //BANKCON0
BANKCON1 =0x00000700; //BANKCON1
BANKCON2 = 0x00000700; //BANKCON2
BANKCON3 = 0x00000700; //BANKCON3
BANKCON4 = 0x00000700; //BANKCON4
BANKCON5 =0x00000700; //BANKCON5
BANKCON6 =0x00018005; //BANKCON6
BANKCON7 = 0x00018005; //BANKCON7
REFRESH =0x008C04F4 ; // REFRESH
BANKSIZE = 0x000000B1; //BANKSIZE
MRSRB6 = 0x00000030; //MRSRB6
MRSRB7 = 0x00000030 ; //MRSRB7
} /****************************************** nand_flash_init ********************************************/ void select_chip(void)
{
NFCONT &= ~(<<);
} void disselect_chip(void)
{
NFCONT |= (<<);
} void write_command(unsigned char cmd)
{
NFCMMD=cmd;
volatile int i;
for (i = ; i < ; i++); } unsigned char read_data(void)
{
return NFDATA;
} void write_addr(unsigned int addr)
{
unsigned int row,col;
int i=;
row=addr/;
col=addr%; NFADDR= 0xff & col;
for (i = ; i < ; i++);
NFADDR=(col>>)& 0xff;
for (i = ; i < ; i++); NFADDR=row& 0xff;
for (i = ; i < ; i++);
NFADDR=(row>>)& 0xff;
for (i = ; i < ; i++);
NFADDR=(row>>)& 0xff;
for (i = ; i < ; i++);
} int nand_ready(void) {
return (NFSTAT & );
} void nand_init(void)
{
NFCONF = (<<|<<|<<);
NFCONT = (<<|<<|<<);
} void nand_read(unsigned int sour,unsigned char* dest,int copy_size)
{
int col=sour % ;
int i=; select_chip();
while(i<copy_size)
{ write_command(0x00); write_addr(sour); write_command(0x30); while(!nand_ready()); for(; (col<)&&(i<copy_size);col++) //page read
{
dest[i]=read_data();
sour++; i++;
}
col=;
} disselect_chip();
} /****************************************** copy_uboot_to_sdram ********************************************/
int nand_boot(void)
{
volatile unsigned long* top = (volatile unsigned long *)0x00000000;
int value=*top;
*top=;
if(*top==)
{
*top=value;
return ;
}
else return ;
} void copy_uboot_to_sdram(unsigned char* sour1,unsigned char *dest,int copy_size)
{
int i=;
unsigned char *sour = sour1;
if(nand_boot()) // nand_boot
{
while(i<copy_size)
{
dest[i]=sour[i];i++;
}
}
else //nor_boot
{
nand_read((unsigned long)sour,dest,copy_size);
}
} /*********************************************clean_bss*************************************************/
void clean_bss(void)
{
extern long __bss_end, __bss_start;
int* p = &__bss_start;
for(;p < &__bss_end ;p++) *p=;
} /********************************************uart_init*****************************************************/ void uart0_init(void)
{
GPHCON|=0xa0;
GPHUP=0x0c; ULCON0=0x03;
UCON0=0x05;
UFCON0=0x00;
UMCON0=0x00;
UBRDIV0=((/(*))-);
} unsigned char getc(void)
{
while(!(UTRSTAT0 & 0x01));
return URXH0;
} void putc(unsigned char date)
{
while(!(UTRSTAT0 & 0x02));
UTXH0=date;
} void puts(char *str)
{
while(*str) putc(*str++); } void puthex(unsigned int val)
{
/* 0x1234abcd */
int i;
int j; puts("0x"); for (i = ; i < ; i++)
{
j = (val >> ((-i)*)) & 0xf;
if ((j >= ) && (j <= ))
putc('' + j);
else
putc('A' + j - 0xa); } }
tag.c源码:
/*****************************************string_lib***********************************************/
int strlen(char *str)
{
int i=;
while(str[i] != ) i++;
return i;
} void strcopy(char *dest,char *sour)
{
while((*dest++ = *sour++)!= );
} /*****************************************tag_init************************************************/
#define tag_next(type) (struct tag *) ((unsigned long *)(type) + (type)->hdr.size)
#define tag_size(size) ((sizeof(struct tag_header)+sizeof(struct size))>>2) struct tag_header
{
unsigned long size;
unsigned long tag_type;
}; struct tag_core
{
unsigned long flags;
unsigned long pagesize;
unsigned long rootdevf;
}; struct tag_mem32
{
unsigned long size;
unsigned long start;
}; struct tag_cmdline
{
char cmdline[];
}; struct tag
{
struct tag_header hdr;
union
{
struct tag_core core;
struct tag_mem32 mem32;
struct tag_cmdline cmdline;
}u;
}; static struct tag *params=(struct tag *)0x30000100; void set_start_tag(void)
{
params->hdr.size=tag_size(tag_core);
params->hdr.tag_type=0x54410001; params->u.core.flags= ;
params->u.core.pagesize= ;
params->u.core.rootdevf= ; params=tag_next(params);
} void set_memory_tag(void)
{
params->hdr.size= tag_size(tag_mem32);
params->hdr.tag_type = 0x54410002; params->u.mem32.size =**;
params->u.mem32.start =
0x30000000; params=tag_next(params); } void set_cmdline_tag(char *cmdline)
{
int len=strlen(cmdline)+;
params->hdr.size = (sizeof(struct tag_header)+len+)>>;
params->hdr.tag_type = 0x54410009;
strcopy(params->u.cmdline.cmdline ,cmdline); params=tag_next(params);
} void set_end_tag(void)
{
params->hdr.size = ;
params->hdr.tag_type = ;
}
tag.h源码:
#ifndef _TAG_H_
#define _TAG_H_ void set_cmdline_tag(char * cmdline);
void set_end_tag(void);
void set_memory_tag(void);
void set_start_tag(void); #endif
main.c源码:
extern void nand_read(unsigned long sour, unsigned char * dest, int copy_size);
extern void puts(char * str);
void putc(unsigned char date);
void puthex(unsigned int val); #include"tag.h" int main(void)
{
void (*thekernel)(int zero,int arch,unsigned int params); puts("bootloader start.....\n\r"); //copy kernel
puts("1. copy kernal to sdram\n\r");
nand_read(0x60000+,(unsigned char *)0x30008000,0x200000); //set params
set_start_tag();
set_memory_tag();
set_cmdline_tag("noinitrd root=/dev/mtdblock3 init=/linuxrc console=ttySAC0");
set_end_tag();
puts("2. set kernel parameters\n\r"); //jump to kernel
puts("3. jump to kernel\n\r");
thekernel=(void (*)(int,int ,unsigned int))0x30008000;
thekernel(,,0x30000100); //error
puts("something wrong\n\r");
return ;
}
编译用的Makefile文件:
OBJS := start.o init.o tag.o main.o
CFLAGS := -O2 -Wall
CPPFLAGS := -nostdinc -fno-builtin CC = arm-linux-gcc
LD = arm-linux-ld
OBJCOPY = arm-linux-objcopy
OBJDUMP = arm-linux-objdump uboot.bin: ${OBJS}
${LD} -Tuboot.lds -o uboot.elf $^
${OBJCOPY} -O binary -S uboot.elf $@
${OBJDUMP} -D -m arm uboot.elf > uboot.dis %.o:%.c
${CC} ${CPPFLAGS} ${CFLAGS} -o $@ -c $< %.o:%.s
${CC} ${CPPFLAGS} ${CFLAGS} -o $@ -c $< clean:
rm -f *.o *.bin *.elf *.dis
连接脚本:
SECTIONS
{
. = 0x33f80000;
.text : {*(.text)} . = ALIGN();
.rodata : {*(.rodata*)} . = ALIGN();
.data : {*(.data)} . = ALIGN();
__bss_start = .;
.bss : {*(.bss) *(COMMON)}
__bss_end = .;
}
实现简单的 u-boot的更多相关文章
-
构建一个简单的Spring Boot项目
11 构建一个简单的Spring Boot项目 这个章节描述如何通过Spring Boot构建一个"Hello Word"web应用,侧重介绍Spring Boot的一些重要功能. ...
-
一个简单的spring boot程序
搭建一个spring boot项目十分的方便,网上也有许多,可以参考 https://www.cnblogs.com/ityouknow/p/5662753.html 进行项目的搭建.在此我就不详细介 ...
-
【Spring Boot】创建一个简单的Spring Boot的 Demo
走进Spring Boot 文章目录 走进Spring Boot 环境搭建 新建Spring Boot项目 开始创建项目 配置JDK版本 和 Initializr Service URL 配置Proj ...
-
简单的Spring Boot项目——实现连接Mysql数据库
一.创建Spring Boot项目 参考:使用IntelliJ IDEA创建简单的Spring Boot项目 二.数据库.表的创建 三.项目开发 3.1 pom.xml文件配置 <?xml ve ...
-
一步一步实现一个简单的OS(简单的让boot载入setup)
这次直接写用boot载入setup模块. 文件系统就先不弄了,以后再说, 咱先整个转简单的载入器. 我把软盘引导改成硬盘了,由于硬盘的读扇区函数简单一些. 这里没有做硬盘的mbr区,我认为在如今我的这 ...
-
超简单,spring boot 添加mybatis
看了很多人写的博客,要么太复杂,要么没有添加xml的方式,自己亲自配置了一下,供各位参考. 项目截图 1.添加pom文件 <!-- 设置mybatis --> <dependency ...
-
最简单的spring boot web项目
搭建效果为: 直接在网页输入请求,在页面中显示一行文字:Hello,Spring Boot 与一般的wen项目不同的地方: 1.不需要配置web.xml 文件,但需要注解@SpringBootAppl ...
-
简单使用Spring Boot+JpaRepository+hibernate搭建项目
sql: -- -------------------------------------------------------- -- 主机: 127.0.0.1 -- 服务器版本: 10.3.9-M ...
-
手把手教你手写一个最简单的 Spring Boot Starter
欢迎关注微信公众号:「Java之言」技术文章持续更新,请持续关注...... 第一时间学习最新技术文章 领取最新技术学习资料视频 最新互联网资讯和面试经验 何为 Starter ? 想必大家都使用过 ...
-
使用IntelliJ IDEA创建简单的Spring Boot项目
方法一: File - New -Project 创建结束后进行测试运行,修改代码如下: package com.springboot.testone; import org.springframew ...
随机推荐
-
烦人的win10的输入法
这段时间在使用win10,被win10的输入法折腾的要死要死的... 通过度娘把它设置得跟win7使用习惯差不多了, (见:http://jingyan.baidu.com/article/b2c18 ...
-
GZFramwork数据库层《三》普通主从表增删改查
运行结果: 使用代码生成器(GZCodeGenerate)生成tb_Cusomer和tb_CusomerDetail的Model 生成器源代码下载地址: https://github.com/Gars ...
-
ProtoBuffer 简单例子
最近学了一下protobuf,写了一个简单的例子,如下: person.proto文件 message Person{ required string name = 1; required int32 ...
-
梭子鱼:APT攻击是一盘更大的棋吗?
随着企业对IT的依赖越来越强,APT攻击可能会成为一种恶意打击竞争对手的手段.目前,APT攻击目标主要有政治和经济目的两大类.而出于经济目的而进行的APT攻击可以获取竞争对手的商业信息,也可使用竞争对 ...
-
php 练习一 5月5日
练习题一:通过登录者找到他的好友并显示在页面上 <title>无标题文档</title> <style type="text/css"> * { ...
-
Google大数据三篇著名论文----中文版
Google File System中文版 Google Bigtable中文版 Google MapReduce中文版
-
笔记整理--HTTP Header 详解
HTTP Header 详解 2013/09/21 | 分类: IT技术 | 0 条评论 | 标签: HTTP 分享到:36 原文出处: zcmhi HTTP(HyperTextTransferPro ...
-
Linux架构浅谈
以下图为基础: 最内层是硬件,最外层是用户常用的应用,比如说firefox浏览器,evolution查看邮件,一个计算流体模型等等.硬件是物质基础,而应用提供服务.但在两者之间,还要经过一番周折. 还 ...
-
课外知识----ini
ini 初始化英文单词的缩写,用来初始化参数 ini文件配置 [小节] 键=值 [小节] 键=值
-
eclipse Tomcat和 MYSQL JAVA web新手开发示例--登录界面连接数据库
登录界面login.jsp 1 <%@ page language="java" import="java.util.*" contentType=&qu ...