Mango24R2 Auto Write http://www.mangoboard.com/ http://cafe.naver.com/embeddedcrazyboys Crazy Embedded Laboratory www.mangoboard.com cafe.naver.com/embeddedcrazyboys CRZ Technology 1
Document History Revision Date Change note 2
1. Auto write...4 1.1. uboot 수정... 4 2. key1,2로 7 inch, 10.4 inch LCD선택하여 NAND flash write...9 3. LCD화면에 writing, write 완료이미지출력하기... 16 www.mangoboard.com cafe.naver.com/embeddedcrazyboys CRZ Technology 3
1. Auto write 1.1. uboot 수정 uboot 를보면아래와같이 GPCDAT_REG 로난드모드인지구별한다. 부트스위치에서 5 번과 6 번에의해서난드부팅과 MMC 부팅으로선택됩니다. GPC5 와 GPC7 번을확인합니다. S3C2450 매뉴얼을보면 To use NAND Flash Device, The OM and the GPC5/6/7 configuration should be set to use IROM boot and select proper nand device type. Nand Boot written below is boot device in IROM boot. Refer to IROM application Note for more information. S3C2450 supports nand boot by using IROM boot mode. 위와같이부트스위치를통해 NAND 모드로부팅합니다. 4
비트분석기로계산해보겠습니다. A0 입니다. uboot$ vi lib_arm/board.c 565 #if 1 /* Delete this code for NFS */ 566 /* by CRZ, boot cmd, args setting */ 567 if((gpcdat_reg & 0xA0) == 0xA0) 568 { 569 setenv("bootcmd", CONFIG_NAND_BOOTCOMMAND); 570 setenv("bootargs", CONFIG_NAND_BOOTARGS); 571 } 572 else 573 { 574 setenv("bootcmd", CONFIG_MMC_BOOTCOMMAND); 575 setenv("bootargs", CONFIG_MMC_BOOTARGS); 576 } 577 #endif if((gpcdat_reg & 0xA0) == 0xA0) << 이부분이 AND연산하여동일하다면 NAND부팅모드입니다. 아래에서각각 bootcmd를설정합니다. uboot$ vi include/configs/mango2450.h 363 #define CONFIG_NAND_BOOTCOMMAND "nand read 0xC0008000 0x80000 0x480000;bootm 0xC0008000" 364 #define CONFIG_NAND_BOOTARGS "noinitrd console=ttysac1,115200 rw ubi.mtd=2 root=ubi0:rootfs rootfstype=ubifs rootwait" 365 //#elif defined(config_boot_movinand) 366 //#define CFG_ENV_IS_IN_MOVINAND 367 //#define CONFIG_BOOTCOMMAND "sleep 1;nand scrub ;sleep 1;nand erase;sleep 1;movi read 3800000# 40000 c0000000 ;sleep 1;nand write c0000000 0 40000;sleep 1;movi read kernel c0000000 ; sleep 1;nand write c0000000 40000 200000;sleep 1;movi read 3600000# 3800000 c0000000;sleep 1;nand write.yaffs c0000000 400000 35db4c0" www.mangoboard.com cafe.naver.com/embeddedcrazyboys CRZ Technology 5
368 #define CONFIG_MMC_BOOTCOMMAND "nand scrub; movi read u-boot C1000000; nand erase 0 40000; nand write C1000000 0 40000; movi read kernel C1000000; nand erase 80000 400000; nand write C 1000000 80000 400000; movi read kernel 0xC0008000; bootm 0xC0008000" 369 370 #define CONFIG_MMC_BOOTARGS "noinitrd console=ttysac1,115200 rw root=/dev/mmcblk0p2 rootfstype=ext3 rootwait" nand scrub 입력시 y 입력안해도되게변경합니다. 418 if (scrub) { 419 skip = argc > 2 &&!strcmp("y", argv[2]); 420 puts("warning: " 421 "scrub option will erase all factory set " 422 "bad blocks!\n" 423 " " 424 "There is no reliable way to recover them.\n" 425 " " 426 "Use this command only for testing purposes " 427 "if you\n" 428 " " 429 "are sure of what you are doing!\n" 430 "\nreally scrub this NAND flash? <y/n>\n"); 431 #if 0 432 if (skip) { 433 opts.scrub = 1; 434 } else if (getc() == 'y' && getc() == '\r') { 435 opts.scrub = 1; 436 } else { 437 puts("scrub aborted\n"); 438 return -1; 439 } 440 } 441 442 #else 443 opts.scrub = 1; 444 #endif 6
변경전 /uboot$ vi include/configs/mango2450.h #define CONFIG_NAND_BOOTCOMMAND "nand read 0xC0008000 0x80000 0x480000;bootm 0xC0008000" 363 #define CONFIG_NAND_BOOTARGS "noinitrd console=ttysac1,115200 rw ubi.mtd=2 root=ubi0:rootfs rootfstype=ubifs rootwait" 364 //#elif defined(config_boot_movinand) 365 //#define CFG_ENV_IS_IN_MOVINAND 366 //#define CONFIG_BOOTCOMMAND "sleep 1;nand scrub ;sleep 1;nand erase;sleep 1;movi read 3800000# 40000 c0000000 ;sleep 1;nand write c0000000 0 40000;sleep 1;movi read kernel c0000000; sleep 1;nand write c0000000 40000 200000;sleep 1;movi read 3600000# 3800000 c0000000;sleep 1;nand write.yaffs c0000000 400000 35db4c0" 367 #define CONFIG_MMC_BOOTCOMMAND "movi read kernel 0xC0008000; bootm 0xC0008000" 368 #define CONFIG_MMC_BOOTARGS "noinitrd console=ttysac1,115200 rw root=/dev/mmcblk0p2 rootfstype=ext3 rootwait" 변경후 /uboot$ vi include/configs/mango2450.h 377 #define CONFIG_NAND_BOOTCOMMAND "nand read 0xC0008000 0x80000 0x480000;bootm 0xC0008000" 378 #define CONFIG_NAND_BOOTARGS "noinitrd console=ttysac1,115200 rw ubi.mtd=2 root=ubi0:rootfs rootfstype=ubifs rootwait" 379 //#elif defined(config_boot_movinand) 380 //#define CFG_ENV_IS_IN_MOVINAND 381 //#define CONFIG_BOOTCOMMAND "sleep 1;nand scrub ;sleep 1;nand erase;sleep 1;movi read 3800000# 40000 c0000000 ;sleep 1;nand write c0000000 0 40000;sleep 1;movi read kernel c0000000 ; sleep 1;nand write c0000000 40000 200000;sleep 1;movi read 3600000# 3800000 c0000000;sleep 1;nand write.yaffs c0000000 400000 35db4c0" 382 #define CONFIG_MMC_BOOTCOMMAND "nand scrub; movi read u-boot C1000000; nand erase 0 40000; nand write C1000000 0 40000; movi read kernel C1000000; nand erase 80000 400000; nand write C 1000000 80000 400000; movi read kernel 0xC0008000; bootm 0xC0008000" 383 384 #define CONFIG_MMC_BOOTARGS "noinitrd console=ttysac1,115200 rw root=/dev/mmcblk0p2 rootfstype=ext3 rootwait" www.mangoboard.com cafe.naver.com/embeddedcrazyboys CRZ Technology 7
S99_build_system.sh 를추가하였습니다. /image/rootfs/etc/init.d$ vi S99_build_system.sh 1 #!/bin/sh 2 3 echo "Start nand boot ubifs filesystem..." 4 mkdir -p /mnt/nand 5 6 flash_erase /dev/mtd2 0 0 7 echo "[Step 1] mtd2 flash_erase done..." 8 9 ubiattach /dev/ubi_ctrl -m 2 10 echo "[Step 2] mtd2 ubiattach done..." 11 12 ubimkvol /dev/ubi0 -N rootfs -m 13 echo "[Step 3] mtd2 ubimkvol done..." 14 15 mount -t ubifs ubi0:rootfs /mnt/nand 16 echo "[Step 4] mount done..." 17 18 tar xvf /root/ /rootfs.tar -C /mnt/nand 19 echo "[Step 5] file copy done..." 20 21 sleep 2 22 23 umount /mnt/nand 24 echo "[Step 6] umount done..." 25 26 echo "Complete nand boot ubifs filesystem..." 27 28 sleep 1 rootfs/etc/init.d $ cd../../ rootfs $ tar cf../rootfs.tar * sd 카드를컴퓨터에연결후 dmesg tail 명령어로 sd카드인식확인 image$./sdwriter_sdhc sdb 24 sd 카드에이미지를라이트합니다. image$ cd rootfs/etc/init.d/ 8
init.d$ rm -rf S99_build_system.sh image/rootfs/etc/init.d$ cd../.. rootfs $ tar cf../rootfs2.tar * Mango24R2 의 DRAM 이 64MB 입니다. yaffs2 의용량을확인하면 64MB 를훌쩍넘어서 UBIFS 를사용했습니다. mango24r2에삽입되어있던 sd카드를빼서 sd카드를리눅스 pc에삽입합니다. fdisk -l 을입력합니다. 개인에맞게 sdc1 sdc2 가보입니다. sdc1은이전에 sdwrie할때사용한것으로 sdc2를사용합니다. mkdir /home/usb sudo chmod 755 /home/usb 마운트할곳을만들고권한설정해줍니다. sudo mount /dev/sdc2 /home/usb 마운트해주고 sudo cp rootfs2.tar /home/usb/root/rootfs.tar sudo umount /home/usb sd카드를빼서보드에삽입후 sd부트로바꿔서부팅 (3 ON) 난드부팅 (3, 5, 6 ON) 합니다. 2. key1,2 로 7 inch, 10.4 inch LCD 선택하여 NAND flash write key1 을누르고부팅시 7 인치 LCD 용커널이미지를라이트하도록하겠습니다. www.mangoboard.com cafe.naver.com/embeddedcrazyboys CRZ Technology 9
매뉴얼을보면 10
GPFCON 으로 Input, Output, EINT, Reserved 모드를결정합니다. 195 #define GPFCON_OFFSET 0x50 196 #define GPFDAT_OFFSET 0x54 197 #define GPFPU_OFFSET 0x58 268 #define GPFCON (0x56000050) 269 #define GPFDAT (0x56000054) 270 #define GP (0x56000058) 341 #define GPFCON_REG REG(0x56000050) 342 #define GPFDAT_REG REG(0x56000054) 343 #define GPFPU_REG REG(0x56000058) www.mangoboard.com cafe.naver.com/embeddedcrazyboys CRZ Technology 11
아래와같이키테스트를합니다. key1을누르고부팅시 key1이출력되고 key2를누르고부팅시 key2 가출력됩니다. 27 #define KEY01 0x2 28 #define KEY02 0x1 29 30 int key_test(void) 70 int board_init(void) 71 { 72 DECLARE_GLOBAL_DATA_PTR; 73 74 usb_pre_init(); 75 smsc9220_pre_init(); 76 77 gd->bd->bi_arch_number = MACH_TYPE; 78 gd->bd->bi_boot_params = (PHYS_SDRAM_1+0x100); 79 key_test(); 80 return 0; 81 }. 98 #if 1//key test 99 int key_test(void) 100 { 101 GPFCON_REG &=0x00; 102 103 104 if((gpfdat_reg&0x3)==key01) 105 { 106 printf("key1"); 107 } 108 else if((gpfdat_reg &0x3)==KEY02) 109 { 110 printf("key2"); 111 } 112 113 } 114 #endif 12
아래와같이 7inch LCD용과 10.4inch LCD용 bootcommand를정의합니다. uboot$ vi include/configs/mango2450.h 363 #define CONFIG_NAND_BOOTCOMMAND "nand read 0xC0008000 0x80000 0x500000;bootm 0xC0008000" 364 #define CONFIG_NAND_BOOTARGS "noinitrd console=ttysac1,115200 rw ubi.mtd=2 root=ubi0:rootfs rootfstype=ubifs rootwait" 365 //#elif defined(config_boot_movinand) 366 //#define CFG_ENV_IS_IN_MOVINAND 367 //#define CONFIG_BOOTCOMMAND "sleep 1;nand scrub ;sleep 1;nand erase;sleep 1;movi read 3800000# 40000 c0000000 ;sleep 1;nand write c0000000 0 40000;sleep 1;movi read kernel c0000000 ; sleep 1;nand write c0000000 40000 200000;sleep 1;movi read 3600000# 3800000 c0000000;sleep 1;nand write.yaffs c0000000 400000 35db4c0" 368 #define CONFIG_MMC_BOOTCOMMAND " movi read kernel 0xC0008000; bootm 0xC0008000" 369 370 #define CONFIG_MMC_BOOTARGS "noinitrd console=ttysac1,115200 rw root=/dev/mmcblk0p2 rootfstype=ext3 rootwait" 371 372 #define CONFIG_MMC_7inch_LCD_BOOTCOMMAND "nand scrub; movi read u-boot C1000000; nand erase 0 40000; nand write C1000000 0 40000; nand erase 80000 500000; movi read 15622094 4FFFFF c0000000; c0 000000; nand write c0000000 80000 500000; movi read kernel 0xC0008000; bootm 0xC0008000" 373 374 #define CONFIG_MMC_10_4inch_LCD_BOOTCOMMAND "nand scrub; movi read u-boot C1000000; nand erase 0 40000; nand write C1000000 0 40000; movi read kernel C1000000; nand erase 80000 400000; nand write C 1000000 80000 400000; movi read kernel 0xC0008000; bootm 0xC0008000" 위에서두껍게표시한 15622094 이값은변할수도있습니다. 동일한 8GB SD카드는상관없으나다른 SD카드에서는값이변경됩니다. 아래에서 SD Write할때설명하겠습니다. /uboot$ vi lib_arm/board.c 63 #define KEY01 0x2 64 #define KEY02 0x1.. 565 #if 1 /* Delete this code for NFS */ 566 /* by CRZ, boot cmd, args setting */ 567 GPFCON_REG &=0x00; 568 569 if((gpcdat_reg & 0xA0) == 0xA0) www.mangoboard.com cafe.naver.com/embeddedcrazyboys CRZ Technology 13
570 { 571 setenv("bootcmd", CONFIG_NAND_BOOTCOMMAND); 572 setenv("bootargs", CONFIG_NAND_BOOTARGS); 573 } 574 else 575 { 576 if((gpfdat_reg&0x3)==key01) 577 { 578 printf("push key1\n7inch LCD image write \n"); 579 setenv("bootcmd", CONFIG_MMC_7inch_LCD_BOOTCOMMAND); 580 setenv("bootargs", CONFIG_MMC_BOOTARGS); 581 } 582 else if((gpfdat_reg&0x3)==key02) 583 { 584 printf("push key2\n10.4inch LCD image write \n") 585 setenv("bootcmd", CONFIG_MMC_10_4inch_LCD_BOOTCOMMAND); 586 setenv("bootargs", CONFIG_MMC_BOOTARGS); 587 } 588 else 589 { 590 setenv("bootcmd", CONFIG_MMC_BOOTCOMMAND); 591 setenv("bootargs", CONFIG_MMC_BOOTARGS); 592 } 593 } 594 #endif zimage가기본이 10.4인치 LCD용이미지입니다. image$ vi sdwriter_sdhc 12 KERNEL_NAME=zImage 13 KERNEL_7_NAME=zImage_7inch 74 OFFSET_KERNEL7=$(($OFFSET_KERNEL-$SIZEOF_KERNEL)) 170 echo -n "OFFSET_KERNEL7 : $OFFSET_KERNEL7 " 171 dd bs=512 seek=$offset_kernel7 if=$kernel_7_name of=$tflash > /dev/null 2>&1 172 print_success "$?" 14
/image$ sudo./sdwriter_sdhc sdb 24 [sudo] password for ubuntu: no talloc stackframe at../source3/param/loadparm.c:4864, leaking memory WARNING: Ignoring invalid value 'share' for parameter 'security' Ignoring unknown parameter "display charset" Mango SD Writer V1.0 TFLASH_SECTORS: 15644672 START_ROOTFS=13508606 Unmount all : success Partition Create : success Write Mango24R2 Signature OFFSET_SIGNATURE_24: 15643646 success OFFSET_BL1: 15643630 Write Mango24R2 BL1 : success OFFSET_BL2: 15642574 Write Mango24R2 Uboot : success OFFSET_KERNEL: 15632334 Write Mango24 Kernel : success OFFSET_KERNEL7 : 15622094 success Linux Filesystem Create : success Unmount all : success Success 이위에서 SD카드에따라서변경될수도있는값을여기서확인합니다. 위에서두껍게표시한 OFFSET_KERNEL7 : 15622094 success 이값을사용하여 uboot$ vi include/configs/mango2450.h << 이부분의값을변경하면됩니다. rootfs.tar를 sd카드에복사해야합니다. rootfs.tar와 rootfs2.tar의차이는 /etc/init.d에 S99_build_system.sh 가있고없고의차이입니다. sdwriter_sdhc에서는 rootfs.tar를사용하여 S99_build_system.sh 스크립트를사용합니다. NAND 부팅을하기위해 NAND flash에 ubifs 를사용하여 filesystem을 write합니다. 스크립트에서사용하는 filesystem은 rootfs2.tar입니다. www.mangoboard.com cafe.naver.com/embeddedcrazyboys CRZ Technology 15
rootfs2.tar는 /etc/init.d에 S99_build_system.sh 스크립트를제거하였습니다. sd write 후아래와같이명령어를입력합니다. image$ sudo mount /dev/sdb2 /home/usb image$ sudo cp rootfs2.tar /home/usb/root/rootfs.tar image$ sudo umount /home/usb 이부분을 sdwriter_sdhc에추가하였습니다. 199 nand_boot_ubifs_filesystem() 200 { 201 echo -n "Start nand_boot_ubifs_filesystem " 202 sudo mkdir /home/usb 203 sudo chmod 755 /home/usb 204 sudo mount "$TFLASH"2 /home/usb 205 sudo cp rootfs2.tar /home/usb/root/rootfs.tar 206 sudo umount /home/usb 207 } 이제위에명령어를입력안하고 sudo./sdwriter_sdhc sdb 24 이렇게입력하여 sdcard를 write하면됩니다. 3. LCD 화면에 writing, write 완료이미지출력하기 NAND FLASH에라이트후이미지를띄우기위해 rootfs 수정아래와같이추가 /etc/init.d$ vi S99_build_system.sh /bin/sh /root/bmp_output.sh /root$ vi bmp_output.sh 1 #!/bin/sh 2 export PATH=/usr/bin/:/sbin:$PATH 3 4 /root/bmp_reader i /root/bmp/all_ok.bmp bmp_reader를파일시스템에 root안에복사합니다. cp bmp_reader root/ /etc/init.d$ vi S01logging /bin/sh /root/bmp_output_writing.sh 16
root$ vi bmp_output_writing.sh 1 #!/bin/sh 2 export PATH=/usr/bin/:/sbin:$PATH 3 4 /root/bmp_reader i /root/bmp/file_ing.bmp 권한을설정합니다. sudo chmod 755 bmp_output_writing.sh bmp_output.sh NAND flash 에라이팅중에는 LCD 화면에아래이미지출력하였습니다. NAND flash 에 write 후에는 LCD 화면에아래이미지출력하였습니다. 4. 추가변경사항 기본부팅을 10.4inch LCD 에서 7inch LCD 로변경하였습니다. 4.1. 커널수정 /image$ vi sdwriter_sdhc_test_touch_ethernet_usb www.mangoboard.com cafe.naver.com/embeddedcrazyboys CRZ Technology 17
KERNEL_10_4_NAME=zImage_10.4inch KERNEL_7_NAME=zImage_7inch ROOTFS_NAME=rootfs_test_touch_ethernet_usb.tar. case "$BOARD" in 24) SIZEOF_SIGNATURE=1026 # SIZEOF_SIGNATURE=2 OFFSET_SIGNATURE_24=$(($TFLASH_SECTORS-$SIZEOF_SIGNATURE)) SIZEOF_BL1=16 OFFSET_BL1=$(($OFFSET_SIGNATURE_24-$SIZEOF_BL1)) #u-boot(1024x512) +env(32x512) SIZEOF_BL2=1056 OFFSET_BL2=$(($OFFSET_BL1-$SIZEOF_BL2)) SIZEOF_KERNEL7=10240 OFFSET_KERNEL7=$(($OFFSET_BL2-$SIZEOF_KERNEL7)) SIZE_FAT=$(($TFLASH_SECTORS-$SIZE_BINARY-$SIZE_ROOTFS-2)) OFFSET_KERNEL_10_4=$(($OFFSET_KERNEL7-$SIZEOF_KERNEL7)) START_FAT=2048 START_ROOTFS=$(($START_FAT+$SIZE_FAT)) echo "START_ROOTFS=$START_ROOTFS" ;;. write_bin() { case "$BOARD" in 24) echo echo -n "Write Mango24R2 Signature" echo -n " OFFSET_SIGNATURE_24: $OFFSET_SIGNATURE_24 " dd bs=512 seek=$offset_signature_24 if=$m24_signature of=$tflash > /dev/null 2>&1 print_success "$?" 18
echo -n " OFFSET_BL1: $OFFSET_BL1 " echo -n "Write Mango24R2 BL1 : " dd bs=512 seek=$offset_bl1 if=$bl1_name of=$tflash > /dev/null 2>&1 print_success "$?" echo -n " OFFSET_BL2: $OFFSET_BL2 " echo -n "Write Mango24R2 Uboot : " dd bs=512 seek=$offset_bl2 if=$uboot_name of=$tflash > /dev/null 2>&1 print_success "$?" 2>&1 echo -n "OFFSET_KERNEL7 : $OFFSET_KERNEL7 " echo -n "Write Mango24 Kernel : " dd bs=512 seek=$offset_kernel7 if=$kernel_7_name of=$tflash > /dev/null print_success "$?" echo -n " OFFSET_KERNEL_10_4: $OFFSET_KERNEL_10_4 " dd bs=512 seek=$offset_kernel_10_4 if=$kernel_10_4_name of=$tflash > /dev/null 2>&1 print_success "$?" ;; } *) echo "Make Bootloader and Kernel: Error!!!" ;; esac 4.2. u-boot 수정 #define CONFIG_MMC_BOOTCOMMAND " movi read kernel 0xC0008000; bootm 0xC0008000" www.mangoboard.com cafe.naver.com/embeddedcrazyboys CRZ Technology 19
#define CONFIG_MMC_BOOTARGS "noinitrd console=ttysac1,115200 rw root=/dev/mmcblk0p2 rootfstype=ext3 rootwait" #define CONFIG_MMC_10_4inch_LCD_BOOTCOMMAND "nand scrub; movi read u-boot C0000000; nand erase 0 40000; nand write C0000000 0 40000; nand erase 80000 500000; movi read 15501262 4FFFFF c0000000; nand write c0000000 80000 500000; movi read kernel 0xC0008000; bootm 0xC0008000" #define CONFIG_MMC_7inch_LCD_BOOTCOMMAND "nand scrub; movi read u-boot C0000000; nand erase 0 40000; nand write C0000000 0 40000; movi read kernel C0000000; nand erase 80000 400000; nand write C0000000 80000 400000; movi read kernel 0xC0008000; bootm 0xC0008000" 20