📄 ubi-media.h
字号:
/* * Copyright (c) International Business Machines Corp., 2006 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See * the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Authors: Artem Bityutskiy (Битюцкий Артём) * Thomas Gleixner * Frank Haverkamp * Oliver Lohmann * Andreas Arnez *//* * This file defines the layout of UBI headers and all the other UBI on-flash * data structures. */#ifndef __UBI_MEDIA_H__#define __UBI_MEDIA_H__#include <asm/byteorder.h>/* The version of UBI images supported by this implementation */#define UBI_VERSION 1/* The highest erase counter value supported by this implementation */#define UBI_MAX_ERASECOUNTER 0x7FFFFFFF/* The initial CRC32 value used when calculating CRC checksums */#define UBI_CRC32_INIT 0xFFFFFFFFU/* Erase counter header magic number (ASCII "UBI#") */#define UBI_EC_HDR_MAGIC 0x55424923/* Volume identifier header magic number (ASCII "UBI!") */#define UBI_VID_HDR_MAGIC 0x55424921/* * Volume type constants used in the volume identifier header. * * @UBI_VID_DYNAMIC: dynamic volume * @UBI_VID_STATIC: static volume */enum { UBI_VID_DYNAMIC = 1, UBI_VID_STATIC = 2};/* * Volume flags used in the volume table record. * * @UBI_VTBL_AUTORESIZE_FLG: auto-resize this volume * * %UBI_VTBL_AUTORESIZE_FLG flag can be set only for one volume in the volume * table. UBI automatically re-sizes the volume which has this flag and makes * the volume to be of largest possible size. This means that if after the * initialization UBI finds out that there are available physical eraseblocks * present on the device, it automatically appends all of them to the volume * (the physical eraseblocks reserved for bad eraseblocks handling and other * reserved physical eraseblocks are not taken). So, if there is a volume with * the %UBI_VTBL_AUTORESIZE_FLG flag set, the amount of available logical * eraseblocks will be zero after UBI is loaded, because all of them will be * reserved for this volume. Note, the %UBI_VTBL_AUTORESIZE_FLG bit is cleared * after the volume had been initialized. * * The auto-resize feature is useful for device production purposes. For * example, different NAND flash chips may have different amount of initial bad * eraseblocks, depending of particular chip instance. Manufacturers of NAND * chips usually guarantee that the amount of initial bad eraseblocks does not * exceed certain percent, e.g. 2%. When one creates an UBI image which will be * flashed to the end devices in production, he does not know the exact amount * of good physical eraseblocks the NAND chip on the device will have, but this * number is required to calculate the volume sized and put them to the volume * table of the UBI image. In this case, one of the volumes (e.g., the one * which will store the root file system) is marked as "auto-resizable", and * UBI will adjust its size on the first boot if needed. * * Note, first UBI reserves some amount of physical eraseblocks for bad * eraseblock handling, and then re-sizes the volume, not vice-versa. This * means that the pool of reserved physical eraseblocks will always be present. */enum { UBI_VTBL_AUTORESIZE_FLG = 0x01,};/* * Compatibility constants used by internal volumes. * * @UBI_COMPAT_DELETE: delete this internal volume before anything is written * to the flash * @UBI_COMPAT_RO: attach this device in read-only mode * @UBI_COMPAT_PRESERVE: preserve this internal volume - do not touch its * physical eraseblocks, don't allow the wear-leveling * sub-system to move them * @UBI_COMPAT_REJECT: reject this UBI image */enum { UBI_COMPAT_DELETE = 1, UBI_COMPAT_RO = 2, UBI_COMPAT_PRESERVE = 4, UBI_COMPAT_REJECT = 5};/* Sizes of UBI headers */#define UBI_EC_HDR_SIZE sizeof(struct ubi_ec_hdr)#define UBI_VID_HDR_SIZE sizeof(struct ubi_vid_hdr)/* Sizes of UBI headers without the ending CRC */#define UBI_EC_HDR_SIZE_CRC (UBI_EC_HDR_SIZE - sizeof(__be32))#define UBI_VID_HDR_SIZE_CRC (UBI_VID_HDR_SIZE - sizeof(__be32))/** * struct ubi_ec_hdr - UBI erase counter header. * @magic: erase counter header magic number (%UBI_EC_HDR_MAGIC) * @version: version of UBI implementation which is supposed to accept this * UBI image * @padding1: reserved for future, zeroes * @ec: the erase counter * @vid_hdr_offset: where the VID header starts * @data_offset: where the user data start * @padding2: reserved for future, zeroes * @hdr_crc: erase counter header CRC checksum * * The erase counter header takes 64 bytes and has a plenty of unused space for * future usage. The unused fields are zeroed. The @version field is used to * indicate the version of UBI implementation which is supposed to be able to * work with this UBI image. If @version is greater then the current UBI * version, the image is rejected. This may be useful in future if something * is changed radically. This field is duplicated in the volume identifier * header. * * The @vid_hdr_offset and @data_offset fields contain the offset of the the * volume identifier header and user data, relative to the beginning of the * physical eraseblock. These values have to be the same for all physical * eraseblocks. */struct ubi_ec_hdr { __be32 magic; __u8 version; __u8 padding1[3]; __be64 ec; /* Warning: the current limit is 31-bit anyway! */ __be32 vid_hdr_offset; __be32 data_offset; __u8 padding2[36]; __be32 hdr_crc;} __attribute__ ((packed));/** * struct ubi_vid_hdr - on-flash UBI volume identifier header. * @magic: volume identifier header magic number (%UBI_VID_HDR_MAGIC) * @version: UBI implementation version which is supposed to accept this UBI * image (%UBI_VERSION) * @vol_type: volume type (%UBI_VID_DYNAMIC or %UBI_VID_STATIC) * @copy_flag: if this logical eraseblock was copied from another physical * eraseblock (for wear-leveling reasons) * @compat: compatibility of this volume (%0, %UBI_COMPAT_DELETE, * %UBI_COMPAT_IGNORE, %UBI_COMPAT_PRESERVE, or %UBI_COMPAT_REJECT) * @vol_id: ID of this volume * @lnum: logical eraseblock number * @padding1: reserved for future, zeroes * @data_size: how many bytes of data this logical eraseblock contains * @used_ebs: total number of used logical eraseblocks in this volume * @data_pad: how many bytes at the end of this physical eraseblock are not * used * @data_crc: CRC checksum of the data stored in this logical eraseblock * @padding2: reserved for future, zeroes * @sqnum: sequence number * @padding3: reserved for future, zeroes * @hdr_crc: volume identifier header CRC checksum * * The @sqnum is the value of the global sequence counter at the time when this * VID header was created. The global sequence counter is incremented each time * UBI writes a new VID header to the flash, i.e. when it maps a logical * eraseblock to a new physical eraseblock. The global sequence counter is an
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -