aesop2440.c

来自「F:worksip2440a board可启动u-boot-like.tar.g」· C语言 代码 · 共 654 行 · 第 1/2 页

C
654
字号
#if 0	        for (i = 0; i < 512; i++) {		if (!(i % 16)) printf("\n%04x : ", i);		printf("%02x ", scratch[i]);	}		for(i=0;i<1024;i++) scratch1[i]=i;	SD_Write((unsigned char *)scratch1, 300000 , 8); 		SD_Read((unsigned char *)scratch1,  300000 , 8);		for(i=0;i<1024;i++) 	{		if(scratch1[i]!=i) printf("oops %d\n",i);	}#endif}#endif   int board_late_init(void){		init_lcd();	if(!SD_card_init()) 		return 0; // No SD/MMC found !!	else	{		SD_FS(); // Check Master boot record !!	}	return 1;}int dram_init(void){	DECLARE_GLOBAL_DATA_PTR;	gd->bd->bi_dram[0].start = PHYS_SDRAM_1;	gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;	return 0;}#if defined(CONFIG_COMMANDS) && defined(CFG_CMD_NAND)#include <linux/mtd/nand.h>int nand_init(void){	S3C2440_NAND * const nand = S3C2440_GetBase_NAND();	extern struct nand_chip nand_dev_desc[CFG_MAX_NAND_DEVICE];		nand->NFCONF = 1 << 12 | 5 << 8 | 1 << 4 | 0 << 0;	nand->NFCONT = 0 << 12 | 0 << 8 | 1 << 6 | 1 << 5 | 1 << 1 | 1 << 0;	nand_probe(0);	if (nand_dev_desc[0].ChipID != NAND_ChipID_UNKNOWN) {		print_size(nand_dev_desc[0].totlen, "\n");	}	return 0;}#endif /* defined(CONFIG_COMMANDS) && defined(CFG_CMD_NAND) */#if defined(CONFIG_COMMANDS) && defined(CFG_CMD_BSP)#ifdef CONFIG_AESOP_LCDint do_bmpload_sub(unsigned char *imgaddr, int pos_x, int pos_y, int disp_info){	S3C24X0_LCD * const lcd = S3C24X0_GetBase_LCD();	bmp_header_t *bmp;	unsigned char *fbaddr, *imgaddr_save;	unsigned char r, g, b;	unsigned long x, y, disp_x_count, disp_y_count;	unsigned long lcd_width, lcd_height, byte_per_pixel;	unsigned long disp_x_offset, disp_x_remain, img_x_remain;		fbaddr = (unsigned char *)AESOP_FB_BASE;	lcd_width = LCD_WIDTH;	lcd_height = LCD_HEIGHT;		if ((lcd->LCDCON1 & 0x1e) == 0x1a) byte_per_pixel = 4;	else byte_per_pixel = 2;		if (disp_info) {			printf("Image location    - %p\n", imgaddr);		printf("Frame buffer      - %p\n", fbaddr);		printf("LCD size          - %ld x %ld\n", lcd_width, lcd_height);		printf("Display position  - %ld , %ld\n", pos_x, pos_y);	}	bmp = (bmp_header_t *)imgaddr;	if (!((bmp->signature[0]=='B') && (bmp->signature[1]=='M'))) {		if (disp_info)			printf("There is no valid bmp file at the given address\n");		return 1;	}	if (disp_info) {			printf("File size         - %d Bytes\n", bmp->file_size);		printf("Image size        - %d x %d\n", bmp->width, bmp->height);		printf("Bits per pixel    - %d\n", bmp->bit_count);		printf("Compression       - %d\n", bmp->compression);	}		imgaddr += bmp->data_offset;	fbaddr += pos_y * (lcd_width * byte_per_pixel);	disp_x_count = (lcd_width > (bmp->width + pos_x)) ? bmp->width : lcd_width - pos_x;	disp_y_count = (lcd_height > (bmp->height + pos_y)) ? bmp->height : lcd_height - pos_y;	disp_x_offset = pos_x * byte_per_pixel;	img_x_remain = (bmp->width - disp_x_count);	disp_x_remain = ((pos_x + disp_x_count) < lcd_width) ? (lcd_width - (pos_x + disp_x_count)) * byte_per_pixel : 0; 	imgaddr_save = imgaddr + (bmp->height * bmp->width * 3);	for (y = 0; y < disp_y_count; y++) {		imgaddr = imgaddr_save - (bmp->width * 3);		imgaddr_save = imgaddr;		fbaddr += disp_x_offset;		for (x = 0; x < disp_x_count; x++) {			b = imgaddr[0];			g = imgaddr[1];			r = imgaddr[2];			imgaddr += 3;			if(byte_per_pixel == 4) {				fbaddr[0] = b;				fbaddr[1] = g;				fbaddr[2] = r;				fbaddr[3] = 0;			} else {				fbaddr[0] = ((g & 0x1c) << 3) | ((b & 0xf8) >> 3);				fbaddr[1] = (r & 0xf8) | (g & 0xe0) >> 5;			}			fbaddr += byte_per_pixel;		}		fbaddr += disp_x_remain;		imgaddr += img_x_remain;		imgaddr += (((unsigned long)imgaddr & 1) == 1) ? 1 : 0;	}	return 0;}/* ------------------------------------------------------------------------- */int do_bmpload(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]){	unsigned char *imgaddr;	unsigned long x_off, y_off;		if ((argc != 2) && (argc != 4)) {		printf ("Usage:\n%s\n", cmdtp->usage);		return -1;	}	x_off = 0;	y_off = 0;		if (argc == 2) {		imgaddr = (unsigned char *)simple_strtoul(argv[1], NULL, 16);	}	else {		imgaddr = (unsigned char *)simple_strtoul(argv[1], NULL, 16);		x_off = simple_strtoul(argv[2], NULL, 10);		y_off = simple_strtoul(argv[3], NULL, 10);	}		return do_bmpload_sub(imgaddr, x_off, y_off, 1);}U_BOOT_CMD(	bmpload,	4,	0,	do_bmpload,	"bmpload - BMP Image load\n",	"[address] [x y] - BMP Image Load\n"	"        address - BMP Image address\n"	"        x - display X position\n"	"        y - display Y position\n");#endif /* CONFIG_AESOP_LCD */#ifdef CONFIG_AESOP_USBDMASS/* ------------------------------------------------------------------------- */int do_usbdmass (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]){	if (argc == 1) 	return usbdmass("sd");	else if (argc == 2) return usbdmass(argv[1]);	printf ("Usage:\n%s\n", cmdtp->usage);	return -1;}U_BOOT_CMD(	usbdmass,	2,	0,	do_usbdmass,	"usbdmass- USB Device Mass-storage\n",	"media - start USB Device Mass-storage class handler with specified media\n"	"        media - ram, sd, nand\n");#endif /* CONFIG_AESOP_USBDMASS */#ifdef CONFIG_AESOP_YAFFS/* ------------------------------------------------------------------------- */#define MTDBLOCK0_OFFSET	0#define MTDBLOCK0_SIZE		2 * SZ_1M#define MTDBLOCK1_OFFSET	MTDBLOCK0_OFFSET + MTDBLOCK0_SIZE#define MTDBLOCK1_SIZE		62 * SZ_1M#define MTDBLOCK2_OFFSET	MTDBLOCK1_OFFSET + MTDBLOCK1_SIZE#define MTDBLOCK2_SIZE		44 * SZ_1M#define MTDBLOCK_MAX		2#define SZ_OOB			16#define SZ_PAGE_WOOB		528#define SZ_PAGE			512#define SZ_BLOCK		512 * 32#include <linux/mtd/nand.h>// countBits is a quick way of counting the number of bits in a byte.// ie. countBits[n] holds the number of 1 bits in a byte with the value n.static const char countBits[256] ={0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8};int nand_read_oob(struct nand_chip *, size_t, size_t, size_t *, u_char *);int nand_write_oob(struct nand_chip *, size_t, size_t, size_t *, const u_char *);int nand_erase(struct nand_chip *, size_t, size_t, int);int nand_write_page_yaffs (int, u_char *);int do_mkyaffs(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]){	extern struct nand_chip nand_dev_desc[CFG_MAX_NAND_DEVICE];	struct nand_chip *nand = &nand_dev_desc[0];	struct {unsigned long offset; unsigned long size;}		mtdblk[MTDBLOCK_MAX] = {			{ MTDBLOCK0_OFFSET, MTDBLOCK0_SIZE },			{ MTDBLOCK1_OFFSET, MTDBLOCK1_SIZE }			 };	unsigned long source, target, count, count_save, addr_blk, addr_sec;	unsigned char *src_ptr, *src_ptr_save, oob_buff[SZ_OOB];	int i, ret;	size_t retlen;		if (argc != 4) {		printf ("Usage:\n%s\n", cmdtp->usage);		return -1;	}	source = simple_strtoul(argv[1], NULL, 16);	target = simple_strtoul(argv[2], NULL, 10);	count = simple_strtoul(argv[3], NULL, 16);	if (target < 0 || target >= MTDBLOCK_MAX) {		printf ("Error - target block no. should be between 0 and %d\n", MTDBLOCK_MAX - 1);		return -1;	}	if (count % SZ_PAGE_WOOB) {		printf ("Error - Image not a multiple of 528 bytes\n");		return -1;	}	if (mtdblk[target].size < ((count / SZ_PAGE_WOOB) * SZ_PAGE)) {		printf ("Error - Image is too big for MTDBLOCK%d\n", target);		printf ("        MTDBLOCK%d size - 0x%lx\n", target, mtdblk[target].size);		return -1;	}	src_ptr = (unsigned char *)source;	for (addr_blk = mtdblk[target].offset; addr_blk < mtdblk[target].offset + mtdblk[target].size; addr_blk += SZ_BLOCK) {		count_save = count;		src_ptr_save = src_ptr;		nand_read_oob(nand, addr_blk, SZ_OOB, &retlen, oob_buff);		if (countBits[oob_buff[5]] < 7) {			printf("Block at 0x%lx is marked BAD and is not being formatted\n",addr_blk);			continue;		}		ret = nand_erase(nand, addr_blk, nand->erasesize, 0);		if (ret == -1) {			for (i = 0; i < SZ_OOB; i++) oob_buff[i] = 0;			nand_write_oob( nand, addr_blk, SZ_OOB, &retlen, oob_buff);			printf("Block erase error at 0x%lx, not formatted\n",addr_blk);			continue;		}		if (addr_blk == mtdblk[target].offset) continue;		for (addr_sec = addr_blk; addr_sec < addr_blk + SZ_BLOCK; addr_sec += SZ_PAGE) {			if (src_ptr < (unsigned char *)(source + count)) {				ret = nand_write_page_yaffs(addr_sec >> 9, src_ptr);				if (ret == -1) {					src_ptr = src_ptr_save;					for (i = 0; i < SZ_OOB; i++) oob_buff[i] = 0;					nand_write_oob( nand, addr_blk, SZ_OOB, &retlen, oob_buff);					printf("Block write error at 0x%lx, mark bad and not formatted\n",addr_sec);					continue;				}				src_ptr += SZ_PAGE_WOOB;				}		}	}	if (src_ptr != (unsigned char *)(count + source)) {		printf("Error - Insufficient NAND flash space.\n");		printf("        mkyaffs failed\n");		return -1;	}	printf("mkyaffs completed.\n");	return 0;}U_BOOT_CMD(	mkyaffs,	4,	0,	do_mkyaffs,	"mkyaffs - Write YAFFS Image to NAND Flash\n",	"source target count\n"	"        source - YAFFS Image address\n"	"        target - NAND Flash destination MTDBlock No.\n"	"        count  - byte count of YAFFS image\n");#endif /* CONFIG_AESOP_YAFFS */#endif	/* defined(CONFIG_COMMANDS) && defined(CFG_CMD_BSP) */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?