iTop-4412精英版的u-boot-2017.11移植教程(一)

获取u-boot-2017.11

本博客的版本是u-boot-2017.11.tar.bz2.
关于u-boot的启动流程及原理,本博客就不详细说明,网上教程也是一大堆,想要了解的各位可以自行搜索学习
官网下载地址:ftp://ftp.denx.de/pub/u-boot/u-boot-2017.11.tar.bz2

开始移植

(一)创建板级目录

mkdir board/samsung/itop4412
mkdir board/samsung/itop4412/tools

(二)添加板级文件

touch board/samsung/itop4412/itop4412.c
touch board/samsung/itop4412/Kconfig
touch board/samsung/itop4412/Makefile
touch board/samsung/itop4412/MAINTAINERS
touch board/samsung/itop4412/tools/mkitop4412spl.c

(三)编辑文件内容
(1)itop4412.c

/*
 * Copyright (C) 2011 Samsung Electronics
 *
 * SPDX-License-Identifier:	GPL-2.0+
 */

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

DECLARE_GLOBAL_DATA_PTR;

u32 get_board_rev(void)
{
	return 0;
}

int exynos_init(void)
{
	return 0;
}

int board_usb_init(int index, enum usb_init_type init)
{
	return 0;
}

#ifdef CONFIG_BOARD_EARLY_INIT_F
int exynos_early_init_f(void)
{
	return 0;
}
#endif

(2)Kconfig

if TARGET_ITOP4412

config SYS_BOARD
	default "itop4412"

config SYS_VENDOR
	default "samsung"

config SYS_CONFIG_NAME
	default "itop4412"

endif

(3)Makefile

#
# Copyright (C) 2011 Samsung Electronics
#
# SPDX-License-Identifier:	GPL-2.0+
#

ifdef CONFIG_SPL_BUILD
# necessary to create built-in.o
obj- := __dummy__.o

hostprogs-y := tools/mkitop4412spl
always := $(hostprogs-y)

# omit -O2 option to suppress
#   warning: dereferencing type-punned pointer will break strict-aliasing rules
#
# TODO:
# Fix the root cause in tools/mkitop4412spl.c and delete the following work-around
$(obj)/tools/mkitop4412spl: HOSTCFLAGS:=$(filter-out -O2,$(HOSTCFLAGS))
else
obj-y	+= itop4412.o
endif

(4)MAINTAINERS

ITOP4412 BOARD
M:	Chander Kashyap 
S:	Maintained
F:	board/samsung/itop4412/
F:	include/configs/itop4412.h
F:	configs/itop4412_defconfig

(5)mkitop4412spl.c

/*
 * Copyright (C) 2011 Samsung Electronics
 *
 * SPDX-License-Identifier:	GPL-2.0+
 */

#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define BUFSIZE			(16*1024)
#define IMG_SIZE		(14*1024) //16*1024
#define SPL_HEADER_SIZE		0 //16
#define FILE_PERM		(S_IRUSR | S_IWUSR | S_IRGRP \
				| S_IWGRP | S_IROTH | S_IWOTH)
#define SPL_HEADER		"S5PC210 HEADER  "
/*
* Requirement:
* IROM code reads first 14K bytes from boot device.
* It then calculates the checksum of 14K-4 bytes and compare with data at
* 14K-4 offset.
*
* This function takes two filenames:
* IN  "u-boot-spl.bin" and
* OUT "$(BOARD)-spl.bin as filenames.
* It reads the "u-boot-spl.bin" in 16K buffer.
* It calculates checksum of 14K-4 Bytes and stores at 14K-4 offset in buffer.
* It writes the buffer to "$(BOARD)-spl.bin" file.
*/

int main(int argc, char **argv)
{
	int i, len;
	unsigned char buffer[BUFSIZE] = {0};
	int ifd, ofd;
	unsigned int checksum = 0, count;

	if (argc != 3) {
		printf(" %d Wrong number of arguments\n", argc);
		exit(EXIT_FAILURE);
	}

	ifd = open(argv[1], O_RDONLY);
	if (ifd < 0) {
		fprintf(stderr, "%s: Can't open %s: %s\n",
			argv[0], argv[1], strerror(errno));
		exit(EXIT_FAILURE);
	}

	ofd = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, FILE_PERM);
	if (ofd < 0) {
		fprintf(stderr, "%s: Can't open %s: %s\n",
			argv[0], argv[2], strerror(errno));
		if (ifd)
			close(ifd);
		exit(EXIT_FAILURE);
	}

	len = lseek(ifd, 0, SEEK_END);
	lseek(ifd, 0, SEEK_SET);

	memcpy(&buffer[0], SPL_HEADER, SPL_HEADER_SIZE);

	count = (len < (IMG_SIZE - SPL_HEADER_SIZE))
		? len : (IMG_SIZE - SPL_HEADER_SIZE);

	if (read(ifd, buffer + SPL_HEADER_SIZE, count) != count) {
		fprintf(stderr, "%s: Can't read %s: %s\n",
			argv[0], argv[1], strerror(errno));

		if (ifd)
			close(ifd);
		if (ofd)
			close(ofd);

		exit(EXIT_FAILURE);
	}
	
#if 0
	for (i = 0; i < IMG_SIZE - SPL_HEADER_SIZE; i++)
		checksum += buffer[i+16];

	*(unsigned long *)buffer ^= 0x1f;
	*(unsigned long *)(buffer+4) ^= checksum;

	for (i = 1; i < SPL_HEADER_SIZE; i++)
		buffer[i] ^= buffer[i-1];
#endif

	for (i = 0; i < IMG_SIZE - 4; i++)
		checksum += (unsigned char)buffer[i];

	*(unsigned int *)&buffer[i] = checksum;

	if (write(ofd, buffer, BUFSIZE) != BUFSIZE) {
		fprintf(stderr, "%s: Can't write %s: %s\n",
			argv[0], argv[2], strerror(errno));

		if (ifd)
			close(ifd);
		if (ofd)
			close(ofd);

		exit(EXIT_FAILURE);
	}

	if (ifd)
		close(ifd);
	if (ofd)
		close(ofd);

	return EXIT_SUCCESS;
}

(四) 修改文件
修改arch/arm/mach-exynos/Kconfig

vim arch/arm/mach-exynos/Kconfig
+config TARGET_ITOP4412
+	bool "Exynos4412 iTop-4412 board"
+	select SUPPORT_SPL

iTop-4412精英版的u-boot-2017.11移植教程(一)_第1张图片

+source "board/samsung/itop4412/Kconfig"

这里写图片描述

(五) 修改顶级目录下的Makefile

vim Makefile
CROSS_COMPILE := arm-linux-gnueabi-

iTop-4412精英版的u-boot-2017.11移植教程(一)_第2张图片

(五) 配置 .config 编译选项

make menuconfig

(1)进入配置页面
iTop-4412精英版的u-boot-2017.11移植教程(一)_第3张图片

(2)选择 Architecture select(平台类型)
iTop-4412精英版的u-boot-2017.11移植教程(一)_第4张图片
(3)选择ARM architecture(ARM平台类型)
iTop-4412精英版的u-boot-2017.11移植教程(一)_第5张图片
(4)选择芯片版本
iTop-4412精英版的u-boot-2017.11移植教程(一)_第6张图片
(5)选择刚刚我们添加的itop4412板级类型
iTop-4412精英版的u-boot-2017.11移植教程(一)_第7张图片
(6)选择Boot media引导媒介
iTop-4412精英版的u-boot-2017.11移植教程(一)_第8张图片
(7)选该引导延时 5s(不是她别重要)
iTop-4412精英版的u-boot-2017.11移植教程(一)_第9张图片
(8)选择控制台选项配置(不是特别重要)
iTop-4412精英版的u-boot-2017.11移植教程(一)_第10张图片
(10)选择SPL/TPL
配置链接脚本的路径
iTop-4412精英版的u-boot-2017.11移植教程(一)_第11张图片
配置支持GPIO
iTop-4412精英版的u-boot-2017.11移植教程(一)_第12张图片
配置支持串口
iTop-4412精英版的u-boot-2017.11移植教程(一)_第13张图片

(11)选择Command line interface(命令行接口)
配置Use hush shell
iTop-4412精英版的u-boot-2017.11移植教程(一)_第14张图片
配置Shell prompt
iTop-4412精英版的u-boot-2017.11移植教程(一)_第15张图片
(12)选择Partition Types(分区类型)
iTop-4412精英版的u-boot-2017.11移植教程(一)_第16张图片
(13)选择Device Tree Control(设备树配置)
iTop-4412精英版的u-boot-2017.11移植教程(一)_第17张图片
(14)选择Device Drivers(设备驱动)
配置Support block devices
iTop-4412精英版的u-boot-2017.11移植教程(一)_第18张图片
配置Serial drivers串口驱动(重要
iTop-4412精英版的u-boot-2017.11移植教程(一)_第19张图片
配置MMC Host controller Support (重要)
iTop-4412精英版的u-boot-2017.11移植教程(一)_第20张图片

(15)选择File systems(文件系统)
iTop-4412精英版的u-boot-2017.11移植教程(一)_第21张图片

make menuconfig基本配置就是这些,由于写不完,留着下一节写。

下一节
iTop-4412精英版的u-boot-2017.11移植教程(二)

你可能感兴趣的:(u-boot,移植)