| 1 | ␉␉␊ |
| 2 | ␉␉JZ Linux 2.6 Kernel Release␊ |
| 3 | ␊ |
| 4 | ␉␉ (Updated: 2008-05-20)␊ |
| 5 | ␊ |
| 6 | ␊ |
| 7 | ---------------␊ |
| 8 | * Quick Start *␊ |
| 9 | ---------------␊ |
| 10 | ␊ |
| 11 | To build linux 2.6, you needs a mipsel-linux-gcc version 4. Please␊ |
| 12 | download it from Ingenic website http://www.ingenic.cn.␊ |
| 13 | ␊ |
| 14 | You should have downloaded the linux-2.6.24.3.tar.bz2 and the latest kernel ␊ |
| 15 | patch. The patch file was named as "linux-2.6.24.3-jz-yyyymmdd.patch.gz".␊ |
| 16 | ␊ |
| 17 | Follow next steps to install the full kernel source:␊ |
| 18 | ␊ |
| 19 | $ tar -xjf linux-2.6.24.3.tar.bz2␊ |
| 20 | $ cd linux-2.6.24.3␊ |
| 21 | $ gzip -cd ../linux-2.6.24.3-jz-yyyymmdd.patch.gz | patch -p1␊ |
| 22 | ␊ |
| 23 | Now you can configure and build the kernel.␊ |
| 24 | ␊ |
| 25 | First, you need to do a 'make board_defconfig' to select a board.␊ |
| 26 | ␊ |
| 27 | For example:␊ |
| 28 | ␊ |
| 29 | - make pavo_defconfig␉ # JZ4740 PAVO board default configuration␊ |
| 30 | - make pmp_defconfig # JZ4730 PMP ver 2.x board default configuration␊ |
| 31 | - make dipper_defconfig # JZ4725 PMP ver 1.x board default configuration␊ |
| 32 | ␊ |
| 33 | Then, configure and compile the kernel:␊ |
| 34 | ␊ |
| 35 | - make xconfig or make menuconfig, if you want to change the configuration.␊ |
| 36 | - make, make uImage, or make zImage, to build the kernel.␊ |
| 37 | ␊ |
| 38 | The ELF format kernel image is linux-2.6.24.3/vmlinux.␊ |
| 39 | The U-Boot format kernel image is linux-2.6.24.3/arch/mips/boot/uImage.␊ |
| 40 | The compressed raw kernel image is linux-2.6.24.3/arch/mips/boot/compressed/zImage.␊ |
| 41 | ␊ |
| 42 | ␊ |
| 43 | -------------------------------␊ |
| 44 | * Supported SOC and Platforms *␊ |
| 45 | -------------------------------␊ |
| 46 | ␊ |
| 47 | This release supports several platforms based on JZ4730 and JZ4740.␊ |
| 48 | ␊ |
| 49 | JZ4740 based platforms:␊ |
| 50 | ␊ |
| 51 | - pavo: JZ4740 reference board␊ |
| 52 | - leo: JZ4740 development board␊ |
| 53 | ␊ |
| 54 | JZ4730 based platforms:␊ |
| 55 | ␊ |
| 56 | - pmp: JZ4730 reference board version 2.x␊ |
| 57 | ␊ |
| 58 | JZ4725 based platforms:␊ |
| 59 | ␊ |
| 60 | - dipper: JZ4725 reference board version 1.x␊ |
| 61 | ␊ |
| 62 | ␊ |
| 63 | ---------------------------␊ |
| 64 | * Overview of source tree *␊ |
| 65 | ---------------------------␊ |
| 66 | ␊ |
| 67 | - Changelog␉␉␉: Revision history␊ |
| 68 | - README-JZ␉␉␉: This file␊ |
| 69 | - arch/mips/␊ |
| 70 | - kernel/␉␉␉: MIPS kernel common code␊ |
| 71 | - mm/␉␉␉: MIPS memory common code␊ |
| 72 | - jz4730/␉␉␉: JZ4730 code␊ |
| 73 | - jz4740/␉␉␉: JZ4740 JZ4725 JZ4720 code␊ |
| 74 | - configs/␊ |
| 75 | - pavo_defconfig␉: jz4740 based pavo default configuration␊ |
| 76 | - pmp_defconfig␉: jz4730 based pmp default configuration␊ |
| 77 | - dipper_defconfig␉: jz4725 based dipper default configuration␊ |
| 78 | - include/asm-mips/␉␉: MIPS asm common include␊ |
| 79 | - jzsoc.h␉␉␉: JZ SoC common include␊ |
| 80 | - mach-jz4730/␉␉: JZ4730 SoC headers␊ |
| 81 | - mach-jz4740/␉␉: JZ4740 JZ4725 JZ4720 SoC headers␊ |
| 82 | - fs/␊ |
| 83 | - jffs2/␉␉␉: JFFS2 file system␊ |
| 84 | - yaffs2/␉␉␉: YAFFS2 file system␊ |
| 85 | - utils/␉␉: YAFFS2 utilities, like mkyaffs2image␊ |
| 86 | - ubifs/␉␉␉: ubifs file system␊ |
| 87 | - mkfs.ubifs/␉␉: mkfs.ubifs util to create UBIFS␊ |
| 88 | - sound/␊ |
| 89 | oss/␉␉␉: OSS audio driver␊ |
| 90 | soc/jz4740/␉␉: JZ4740 ALSA audio driver␊ |
| 91 | - drivers/␊ |
| 92 | - char/␊ |
| 93 | - serial.c␉␉: serial port driver␊ |
| 94 | - rtc_pcf8563.c␉: PCF8563 RTC driver␊ |
| 95 | - rtc_jz.c␉␉: JZSOC On-Chip RTC driver␊ |
| 96 | - jzchar/␉␉: jzchar devices␊ |
| 97 | ␉ - jz_ts.c␉␉: generic touch screen driver␊ |
| 98 | ␉ - sadc.c␉␉: JZ4740 SADC driver␊ |
| 99 | - ak4182.c␉␉: AK4182 touch driver␊ |
| 100 | ␉ - udc_hotplug.c␉: UDC hotplug management␊ |
| 101 | ␉ - poweroff.c␉: suspend/poweroff management␊ |
| 102 | - input/keyboard/␊ |
| 103 | - jz_keypad.c : scan keypad driver␊ |
| 104 | - gpio_keys.c : gpio keypad driver␊ |
| 105 | - media/video/␊ |
| 106 | ␉ - jz_cim.c␉␉: generic camera driver␊ |
| 107 | ␉ - jz_sensor.c␉␉: generic sensor driver␊ |
| 108 | - mmc/host/␊ |
| 109 | ␉ - jz_mmc.c␉␉: jz mmc/sd card driver␊ |
| 110 | - mtd/␊ |
| 111 | - mtdblock-jz.c␉: NAND Flash translation layer driver␊ |
| 112 | - nand/␊ |
| 113 | - nand_base.c␉: NAND flash interface to MTD␊ |
| 114 | - jz4730_nand.c␉: NAND flash definition on JZ4730 boards␊ |
| 115 | - jz4740_nand.c␉: NAND flash definition on JZ4740 boards␊ |
| 116 | - ubi/␉␉: MTD utilities like flash_eraseall, nandwrite etc.␊ |
| 117 | - ubiblk.c␉␉: UBI block layer driver on top of UBI␊ |
| 118 | - mtd-utils/␉␉: MTD and UBI utilities, like flash_eraseall, nandwrite and ubimkvol etc.␊ |
| 119 | - ubi-utils␉: UBI utils like ubimkvol/ubirmvol/ubinize etc.␊ |
| 120 | - net/␊ |
| 121 | - jz_eth.c␉␉: JZ4730 On-Chip ethernet driver␊ |
| 122 | - jzcs8900a.c␉␉: cs8900a ethernet driver␊ |
| 123 | - serial/␊ |
| 124 | ␉ - 8250.c␉␉: standard 16550A serial driver␊ |
| 125 | - usb/␉␉␉: USB OHCI host driver␊ |
| 126 | ␉ - usb/host/␊ |
| 127 | ␉ ohci-jz.c␉␉: JZ OHCI driver␊ |
| 128 | - usb/gadget/␊ |
| 129 | - jz4730_udc.c␉: JZ4730 UDC low-level driver␊ |
| 130 | - jz4740_udc.c␉: JZ4740 UDC low-level driver␊ |
| 131 | - file_storage.c␉: USB mass storage class driver␊ |
| 132 | - serial.c␉␉: USB serial class driver␊ |
| 133 | - video/␊ |
| 134 | - jzlcd.c␉␉: JZ LCD controller framebuffer driver␊ |
| 135 | - jzslcd.c␉␉: JZ Smart LCD controller framebuffer driver␊ |
| 136 | - watchdog/␊ |
| 137 | ␉ - jz_wdt.c␉␉: JZ On-Chip watchdog driver␊ |
| 138 | ␊ |
| 139 | ␊ |
| 140 | -------------------------␊ |
| 141 | * NAND Flash Filesystem *␊ |
| 142 | -------------------------␊ |
| 143 | ␊ |
| 144 | NAND Flash is the main non-volatile storage for most embedded devices. ␊ |
| 145 | So, it's very important to implement a stable and reasonable filesystem on␊ |
| 146 | NAND flash.␊ |
| 147 | ␊ |
| 148 | In Linux, the MTD subsystem provides a common interface for operating with␊ |
| 149 | many flash devices, such as NOR, NAND etc.␊ |
| 150 | ␊ |
| 151 | Above MTD layer, we can implement the YAFFS2 filesystem. Or we can implement␊ |
| 152 | a MTD block device, on top of it we can implement the general filesystem␊ |
| 153 | such as FAT and EXT2.␊ |
| 154 | ␊ |
| 155 | The Linux 2.6 kernel also implements the UBI (Unsorted Block Images). UBI␊ |
| 156 | is a software layer above MTD layer which admits of LVM-like logical volumes␊ |
| 157 | on top of MTD devices, hides some complexities of flash chips like wear ␊ |
| 158 | and bad blocks and provides some other useful capabilities. Please, consult␊ |
| 159 | the MTD web site for more details (www.linux-mtd.infradead.org).␊ |
| 160 | ␊ |
| 161 | On top of UBI, we can implement the UBIFS filesystem. We can also emulate ␊ |
| 162 | block devices above UBI, such that we can use the general filesystem such as␊ |
| 163 | FAT and EXT2 on it.␊ |
| 164 | ␊ |
| 165 | The architecture of the NAND flash filesystem is illustrated as below:␊ |
| 166 | ␊ |
| 167 | ␊ |
| 168 | ␊ |
| 169 | +-----------+ +-------------+ +-------------+␊ |
| 170 | | YAFFS2 | | UBIFS | | FAT or EXT2 |␉Filesystems␊ |
| 171 | +-----------+ +-------------+ +-------------+␊ |
| 172 | \ | / \␊ |
| 173 | \ | / \␊ |
| 174 | \ | / \␊ |
| 175 | \ | +-----------------+ +-----------------+␊ |
| 176 | \ | | UBI Block Layer | | MTD Block Layer |␊ |
| 177 | \ | +-----------------+ +-----------------+␊ |
| 178 | \ | / /␊ |
| 179 | \ | / /␊ |
| 180 | \ +-------------+ /␊ |
| 181 | \ | UBI | /␊ |
| 182 | \ +-------------+ /␊ |
| 183 | \ | /␊ |
| 184 | +-------------------------------------------+␊ |
| 185 | | MTD |␊ |
| 186 | +-------------------------------------------+␊ |
| 187 | |␊ |
| 188 | +--------------------+␊ |
| 189 | | nand_base.c |␊ |
| 190 | +--------------------+␊ |
| 191 | |␊ |
| 192 | +--------------------+␊ |
| 193 | | jz4740_nand.c |␊ |
| 194 | +--------------------+␊ |
| 195 | ␊ |
| 196 | ␊ |
| 197 | The related source codes are listed below:␊ |
| 198 | ␊ |
| 199 | fs/yaffs2:␉␉␉YAFFS2␊ |
| 200 | fs/ubifs:␉␉␉UBIFS␊ |
| 201 | fs/fat:␉␉␉␉FAT␊ |
| 202 | fs/ext2:␉␉␉EXT2␊ |
| 203 | drivers/mtd:␉␉␉MTD␊ |
| 204 | drivers/mtd/ubi:␉␉UBI␊ |
| 205 | drivers/mtd/ubi/ubiblk.c:␉UBI Block Layer␊ |
| 206 | drivers/mtd/mtdblock-jz.c:␉MTD Block Layer␊ |
| 207 | drivers/mtd/mtd-utils:␉␉MTD and UBI utils (flash_eraseall/ubimkvol/ubinfo/ubinize etc.)␊ |
| 208 | fs/ubifs/mkfs.ubifs:␉␉UBIFS util to create ubifs image (mkfs.ubifs)␊ |
| 209 | fs/yaffs2/util:␉␉␉YAFFS2 util (mkyaffs2image)␊ |
| 210 | ␊ |
| 211 | To build mtd utils, go to drivers/mtd/mtd-utils, type 'make' and␊ |
| 212 | 'make install DESTDIR=/nfsroot/root26'.␊ |
| 213 | ␊ |
| 214 | To build yaffs2 util, go to fs/yaffs2/utils and type 'make'.␊ |
| 215 | ␊ |
| 216 | To build ubifs util, go to fs/ubifs/mkfs.ubifs and type 'make'.␊ |
| 217 | ␊ |
| 218 | Except 'UBI Block Layer' and 'MTD Block Layer', which are implement by Ingenic␊ |
| 219 | ourself, the others are general in the linux kernel tree.␊ |
| 220 | ␊ |
| 221 | User can select any one of these drivers to implement the filesystem. It all␊ |
| 222 | depends on yourself.␊ |
| 223 | ␊ |
| 224 | Following sections will describe how to use these drivers in details.␊ |
| 225 | ␊ |
| 226 | ␊ |
| 227 | ----------------------------------␊ |
| 228 | * UBI, UBIFS and UBI Block Layer *␊ |
| 229 | ----------------------------------␊ |
| 230 | ␊ |
| 231 | UBIFS is a new flash file system which is designed to work on top of UBI. ␊ |
| 232 | ␊ |
| 233 | Here is a short and unsorted list of some of UBIFS features:␊ |
| 234 | ␊ |
| 235 | * write-back support - This dramatically improves the throughput of the ␊ |
| 236 | file-system comparing to JFFS2, which is write-through; ␊ |
| 237 | ␊ |
| 238 | * fast mount time␊ |
| 239 | ␊ |
| 240 | * tolerance to unclean reboots - UBIFS is a journaling file system and it ␊ |
| 241 | tolerates sudden crashes and unclean reboots;␊ |
| 242 | ␊ |
| 243 | * fast I/O - even with write-back disabled;␊ |
| 244 | ␊ |
| 245 | * on-the-flight compression - the data is stored in compressed form on ␊ |
| 246 | the flash media, which makes it possible to put considerably more data to␊ |
| 247 | the flash as if the data would not be compressed;␊ |
| 248 | ␊ |
| 249 | Please, consult the MTD web site for more details (www.linux-mtd.infradead.org).␊ |
| 250 | ␊ |
| 251 | The UBI and UBIFS can be compiled as modules or built into the kernel.␊ |
| 252 | ␊ |
| 253 | To enable UBI, you need to select following configurations:␊ |
| 254 | ␊ |
| 255 | CONFIG_MTD_UBI:␉␉␉Enable UBI␊ |
| 256 | CONFIG_MTD_UBI_WL_THRESHOLD:␉UBI wear-leveling threshold␊ |
| 257 | CONFIG_MTD_UBI_BEB_RESERVE:␉Percentage of reserved eraseblocks for bad eraseblocks handling␊ |
| 258 | ␊ |
| 259 | To enable 'UBI Block Layer', you need to select following configurations:␊ |
| 260 | ␊ |
| 261 | CONFIG_MTD_UBI_BLKDEVS:␉␉Common interface to block layer for UBI␊ |
| 262 | CONFIG_MTD_UBI_BLOCK:␉␉Emulate block devices␊ |
| 263 | ␊ |
| 264 | To enable UBIFS, you need to select following configurations:␊ |
| 265 | ␊ |
| 266 | CONFIG_UBIFS_FS:␉␉UBIFS file system support␊ |
| 267 | CONFIG_UBIFS_COMPRESSION_OPTIONS:␉Advanced compression options for UBIFS␊ |
| 268 | CONFIG_UBIFS_LZO:␉␉UBIFS LZO compression support␊ |
| 269 | CONFIG_UBIFS_ZLIB:␉␉UBIFS ZLIB compression support␊ |
| 270 | CONFIG_UBIFS_FS_DEBUG:␉␉UBIFS debugging␊ |
| 271 | ␊ |
| 272 | If you want to compile as modules, take next steps:␊ |
| 273 | ␊ |
| 274 | Type 'make modules' to compile the modules.␊ |
| 275 | ␊ |
| 276 | Type 'make modules_install INSTALL_MOD_PATH=/nfsroot/root26' to install the␊ |
| 277 | modules to the target root.␊ |
| 278 | ␊ |
| 279 | You also need to compile the MTD and UBIFS utilities and install them to the␊ |
| 280 | target root.␊ |
| 281 | ␊ |
| 282 | ␊ |
| 283 | Now boot your board and mounted root FS with these modules, and below is a␊ |
| 284 | simple guide to test and use the UBIFS and 'UBI Block Layer':␊ |
| 285 | ␊ |
| 286 | Here we will create UBI volumes on mtd5.␊ |
| 287 | ␊ |
| 288 | First, format mtd5:␊ |
| 289 | ␊ |
| 290 | # flash_eraseall /dev/mtd5␊ |
| 291 | Erasing 256 Kibyte @ 1ffc0000 -- 99 % complete.␊ |
| 292 | ␊ |
| 293 | Install UBI module, attached it to mtd5:␊ |
| 294 | ␊ |
| 295 | # modprobe ubi mtd=5␊ |
| 296 | UBI: empty MTD device detected␊ |
| 297 | UBI: create volume table (copy #1)␊ |
| 298 | UBI: create volume table (copy #2)␊ |
| 299 | UBI: attached mtd5 to ubi0␊ |
| 300 | UBI: MTD device name: "NAND VFAT partition"␊ |
| 301 | UBI: MTD device size: 512 MiB␊ |
| 302 | UBI: physical eraseblock size: 262144 bytes (256 KiB)␊ |
| 303 | UBI: logical eraseblock size: 258048 bytes␊ |
| 304 | UBI: number of good PEBs: 2048␊ |
| 305 | UBI: number of bad PEBs: 0␊ |
| 306 | UBI: smallest flash I/O unit: 2048␊ |
| 307 | UBI: VID header offset: 2048 (aligned 2048)␊ |
| 308 | UBI: data offset: 4096␊ |
| 309 | UBI: max. allowed volumes: 128␊ |
| 310 | UBI: wear-leveling threshold: 4096␊ |
| 311 | UBI: number of internal volumes: 1␊ |
| 312 | UBI: number of user volumes: 0␊ |
| 313 | UBI: available PEBs: 2024␊ |
| 314 | UBI: total number of reserved PEBs: 24␊ |
| 315 | UBI: number of PEBs reserved for bad PEB handling: 20␊ |
| 316 | UBI: max/mean erase counter: 0/0␊ |
| 317 | UBI: background thread "ubi_bgt0d" started, PID 241␊ |
| 318 | ␊ |
| 319 | Now, create two UBI volumes, one is called ubifs and size is 200MB, the␊ |
| 320 | other is called vfat and size is 298MB.␊ |
| 321 | ␊ |
| 322 | # ubimkvol /dev/ubi0 -s 200MiB -N ubifs␊ |
| 323 | Volume ID 0, size 813 LEBs (209793024 bytes, 200.1 MiB), LEB size 258048 bytes (252.0 KiB), dynamic, name "ubifs", alignment 1␊ |
| 324 | # ubimkvol /dev/ubi0 -s 298MiB -N vfat ␊ |
| 325 | Volume ID 1, size 1211 LEBs (312496128 bytes, 298.0 MiB), LEB size 258048 bytes (252.0 KiB), dynamic, name "vfat", alignment 1␊ |
| 326 | ␊ |
| 327 | Then you can use 'ubinfo' to query the UBI volume info:␊ |
| 328 | ␊ |
| 329 | # ubinfo -a␊ |
| 330 | UBI version: 1␊ |
| 331 | Count of UBI devices: 1␊ |
| 332 | UBI control device major/minor: 10:63␊ |
| 333 | Present UBI devices: ubi0␊ |
| 334 | ␊ |
| 335 | ubi0:␊ |
| 336 | Volumes count: 2␊ |
| 337 | Logical eraseblock size: 258048␊ |
| 338 | Total amount of logical eraseblocks: 2048 (528482304 bytes, 504.0 MiB)␊ |
| 339 | Amount of available logical eraseblocks: 0 (0 bytes)␊ |
| 340 | Maximum count of volumes 128␊ |
| 341 | Count of bad physical eraseblocks: 0␊ |
| 342 | Count of reserved physical eraseblocks: 20␊ |
| 343 | Current maximum erase counter value: 3␊ |
| 344 | Minimum input/output unit size: 2048 bytes␊ |
| 345 | Character device major/minor: 252:0␊ |
| 346 | Present volumes: 0, 1␊ |
| 347 | ␊ |
| 348 | Volume ID: 0 (on ubi0)␊ |
| 349 | Type: dynamic␊ |
| 350 | Alignment: 1␊ |
| 351 | Size: 813 LEBs (209793024 bytes, 200.1 MiB)␊ |
| 352 | State: OK␊ |
| 353 | Name: ubifs␊ |
| 354 | Character device major/minor: 252:1␊ |
| 355 | -----------------------------------␊ |
| 356 | Volume ID: 1 (on ubi0)␊ |
| 357 | Type: dynamic␊ |
| 358 | Alignment: 1␊ |
| 359 | Size: 1211 LEBs (312496128 bytes, 298.0 MiB)␊ |
| 360 | State: OK␊ |
| 361 | Name: vfat␊ |
| 362 | Character device major/minor: 252:2␊ |
| 363 | ␊ |
| 364 | ␊ |
| 365 | It shows that we have successfully created two UBI volumes (Volume ID 0 and 1)␊ |
| 366 | on ubi0.␊ |
| 367 | ␊ |
| 368 | Now you can install the UBIFS and 'UBI Block Layer' modules and create␊ |
| 369 | UBIFS and FAT on UBI volume 0 and 1 respectively.␊ |
| 370 | ␊ |
| 371 | # modprobe ubifs␊ |
| 372 | # modprobe ubiblk␊ |
| 373 | ␊ |
| 374 | # lsmod␊ |
| 375 | Module Size Used by Not tainted␊ |
| 376 | ubiblk 7696 0 ␊ |
| 377 | bdev 10016 1 ubiblk␊ |
| 378 | deflate 4256 1 ␊ |
| 379 | zlib_deflate 22256 1 deflate␊ |
| 380 | zlib_inflate 16992 1 deflate␊ |
| 381 | lzo 2400 1 ␊ |
| 382 | lzo_decompress 2816 1 lzo␊ |
| 383 | lzo_compress 2848 1 lzo␊ |
| 384 | ubifs 208560 0 ␊ |
| 385 | crc16 2048 1 ubifs␊ |
| 386 | ubi 103664 4 ubiblk,bdev,ubifs␊ |
| 387 | ␊ |
| 388 | Mount UBI volume 0 (the name is "ubifs") on ubi0 with type ubifs:␊ |
| 389 | ␊ |
| 390 | # mount -t ubifs ubi0:ubifs /mnt/ubifs/␊ |
| 391 | UBIFS: mounted UBI device 0, volume 0␊ |
| 392 | UBIFS: minimal I/O unit size: 2048 bytes␊ |
| 393 | UBIFS: logical eraseblock size: 258048 bytes (252 KiB)␊ |
| 394 | UBIFS: file system size: 207212544 bytes (202356 KiB, 197 MiB, 803 LEBs)␊ |
| 395 | UBIFS: journal size: 9420800 bytes (9200 KiB, 8 MiB, 37 LEBs)␊ |
| 396 | UBIFS: data journal heads: 1␊ |
| 397 | UBIFS: default compressor: LZO␊ |
| 398 | ␊ |
| 399 | It shows that we have mounted it sucessfully.␊ |
| 400 | ␊ |
| 401 | Format /dev/ubiblock1 (the block device for UBI volume 1) and mount it with␊ |
| 402 | type vfat:␊ |
| 403 | ␊ |
| 404 | # mkfs.vfat /dev/ubiblock1␊ |
| 405 | # mount -t vfat /dev/ubiblock1 /mnt/ubiblock1␊ |
| 406 | ␊ |
| 407 | Please refer to the linux26_developer_guide.pdf for more details about␊ |
| 408 | the UBI and UBIFS.␊ |
| 409 | ␊ |
| 410 | ␊ |
| 411 | ------------------------␊ |
| 412 | * UBI and UBIFS images *␊ |
| 413 | ------------------------␊ |
| 414 | ␊ |
| 415 | Generally, you want to create UBIFS and VFAT images respectively and combine␊ |
| 416 | these two images into one single image, and then use the nandwrite command␊ |
| 417 | to write this image to the MTD partition.␊ |
| 418 | ␊ |
| 419 | First of all, you need to compile the mkfs.ubifs utility. We use mkfs.ubifs␊ |
| 420 | to create the UBIFS image, like this:␊ |
| 421 | ␊ |
| 422 | Note: download the linux-nand-utils.tar.gz package from www.ingenic.cn and␊ |
| 423 | follows the guide to compile and run the mkfs.ubifs.␊ |
| 424 | ␊ |
| 425 | On the PC host:␊ |
| 426 | ␊ |
| 427 | $ mkfs.ubifs -h␊ |
| 428 | Usage: mkfs.ubifs [OPTIONS]␊ |
| 429 | Make a UBIFS file system image from an existing directory tree␊ |
| 430 | ␊ |
| 431 | Options:␊ |
| 432 | -r, -d, --root=DIR Build file system from directory DIR␊ |
| 433 | -m, --min-io-size=SIZE Minimum I/O size SIZE␊ |
| 434 | -e, --leb-size=SIZE Use logical erase block size SIZE␊ |
| 435 | -c, --max-leb-cnt=COUNT Use maximum logical erase block count COUNT␊ |
| 436 | -o, --output=FILE Output to FILE␊ |
| 437 | -j, --jrn-size=SIZE Use journal size SIZE bytes␊ |
| 438 | -x, --compr=TYPE Use compression type TYPE (lzo, zlib or none) (default: lzo)␊ |
| 439 | -f, --fanout=NUM Use fanout NUM (default: 8)␊ |
| 440 | -k, --keyhash=TYPE Use key hash type TYPE (r5 or test) (default: r5)␊ |
| 441 | -l, --log-lebs=COUNT Use COUNT erase blocks for the log␊ |
| 442 | -p, --orph-lebs=COUNT Use COUNT erase blocks for orphans (default: 1)␊ |
| 443 | -v, --verbose Verbose operation␊ |
| 444 | -V, --version Display version information␊ |
| 445 | -g, --debug=LEVEL Display debug information␊ |
| 446 | -h, --help Display this help text␊ |
| 447 | ␊ |
| 448 | $ mkfs.ubifs -r /nfsroot/root26 -m 2048 -e 258048 -c 813 -o ubifs.img␊ |
| 449 | ␊ |
| 450 | This will create an UBIFS image called ubifs.img. The argument values␊ |
| 451 | can be obtained from the 'ubinfo -a' command.␊ |
| 452 | ␊ |
| 453 | Follow next steps to create a 30MB FAT32 image called vfat.img:␊ |
| 454 | ␊ |
| 455 | # dd if=/dev/zero of=vfat.img bs=1M count=30␊ |
| 456 | # losetup /dev/loop0 vfat.img␊ |
| 457 | # mkfs.vfat /dev/loop0␊ |
| 458 | # mount -t vfat /dev/loop0 /mnt/vfat␊ |
| 459 | # cp * /mnt/vfat␊ |
| 460 | # umount /mnt/vfat␊ |
| 461 | # losetup -d /dev/loop0␊ |
| 462 | ␊ |
| 463 | Now the two images ubifs.img and vfat.img are ready, and we want to␊ |
| 464 | create two UBI volumes and write these two images to the two UBI volumes␊ |
| 465 | respectively. We can do like this:␊ |
| 466 | ␊ |
| 467 | First, use 'ubinize' command to combine ubifs.img and vfat.img into one␊ |
| 468 | UBI image called ubi.img.␊ |
| 469 | ␊ |
| 470 | Second, use 'nandwrite_mlc_ubi' command to write the ubi.img to the␊ |
| 471 | MTD partition.␊ |
| 472 | ␊ |
| 473 | To use 'ubinize' command, you should prepare an INI file for it. The␊ |
| 474 | content of the INI file are as below:␊ |
| 475 | ␊ |
| 476 | # cat ubinize.cfg ␊ |
| 477 | [ubifs]␊ |
| 478 | mode=ubi␊ |
| 479 | image=ubifs.img␊ |
| 480 | vol_id=0␊ |
| 481 | vol_size=200MiB␊ |
| 482 | vol_type=dynamic␊ |
| 483 | vol_name=ubifs␊ |
| 484 | vol_alignment=1␊ |
| 485 | vol_flag=autoresize␊ |
| 486 | ␊ |
| 487 | [vfat]␊ |
| 488 | mode=ubi␊ |
| 489 | image=vfat.img␊ |
| 490 | vol_id=1␊ |
| 491 | vol_size=298MiB␊ |
| 492 | vol_type=dynamic␊ |
| 493 | vol_name=vfat␊ |
| 494 | vol_alignment=1␊ |
| 495 | vol_flag=autoresize␊ |
| 496 | ␊ |
| 497 | ␊ |
| 498 | Now you can boot your board and follow next guides to create the UBI␊ |
| 499 | image and burn the UBI image.␊ |
| 500 | ␊ |
| 501 | On the target board side:␊ |
| 502 | ␊ |
| 503 | # ubinize -o ubi.img ubinize.cfg -p 262144 -m 2048␊ |
| 504 | ␊ |
| 505 | If things go well, you can get the UBI image ubi.img. ␊ |
| 506 | ␊ |
| 507 | Then use 'nandwrite_ubi' command to write it to the MTD partition.␊ |
| 508 | ␊ |
| 509 | # flash_eraseall /dev/mtd5␊ |
| 510 | # nandwrite_ubi -a -q -m /dev/mtd5 ubi.img␊ |
| 511 | ␊ |
| 512 | Now the UBI image has been written to the NAND mtd5 partition.␊ |
| 513 | ␊ |
| 514 | Use next commands to test it.␊ |
| 515 | ␊ |
| 516 | # modprobe ubi mtd=5␊ |
| 517 | ␊ |
| 518 | # ubinfo -a␊ |
| 519 | UBI version: 1␊ |
| 520 | Count of UBI devices: 1␊ |
| 521 | UBI control device major/minor: 10:63␊ |
| 522 | Present UBI devices: ubi0␊ |
| 523 | ␊ |
| 524 | ubi0:␊ |
| 525 | Volumes count: 2␊ |
| 526 | Logical eraseblock size: 258048␊ |
| 527 | Total amount of logical eraseblocks: 2048 (528482304 bytes, 504.0 MiB)␊ |
| 528 | Amount of available logical eraseblocks: 0 (0 bytes)␊ |
| 529 | Maximum count of volumes 128␊ |
| 530 | Count of bad physical eraseblocks: 0␊ |
| 531 | Count of reserved physical eraseblocks: 20␊ |
| 532 | Current maximum erase counter value: 1␊ |
| 533 | Minimum input/output unit size: 2048 bytes␊ |
| 534 | Character device major/minor: 252:0␊ |
| 535 | Present volumes: 0, 1␊ |
| 536 | ␊ |
| 537 | Volume ID: 0 (on ubi0)␊ |
| 538 | Type: dynamic␊ |
| 539 | Alignment: 1␊ |
| 540 | Size: 813 LEBs (209793024 bytes, 200.1 MiB)␊ |
| 541 | State: OK␊ |
| 542 | Name: ubifs␊ |
| 543 | Character device major/minor: 252:1␊ |
| 544 | -----------------------------------␊ |
| 545 | Volume ID: 1 (on ubi0)␊ |
| 546 | Type: dynamic␊ |
| 547 | Alignment: 1␊ |
| 548 | Size: 1211 LEBs (312496128 bytes, 298.0 MiB)␊ |
| 549 | State: OK␊ |
| 550 | Name: vfat␊ |
| 551 | Character device major/minor: 252:2␊ |
| 552 | ␊ |
| 553 | ␊ |
| 554 | This shows that two UBI volumes are present on ubi0.␊ |
| 555 | ␊ |
| 556 | # modprobe ubifs␊ |
| 557 | # mount -t ubifs ubi0:ubifs /mnt/ubifs/␊ |
| 558 | UBIFS: mounted UBI device 0, volume 0␊ |
| 559 | UBIFS: minimal I/O unit size: 2048 bytes␊ |
| 560 | UBIFS: logical eraseblock size: 258048 bytes (252 KiB)␊ |
| 561 | UBIFS: file system size: 207212544 bytes (202356 KiB, 197 MiB, 803 LEBs)␊ |
| 562 | UBIFS: journal size: 9420800 bytes (9200 KiB, 8 MiB, 37 LEBs)␊ |
| 563 | UBIFS: data journal heads: 1␊ |
| 564 | UBIFS: default compressor: LZO␊ |
| 565 | ␊ |
| 566 | # modprobe ubiblk␊ |
| 567 | # mount -t vfat /dev/ubiblock1 /mnt/ubiblock1␊ |
| 568 | ␊ |
| 569 | # df␊ |
| 570 | Filesystem 1k-blocks Used Available Use% Mounted on␊ |
| 571 | tmpfs 30196 56 30140 0% /dev␊ |
| 572 | ubi0:ubifs 197536 48228 149308 24% /mnt/ubifs␊ |
| 573 | /dev/ubiblock1 30642 5762 24880 19% /mnt/ubiblock1␊ |
| 574 | ␊ |
| 575 | It shows that the UBIFS and VFAT are all mounted successfully.␊ |
| 576 | ␊ |
| 577 | ␊ |
| 578 | ----------␊ |
| 579 | * YAFFS2 *␊ |
| 580 | ----------␊ |
| 581 | ␊ |
| 582 | YAFFS (Yet Another Flash File System) was written to satisfy the ␊ |
| 583 | special needs of NAND flash. The second release of YAFFS especially ␊ |
| 584 | points to supporting newer NAND flash chips with 2k page size and ␊ |
| 585 | up to 128MB capacity.␊ |
| 586 | ␊ |
| 587 | YAFFS2 is supported in this kernel. It's built on top of MTD directly.␊ |
| 588 | Go to fs/yaffs2 for more details.␊ |
| 589 | ␊ |
| 590 | To build the utility of YAFFS2, change to directory fs/yaffs2/utils/␊ |
| 591 | and type 'make'.␊ |
| 592 | ␊ |
| 593 | To create a YAFFS2 image, use next command (On PC host):␊ |
| 594 | ␊ |
| 595 | $ mkyaffs2image 1 /nfsroot/root26 root26.yaffs2␊ |
| 596 | ␊ |
| 597 | To burn the yaffs2 image to the NAND, use next command (On target board):␊ |
| 598 | ␊ |
| 599 | # nandwrite -a -o /dev/mtd2 root26.yaffs2␊ |
| 600 | ␊ |
| 601 | To format and mount YAFFS2 (On target board):␊ |
| 602 | ␊ |
| 603 | # flash_eraseall /dev/mtd2␊ |
| 604 | # mount -t yaffs2 /dev/mtdblock2 /mnt/mtdblock2␊ |
| 605 | ␊ |
| 606 | ␊ |
| 607 | -------------------␊ |
| 608 | * MTD Block Layer *␊ |
| 609 | -------------------␊ |
| 610 | ␊ |
| 611 | Ingenic implement the 'MTD Block Layer' by ourself. This gives you a choice␊ |
| 612 | to implement a general filesystem such as FAT and ext2 on NAND flash.␊ |
| 613 | ␊ |
| 614 | Features of the 'MTD Block Layer' include:␊ |
| 615 | ␊ |
| 616 | 1. Block unit management (address mapping & block cache operations)␊ |
| 617 | 2. Wear-leveling ␊ |
| 618 | 3. Bad block management␊ |
| 619 | 4. Write verify enable ␊ |
| 620 | 5. mutiple choice of ECC algorithms (hardware Hamming ECC & Reed Solomon ECC, ␊ |
| 621 | software Hamming ECC)␊ |
| 622 | ␊ |
| 623 | Kernel configurations related to the 'MTD Block Layer':␊ |
| 624 | ␊ |
| 625 | * CONFIG_MTD_OOB_COPIES: defines how many copies of the critical oob data for␊ |
| 626 | each block. Since the page data can be corrected by the ECC algorithm but ␊ |
| 627 | the oob data can't, we want to ensure the correction of the oob data by this␊ |
| 628 | way. The mtdblock-jz translation layer driver uses block mode to manipulate␊ |
| 629 | the NAND flash. It makes several copies of the oobinfo data for each block, ␊ |
| 630 | so that it can get a correct copy even there is an error in one of them.␊ |
| 631 | ␊ |
| 632 | * CONFIG_MTD_MTDBLOCK_WRITE_VERIFY_ENABLE: defines this to enable the write␊ |
| 633 | verification function, which will read back data to verify during a write␊ |
| 634 | operation.␊ |
| 635 | ␊ |
| 636 | Take following steps to use the 'MTD Block Layer':␊ |
| 637 | ␊ |
| 638 | # flash_eraseall /dev/mtd3␊ |
| 639 | # mkfs.vfat /dev/mtdblock3␊ |
| 640 | # mount -t vfat /dev/mtdblock3 /mnt/vfat␊ |
| 641 | ␊ |
| 642 | ␊ |
| 643 | NOTICE:␊ |
| 644 | ␊ |
| 645 | You can define mutiple VFAT partitions, all the VFAT partitions share␊ |
| 646 | the same above configurations.␊ |
| 647 | ␊ |
| 648 | Each VFAT partition have its own block cache which resides only in RAM. ␊ |
| 649 | Generally, the block cache flush operation is triggered when the access␊ |
| 650 | address exceeds block boundary. The last block cache usually will be ␊ |
| 651 | flushed to NAND device when the device is closed (eg: umount /mnt/vfat;␊ |
| 652 | use system call close(fd)).␊ |
| 653 | ␊ |
| 654 | Abrupt poweroff without flushing the last block cache will cause the ␊ |
| 655 | VFAT partition to lose the most significant data which records the ␊ |
| 656 | information of the file system management such as FAT table, inodes ...␊ |
| 657 | ␊ |
| 658 | To avoid this bad thing, you have to flush block cache as soon as possible. ␊ |
| 659 | Please do remember to flush block cache manually when you finish ␊ |
| 660 | a write operation.␊ |
| 661 | ␊ |
| 662 | The MTD block layer driver supplys an ioctl for triggering flush block cache ␊ |
| 663 | operation. The code attached behind is a reference for you to use.␊ |
| 664 | ␊ |
| 665 | eg:␉␊ |
| 666 | ␊ |
| 667 | # cp * /mnt/vfat␊ |
| 668 | # sync␉␉␉; this step is necessary to flush the FS cache␊ |
| 669 | # flushcache /dev/mtdblock3␉; this step is necessary to flush the NFTL block cache␊ |
| 670 | ␊ |
| 671 | ␊ |
| 672 | /* flushcache.c */␊ |
| 673 | #include <sys/ioctl.h>␊ |
| 674 | #include <linux/fs.h>␊ |
| 675 | #include <fcntl.h>␊ |
| 676 | #include <stdio.h>␊ |
| 677 | ␊ |
| 678 | int main(int argc,char **argv) ␊ |
| 679 | { ␊ |
| 680 | ␉int fd; ␊ |
| 681 | ␊ |
| 682 | ␉if( argc != 2 ){ ␊ |
| 683 | ␉␉printf( "Usage:%s device name(full path)\n", argv[0] ); ␊ |
| 684 | ␉␉return -1; ␊ |
| 685 | ␉} ␉␊ |
| 686 | ␊ |
| 687 | ␉if( (fd = open( argv[1], O_RDONLY ) ) == -1) { ␊ |
| 688 | ␉␉printf( "Open %s failed\n", argv[1] ); ␊ |
| 689 | ␉␉return -1; ␊ |
| 690 | ␉} ␊ |
| 691 | ␊ |
| 692 | ␉if( ioctl( fd, BLKFLSBUF) == -1)␊ |
| 693 | ␉␉printf("flush catche failed\n");␊ |
| 694 | ␉␉␊ |
| 695 | ␉close(fd); ␊ |
| 696 | ␉return 0; ␊ |
| 697 | }␊ |
| 698 | ␊ |
| 699 | ␊ |
| 700 | ----------------------------␊ |
| 701 | * About Bad Blocks of NAND *␊ |
| 702 | ----------------------------␊ |
| 703 | ␊ |
| 704 | NAND is a special flash type which there are new bad blocks generated during␊ |
| 705 | the whole period of using it. So the NAND driver should know how to detect␊ |
| 706 | a bad block and how to mark a new block bad.␊ |
| 707 | ␊ |
| 708 | Some types of NAND flash mark the bad block in the spare area of the first␊ |
| 709 | page but others in the last page. So we define a kernel configuration called␊ |
| 710 | CONFIG_MTD_BADBLOCK_FLAG_PAGE and use it to decide the bad block.␊ |
| 711 | ␊ |
| 712 | CONFIG_MTD_BADBLOCK_FLAG_PAGE: page in a block to store the badblock mark␊ |
| 713 | ␊ |
| 714 | Following functions should be cared:␊ |
| 715 | ␊ |
| 716 | nand_base.c:␊ |
| 717 | ␊ |
| 718 | - nand_block_bad()␊ |
| 719 | - nand_default_block_markbad()␊ |
| 720 | ␊ |
| 721 | nand_bbt.c:␊ |
| 722 | ␊ |
| 723 | - create_bbt()␊ |
| 724 | ␊ |
| 725 | ␊ |
| 726 | --------------------------␊ |
| 727 | * SLC and MLC NAND Flash *␊ |
| 728 | --------------------------␊ |
| 729 | ␊ |
| 730 | Single-Level Cell (SLC) and Multi-Level Cell (MLC) are both NAND-based ␊ |
| 731 | non-volatile memory technologies. MLC NAND Flash allows each memory cell ␊ |
| 732 | to store two bits of information, compared to the one bit-per-cell SLC ␊ |
| 733 | NAND Flash allows. As a result, 90 nanometer (nm) MLC NAND offers a ␊ |
| 734 | larger capacity (typically twice the density of SLC) and at a cost point␊ |
| 735 | appropriate for consumer products.␊ |
| 736 | ␊ |
| 737 | Though SLC NAND offers a lower density, it also provides an enhanced ␊ |
| 738 | level of performance in the form of faster write speeds. Because SLC ␊ |
| 739 | stores only one bit per cell, the likelihood for error is reduced.␊ |
| 740 | At 90 nanometer process, it is recommended to implement a 1 to 2-bit ␊ |
| 741 | ECC for SLC, whereas 4-bit ECC is recommended on the MLC architecture.␊ |
| 742 | ␊ |
| 743 | The linux kernel from ingenic provides MLC NAND support through a␊ |
| 744 | Reed-Solomon (RS) ECC algorithm, which can detect and correct 4-bit␊ |
| 745 | errors at least. The RS ECC algorithm is realized through the HW unit␊ |
| 746 | provided by the JZ4740 SoC.␊ |
| 747 | ␊ |
| 748 | To include MLC NAND support, you are required to configure the kernel␊ |
| 749 | and select the configuration CONFIG_MTD_HW_RS_ECC, which can be found␊ |
| 750 | at:␊ |
| 751 | ␊ |
| 752 | [Memory Technology Devices (MTD)] --> [NAND Device Support]␊ |
| 753 | ␊ |
| 754 | --> [ECC Type] --> [Select hardware RS ECC]␊ |
| 755 | ␊ |
| 756 | ␊ |
| 757 | -------------␊ |
| 758 | * initramfs *␊ |
| 759 | -------------␊ |
| 760 | ␊ |
| 761 | Please read Documentation/filesystems/ramfs-rootfs-initramfs.txt for ␊ |
| 762 | more information about how to use initramfs.␊ |
| 763 | ␊ |
| 764 | Following are some steps to help you to create root fs by using initramfs:␊ |
| 765 | ␊ |
| 766 | # cd /rootfs/␊ |
| 767 | # find . | cpio -c -o | gzip -9 > ../rootfs.cpio.gz␊ |
| 768 | ␊ |
| 769 | Reconfigure the Linux kernel and select next configurations:␊ |
| 770 | ␊ |
| 771 | CONFIG_BLK_DEV_INITRD=y␊ |
| 772 | CONFIG_INITRAMFS_SOURCE="/rootfs.cpio.gz"␊ |
| 773 | CONFIG_INITRAMFS_ROOT_UID=0␊ |
| 774 | CONFIG_INITRAMFS_ROOT_GID=0␊ |
| 775 | ␊ |
| 776 | Rebuild the kernel and boot the kernel with next command lines:␊ |
| 777 | ␊ |
| 778 | "root=/dev/ram0 rw rdinit=/sbin/init"␊ |
| 779 | ␊ |
| 780 | ␊ |
| 781 | -----------␊ |
| 782 | * Support *␊ |
| 783 | -----------␊ |
| 784 | ␊ |
| 785 | Welcome to Ingenic website: <http://www.ingenic.cn>␊ |
| 786 | ␊ |
| 787 | More details, please refer to linux26_developer_guide.pdf.␊ |
| 788 | |