Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) International Business Machines Corp., 2006
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Authors: Artem Bityutskiy (Битюцкий Артём)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *          Thomas Gleixner
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *          Frank Haverkamp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *          Oliver Lohmann
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *          Andreas Arnez
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * This file defines the layout of UBI headers and all the other UBI on-flash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * data structures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #ifndef __UBI_MEDIA_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #define __UBI_MEDIA_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <asm/byteorder.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) /* The version of UBI images supported by this implementation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define UBI_VERSION 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) /* The highest erase counter value supported by this implementation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define UBI_MAX_ERASECOUNTER 0x7FFFFFFF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) /* The initial CRC32 value used when calculating CRC checksums */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define UBI_CRC32_INIT 0xFFFFFFFFU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) /* Erase counter header magic number (ASCII "UBI#") */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define UBI_EC_HDR_MAGIC  0x55424923
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) /* Volume identifier header magic number (ASCII "UBI!") */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define UBI_VID_HDR_MAGIC 0x55424921
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * Volume type constants used in the volume identifier header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * @UBI_VID_DYNAMIC: dynamic volume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * @UBI_VID_STATIC: static volume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	UBI_VID_DYNAMIC = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	UBI_VID_STATIC  = 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * Volume flags used in the volume table record.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * @UBI_VTBL_AUTORESIZE_FLG: auto-resize this volume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * @UBI_VTBL_SKIP_CRC_CHECK_FLG: skip the CRC check done on a static volume at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  *				 open time. Should only be set on volumes that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  *				 are used by upper layers doing this kind of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  *				 check. Main use-case for this flag is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  *				 boot-time reduction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  * %UBI_VTBL_AUTORESIZE_FLG flag can be set only for one volume in the volume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  * table. UBI automatically re-sizes the volume which has this flag and makes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  * the volume to be of largest possible size. This means that if after the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  * initialization UBI finds out that there are available physical eraseblocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  * present on the device, it automatically appends all of them to the volume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  * (the physical eraseblocks reserved for bad eraseblocks handling and other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * reserved physical eraseblocks are not taken). So, if there is a volume with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  * the %UBI_VTBL_AUTORESIZE_FLG flag set, the amount of available logical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  * eraseblocks will be zero after UBI is loaded, because all of them will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  * reserved for this volume. Note, the %UBI_VTBL_AUTORESIZE_FLG bit is cleared
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  * after the volume had been initialized.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  * The auto-resize feature is useful for device production purposes. For
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  * example, different NAND flash chips may have different amount of initial bad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  * eraseblocks, depending of particular chip instance. Manufacturers of NAND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  * chips usually guarantee that the amount of initial bad eraseblocks does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  * exceed certain percent, e.g. 2%. When one creates an UBI image which will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  * flashed to the end devices in production, he does not know the exact amount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  * of good physical eraseblocks the NAND chip on the device will have, but this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  * number is required to calculate the volume sized and put them to the volume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  * table of the UBI image. In this case, one of the volumes (e.g., the one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  * which will store the root file system) is marked as "auto-resizable", and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  * UBI will adjust its size on the first boot if needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  * Note, first UBI reserves some amount of physical eraseblocks for bad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  * eraseblock handling, and then re-sizes the volume, not vice-versa. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  * means that the pool of reserved physical eraseblocks will always be present.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	UBI_VTBL_AUTORESIZE_FLG = 0x01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	UBI_VTBL_SKIP_CRC_CHECK_FLG = 0x02,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  * Compatibility constants used by internal volumes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90)  * @UBI_COMPAT_DELETE: delete this internal volume before anything is written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)  *                     to the flash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92)  * @UBI_COMPAT_RO: attach this device in read-only mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  * @UBI_COMPAT_PRESERVE: preserve this internal volume - do not touch its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  *                       physical eraseblocks, don't allow the wear-leveling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  *                       sub-system to move them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  * @UBI_COMPAT_REJECT: reject this UBI image
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	UBI_COMPAT_DELETE   = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	UBI_COMPAT_RO       = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	UBI_COMPAT_PRESERVE = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	UBI_COMPAT_REJECT   = 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /* Sizes of UBI headers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #define UBI_EC_HDR_SIZE  sizeof(struct ubi_ec_hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #define UBI_VID_HDR_SIZE sizeof(struct ubi_vid_hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) /* Sizes of UBI headers without the ending CRC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) #define UBI_EC_HDR_SIZE_CRC  (UBI_EC_HDR_SIZE  - sizeof(__be32))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #define UBI_VID_HDR_SIZE_CRC (UBI_VID_HDR_SIZE - sizeof(__be32))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)  * struct ubi_ec_hdr - UBI erase counter header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)  * @magic: erase counter header magic number (%UBI_EC_HDR_MAGIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)  * @version: version of UBI implementation which is supposed to accept this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)  *           UBI image
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)  * @padding1: reserved for future, zeroes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  * @ec: the erase counter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  * @vid_hdr_offset: where the VID header starts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  * @data_offset: where the user data start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)  * @image_seq: image sequence number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  * @padding2: reserved for future, zeroes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)  * @hdr_crc: erase counter header CRC checksum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)  * The erase counter header takes 64 bytes and has a plenty of unused space for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)  * future usage. The unused fields are zeroed. The @version field is used to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)  * indicate the version of UBI implementation which is supposed to be able to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)  * work with this UBI image. If @version is greater than the current UBI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)  * version, the image is rejected. This may be useful in future if something
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)  * is changed radically. This field is duplicated in the volume identifier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)  * header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)  * The @vid_hdr_offset and @data_offset fields contain the offset of the the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  * volume identifier header and user data, relative to the beginning of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  * physical eraseblock. These values have to be the same for all physical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)  * eraseblocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)  * The @image_seq field is used to validate a UBI image that has been prepared
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)  * for a UBI device. The @image_seq value can be any value, but it must be the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)  * same on all eraseblocks. UBI will ensure that all new erase counter headers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)  * also contain this value, and will check the value when attaching the flash.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)  * One way to make use of @image_seq is to increase its value by one every time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)  * an image is flashed over an existing image, then, if the flashing does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  * complete, UBI will detect the error when attaching the media.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct ubi_ec_hdr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	__be32  magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	__u8    version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	__u8    padding1[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	__be64  ec; /* Warning: the current limit is 31-bit anyway! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	__be32  vid_hdr_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	__be32  data_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	__be32  image_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	__u8    padding2[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	__be32  hdr_crc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)  * struct ubi_vid_hdr - on-flash UBI volume identifier header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)  * @magic: volume identifier header magic number (%UBI_VID_HDR_MAGIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)  * @version: UBI implementation version which is supposed to accept this UBI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)  *           image (%UBI_VERSION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)  * @vol_type: volume type (%UBI_VID_DYNAMIC or %UBI_VID_STATIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)  * @copy_flag: if this logical eraseblock was copied from another physical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)  *             eraseblock (for wear-leveling reasons)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)  * @compat: compatibility of this volume (%0, %UBI_COMPAT_DELETE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)  *          %UBI_COMPAT_IGNORE, %UBI_COMPAT_PRESERVE, or %UBI_COMPAT_REJECT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)  * @vol_id: ID of this volume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)  * @lnum: logical eraseblock number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)  * @padding1: reserved for future, zeroes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)  * @data_size: how many bytes of data this logical eraseblock contains
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)  * @used_ebs: total number of used logical eraseblocks in this volume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)  * @data_pad: how many bytes at the end of this physical eraseblock are not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)  *            used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)  * @data_crc: CRC checksum of the data stored in this logical eraseblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)  * @padding2: reserved for future, zeroes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)  * @sqnum: sequence number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)  * @padding3: reserved for future, zeroes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)  * @hdr_crc: volume identifier header CRC checksum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  * The @sqnum is the value of the global sequence counter at the time when this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  * VID header was created. The global sequence counter is incremented each time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  * UBI writes a new VID header to the flash, i.e. when it maps a logical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)  * eraseblock to a new physical eraseblock. The global sequence counter is an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)  * unsigned 64-bit integer and we assume it never overflows. The @sqnum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)  * (sequence number) is used to distinguish between older and newer versions of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)  * logical eraseblocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)  * There are 2 situations when there may be more than one physical eraseblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)  * corresponding to the same logical eraseblock, i.e., having the same @vol_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)  * and @lnum values in the volume identifier header. Suppose we have a logical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)  * eraseblock L and it is mapped to the physical eraseblock P.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)  * 1. Because UBI may erase physical eraseblocks asynchronously, the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)  * situation is possible: L is asynchronously erased, so P is scheduled for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  * erasure, then L is written to,i.e. mapped to another physical eraseblock P1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)  * so P1 is written to, then an unclean reboot happens. Result - there are 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)  * physical eraseblocks P and P1 corresponding to the same logical eraseblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)  * L. But P1 has greater sequence number, so UBI picks P1 when it attaches the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)  * flash.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)  * 2. From time to time UBI moves logical eraseblocks to other physical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)  * eraseblocks for wear-leveling reasons. If, for example, UBI moves L from P
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)  * to P1, and an unclean reboot happens before P is physically erased, there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)  * are two physical eraseblocks P and P1 corresponding to L and UBI has to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)  * select one of them when the flash is attached. The @sqnum field says which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)  * PEB is the original (obviously P will have lower @sqnum) and the copy. But
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)  * it is not enough to select the physical eraseblock with the higher sequence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)  * number, because the unclean reboot could have happen in the middle of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)  * copying process, so the data in P is corrupted. It is also not enough to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)  * just select the physical eraseblock with lower sequence number, because the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)  * data there may be old (consider a case if more data was added to P1 after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)  * the copying). Moreover, the unclean reboot may happen when the erasure of P
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)  * was just started, so it result in unstable P, which is "mostly" OK, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)  * still has unstable bits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)  * UBI uses the @copy_flag field to indicate that this logical eraseblock is a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)  * copy. UBI also calculates data CRC when the data is moved and stores it at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)  * the @data_crc field of the copy (P1). So when UBI needs to pick one physical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)  * eraseblock of two (P or P1), the @copy_flag of the newer one (P1) is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)  * examined. If it is cleared, the situation is simple and the newer one is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)  * picked. If it is set, the data CRC of the copy (P1) is examined. If the CRC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)  * checksum is correct, this physical eraseblock is selected (P1). Otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)  * the older one (P) is selected.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)  * There are 2 sorts of volumes in UBI: user volumes and internal volumes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)  * Internal volumes are not seen from outside and are used for various internal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)  * UBI purposes. In this implementation there is only one internal volume - the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)  * layout volume. Internal volumes are the main mechanism of UBI extensions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)  * For example, in future one may introduce a journal internal volume. Internal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)  * volumes have their own reserved range of IDs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)  * The @compat field is only used for internal volumes and contains the "degree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)  * of their compatibility". It is always zero for user volumes. This field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)  * provides a mechanism to introduce UBI extensions and to be still compatible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)  * with older UBI binaries. For example, if someone introduced a journal in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)  * future, he would probably use %UBI_COMPAT_DELETE compatibility for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)  * journal volume.  And in this case, older UBI binaries, which know nothing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)  * about the journal volume, would just delete this volume and work perfectly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)  * fine. This is similar to what Ext2fs does when it is fed by an Ext3fs image
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)  * - it just ignores the Ext3fs journal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)  * The @data_crc field contains the CRC checksum of the contents of the logical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)  * eraseblock if this is a static volume. In case of dynamic volumes, it does
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)  * not contain the CRC checksum as a rule. The only exception is when the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)  * data of the physical eraseblock was moved by the wear-leveling sub-system,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)  * then the wear-leveling sub-system calculates the data CRC and stores it in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)  * the @data_crc field. And of course, the @copy_flag is %in this case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)  * The @data_size field is used only for static volumes because UBI has to know
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)  * how many bytes of data are stored in this eraseblock. For dynamic volumes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)  * this field usually contains zero. The only exception is when the data of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)  * physical eraseblock was moved to another physical eraseblock for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)  * wear-leveling reasons. In this case, UBI calculates CRC checksum of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)  * contents and uses both @data_crc and @data_size fields. In this case, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)  * @data_size field contains data size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)  * The @used_ebs field is used only for static volumes and indicates how many
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)  * eraseblocks the data of the volume takes. For dynamic volumes this field is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)  * not used and always contains zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)  * The @data_pad is calculated when volumes are created using the alignment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)  * parameter. So, effectively, the @data_pad field reduces the size of logical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)  * eraseblocks of this volume. This is very handy when one uses block-oriented
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)  * software (say, cramfs) on top of the UBI volume.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) struct ubi_vid_hdr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	__be32  magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	__u8    version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	__u8    vol_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	__u8    copy_flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	__u8    compat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	__be32  vol_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	__be32  lnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	__u8    padding1[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	__be32  data_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	__be32  used_ebs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	__be32  data_pad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	__be32  data_crc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	__u8    padding2[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	__be64  sqnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	__u8    padding3[12];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	__be32  hdr_crc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) /* Internal UBI volumes count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) #define UBI_INT_VOL_COUNT 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)  * Starting ID of internal volumes: 0x7fffefff.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)  * There is reserved room for 4096 internal volumes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) #define UBI_INTERNAL_VOL_START (0x7FFFFFFF - 4096)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) /* The layout volume contains the volume table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) #define UBI_LAYOUT_VOLUME_ID     UBI_INTERNAL_VOL_START
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) #define UBI_LAYOUT_VOLUME_TYPE   UBI_VID_DYNAMIC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) #define UBI_LAYOUT_VOLUME_ALIGN  1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) #define UBI_LAYOUT_VOLUME_EBS    2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) #define UBI_LAYOUT_VOLUME_NAME   "layout volume"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) #define UBI_LAYOUT_VOLUME_COMPAT UBI_COMPAT_REJECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) /* The maximum number of volumes per one UBI device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) #define UBI_MAX_VOLUMES 128
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) /* The maximum volume name length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) #define UBI_VOL_NAME_MAX 127
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) /* Size of the volume table record */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) #define UBI_VTBL_RECORD_SIZE sizeof(struct ubi_vtbl_record)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) /* Size of the volume table record without the ending CRC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) #define UBI_VTBL_RECORD_SIZE_CRC (UBI_VTBL_RECORD_SIZE - sizeof(__be32))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)  * struct ubi_vtbl_record - a record in the volume table.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)  * @reserved_pebs: how many physical eraseblocks are reserved for this volume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)  * @alignment: volume alignment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)  * @data_pad: how many bytes are unused at the end of the each physical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)  * eraseblock to satisfy the requested alignment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)  * @vol_type: volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)  * @upd_marker: if volume update was started but not finished
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)  * @name_len: volume name length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)  * @name: the volume name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)  * @flags: volume flags (%UBI_VTBL_AUTORESIZE_FLG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)  * @padding: reserved, zeroes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)  * @crc: a CRC32 checksum of the record
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)  * The volume table records are stored in the volume table, which is stored in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)  * the layout volume. The layout volume consists of 2 logical eraseblock, each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)  * of which contains a copy of the volume table (i.e., the volume table is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)  * duplicated). The volume table is an array of &struct ubi_vtbl_record
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)  * objects indexed by the volume ID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)  * If the size of the logical eraseblock is large enough to fit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)  * %UBI_MAX_VOLUMES records, the volume table contains %UBI_MAX_VOLUMES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)  * records. Otherwise, it contains as many records as it can fit (i.e., size of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)  * logical eraseblock divided by sizeof(struct ubi_vtbl_record)).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)  * The @upd_marker flag is used to implement volume update. It is set to %1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)  * before update and set to %0 after the update. So if the update operation was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)  * interrupted, UBI knows that the volume is corrupted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)  * The @alignment field is specified when the volume is created and cannot be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)  * later changed. It may be useful, for example, when a block-oriented file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)  * system works on top of UBI. The @data_pad field is calculated using the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)  * logical eraseblock size and @alignment. The alignment must be multiple to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)  * minimal flash I/O unit. If @alignment is 1, all the available space of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)  * the physical eraseblocks is used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)  * Empty records contain all zeroes and the CRC checksum of those zeroes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) struct ubi_vtbl_record {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	__be32  reserved_pebs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	__be32  alignment;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	__be32  data_pad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	__u8    vol_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	__u8    upd_marker;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	__be16  name_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	__u8    name[UBI_VOL_NAME_MAX+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	__u8    flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	__u8    padding[23];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	__be32  crc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) /* UBI fastmap on-flash data structures */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) #define UBI_FM_SB_VOLUME_ID	(UBI_LAYOUT_VOLUME_ID + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) #define UBI_FM_DATA_VOLUME_ID	(UBI_LAYOUT_VOLUME_ID + 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) /* fastmap on-flash data structure format version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) #define UBI_FM_FMT_VERSION	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) #define UBI_FM_SB_MAGIC		0x7B11D69F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) #define UBI_FM_HDR_MAGIC	0xD4B82EF7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) #define UBI_FM_VHDR_MAGIC	0xFA370ED1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) #define UBI_FM_POOL_MAGIC	0x67AF4D08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) #define UBI_FM_EBA_MAGIC	0xf0c040a8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) /* A fastmap super block can be located between PEB 0 and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)  * UBI_FM_MAX_START */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) #define UBI_FM_MAX_START	64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) /* A fastmap can use up to UBI_FM_MAX_BLOCKS PEBs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) #define UBI_FM_MAX_BLOCKS	32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) /* 5% of the total number of PEBs have to be scanned while attaching
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)  * from a fastmap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)  * But the size of this pool is limited to be between UBI_FM_MIN_POOL_SIZE and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)  * UBI_FM_MAX_POOL_SIZE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) #define UBI_FM_MIN_POOL_SIZE	8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) #define UBI_FM_MAX_POOL_SIZE	256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)  * struct ubi_fm_sb - UBI fastmap super block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)  * @magic: fastmap super block magic number (%UBI_FM_SB_MAGIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)  * @version: format version of this fastmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)  * @data_crc: CRC over the fastmap data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)  * @used_blocks: number of PEBs used by this fastmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)  * @block_loc: an array containing the location of all PEBs of the fastmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)  * @block_ec: the erase counter of each used PEB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)  * @sqnum: highest sequence number value at the time while taking the fastmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) struct ubi_fm_sb {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	__be32 magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	__u8 version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	__u8 padding1[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	__be32 data_crc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	__be32 used_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	__be32 block_loc[UBI_FM_MAX_BLOCKS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	__be32 block_ec[UBI_FM_MAX_BLOCKS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	__be64 sqnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	__u8 padding2[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)  * struct ubi_fm_hdr - header of the fastmap data set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)  * @magic: fastmap header magic number (%UBI_FM_HDR_MAGIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)  * @free_peb_count: number of free PEBs known by this fastmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)  * @used_peb_count: number of used PEBs known by this fastmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)  * @scrub_peb_count: number of to be scrubbed PEBs known by this fastmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)  * @bad_peb_count: number of bad PEBs known by this fastmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)  * @erase_peb_count: number of bad PEBs which have to be erased
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)  * @vol_count: number of UBI volumes known by this fastmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) struct ubi_fm_hdr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	__be32 magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	__be32 free_peb_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	__be32 used_peb_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	__be32 scrub_peb_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	__be32 bad_peb_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	__be32 erase_peb_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	__be32 vol_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	__u8 padding[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) /* struct ubi_fm_hdr is followed by two struct ubi_fm_scan_pool */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)  * struct ubi_fm_scan_pool - Fastmap pool PEBs to be scanned while attaching
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)  * @magic: pool magic numer (%UBI_FM_POOL_MAGIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)  * @size: current pool size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)  * @max_size: maximal pool size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)  * @pebs: an array containing the location of all PEBs in this pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) struct ubi_fm_scan_pool {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	__be32 magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	__be16 size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	__be16 max_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	__be32 pebs[UBI_FM_MAX_POOL_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	__be32 padding[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) /* ubi_fm_scan_pool is followed by nfree+nused struct ubi_fm_ec records */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)  * struct ubi_fm_ec - stores the erase counter of a PEB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)  * @pnum: PEB number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)  * @ec: ec of this PEB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) struct ubi_fm_ec {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	__be32 pnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	__be32 ec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)  * struct ubi_fm_volhdr - Fastmap volume header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)  * it identifies the start of an eba table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)  * @magic: Fastmap volume header magic number (%UBI_FM_VHDR_MAGIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)  * @vol_id: volume id of the fastmapped volume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)  * @vol_type: type of the fastmapped volume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)  * @data_pad: data_pad value of the fastmapped volume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)  * @used_ebs: number of used LEBs within this volume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)  * @last_eb_bytes: number of bytes used in the last LEB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) struct ubi_fm_volhdr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	__be32 magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	__be32 vol_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	__u8 vol_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	__u8 padding1[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	__be32 data_pad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	__be32 used_ebs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	__be32 last_eb_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	__u8 padding2[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) /* struct ubi_fm_volhdr is followed by one struct ubi_fm_eba records */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)  * struct ubi_fm_eba - denotes an association between a PEB and LEB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)  * @magic: EBA table magic number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)  * @reserved_pebs: number of table entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)  * @pnum: PEB number of LEB (LEB is the index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) struct ubi_fm_eba {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	__be32 magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	__be32 reserved_pebs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	__be32 pnum[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) #endif /* !__UBI_MEDIA_H__ */