mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-11-24 02:05:01 +00:00
Implement cgptlib for MTD devices.
Defines MTD on-disk structures & API in mtdlib.h/c that closely mirrors the existing cgpt implementation. Currently, the disk structures do not contain guids or labels, and the number of available partition types and quantities are limited, exactly what we want to support should be decided before we ship this. Adds appropriate test coverage to the unit test library - either by modifying existing tests, or copying them and changing them accordingly. BUG=chromium:221745 TEST=added appropriate tests to the unittests BRANCH=none Change-Id: Iee19864498024c72229bc3c7811594fe762f52de Original-Change-Id: I031eca69d6c8e825b02bd0522d57e92b05eb191a Reviewed-on: https://gerrit.chromium.org/gerrit/46082 Tested-by: Albert Chaulk <achaulk@chromium.org> Reviewed-by: Bill Richardson <wfrichar@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org> Commit-Queue: Albert Chaulk <achaulk@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/48793 Reviewed-by: Albert Chaulk <achaulk@chromium.org>
This commit is contained in:
148
firmware/lib/cgptlib/include/mtdlib.h
Normal file
148
firmware/lib/cgptlib/include/mtdlib.h
Normal file
@@ -0,0 +1,148 @@
|
||||
/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef VBOOT_REFERENCE_MTDLIB_H_
|
||||
#define VBOOT_REFERENCE_MTDLIB_H_
|
||||
|
||||
#include "cgptlib.h"
|
||||
#include "sysincludes.h"
|
||||
|
||||
|
||||
#define MTD_DRIVE_SIGNATURE "CrOSPart" /* This must be exactly 8 chars */
|
||||
|
||||
/*
|
||||
* Bit definitions and masks for MTD attributes.
|
||||
*
|
||||
* 13-16 -- partition number
|
||||
* 9-12 -- partition type
|
||||
* 8 -- success
|
||||
* 7-4 -- tries
|
||||
* 3-0 -- priority
|
||||
*/
|
||||
#define MTD_ATTRIBUTE_PRIORITY_OFFSET (0)
|
||||
#define MTD_ATTRIBUTE_MAX_PRIORITY (15UL)
|
||||
#define MTD_ATTRIBUTE_PRIORITY_MASK (MTD_ATTRIBUTE_MAX_PRIORITY << \
|
||||
MTD_ATTRIBUTE_PRIORITY_OFFSET)
|
||||
|
||||
#define MTD_ATTRIBUTE_TRIES_OFFSET (4)
|
||||
#define MTD_ATTRIBUTE_MAX_TRIES (15UL)
|
||||
#define MTD_ATTRIBUTE_TRIES_MASK (MTD_ATTRIBUTE_MAX_TRIES << \
|
||||
MTD_ATTRIBUTE_TRIES_OFFSET)
|
||||
|
||||
#define MTD_ATTRIBUTE_SUCCESSFUL_OFFSET (8)
|
||||
#define MTD_ATTRIBUTE_MAX_SUCCESSFUL (1UL)
|
||||
#define MTD_ATTRIBUTE_SUCCESSFUL_MASK (MTD_ATTRIBUTE_MAX_SUCCESSFUL << \
|
||||
MTD_ATTRIBUTE_SUCCESSFUL_OFFSET)
|
||||
|
||||
#define MTD_ATTRIBUTE_TYPE_OFFSET (9)
|
||||
#define MTD_ATTRIBUTE_MAX_TYPE (15UL)
|
||||
#define MTD_ATTRIBUTE_TYPE_MASK (MTD_ATTRIBUTE_MAX_TYPE << \
|
||||
MTD_ATTRIBUTE_TYPE_OFFSET)
|
||||
|
||||
#define MTD_ATTRIBUTE_NUMBER_OFFSET (13)
|
||||
#define MTD_ATTRIBUTE_MAX_NUMBER (15UL)
|
||||
#define MTD_ATTRIBUTE_NUMBER_MASK (MTD_ATTRIBUTE_MAX_NUMBER << \
|
||||
MTD_ATTRIBUTE_NUMBER_OFFSET)
|
||||
|
||||
|
||||
#define MTD_PARTITION_TYPE_UNUSED 0
|
||||
#define MTD_PARTITION_TYPE_CHROMEOS_KERNEL 1
|
||||
#define MTD_PARTITION_TYPE_CHROMEOS_FIRMWARE 2
|
||||
#define MTD_PARTITION_TYPE_CHROMEOS_ROOTFS 3
|
||||
#define MTD_PARTITION_TYPE_CHROMEOS_RESERVED 4
|
||||
#define MTD_PARTITION_TYPE_CHROMEOS_FLAGSTORE 5
|
||||
#define MTD_PARTITION_TYPE_LINUX_DATA 6
|
||||
#define MTD_PARTITION_TYPE_EFI 7
|
||||
|
||||
/* This is mostly arbitrary at the moment, but gives a little room to expand. */
|
||||
#define MTD_MAX_PARTITIONS 16
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint32_t starting_lba;
|
||||
uint32_t ending_lba;
|
||||
uint32_t flags;
|
||||
uint32_t reserved;
|
||||
} __attribute__((packed)) MtdDiskPartition;
|
||||
|
||||
typedef struct {
|
||||
unsigned char signature[8];
|
||||
/* For compatibility, this is only ever the CRC of the first
|
||||
* MTD_DRIVE_V1_SIZE bytes. Further extensions must include their own CRCs,
|
||||
* so older FW can boot newer layouts if we expand in the future.
|
||||
*/
|
||||
uint32_t crc32;
|
||||
uint32_t size;
|
||||
uint32_t first_lba;
|
||||
uint32_t last_lba;
|
||||
MtdDiskPartition partitions[MTD_MAX_PARTITIONS];
|
||||
} __attribute__((packed)) MtdDiskLayout;
|
||||
|
||||
#define MTD_DRIVE_V1_SIZE (24 + 16*16)
|
||||
|
||||
#define MTDENTRY_EXPECTED_SIZE (16)
|
||||
#define MTDLAYOUT_EXPECTED_SIZE (24 + 16 * MTDENTRY_EXPECTED_SIZE)
|
||||
|
||||
|
||||
typedef struct {
|
||||
/* Specifies the flash geometry, in erase blocks & write pages */
|
||||
uint32_t flash_block_bytes;
|
||||
uint32_t flash_page_bytes;
|
||||
|
||||
/* Location, in blocks, of FTS partition */
|
||||
uint32_t fts_block_offset;
|
||||
/* Size, in blocks, of FTS partition */
|
||||
uint32_t fts_block_size;
|
||||
|
||||
/* Size of a LBA sector, in bytes */
|
||||
uint32_t sector_bytes;
|
||||
/* Size of drive in LBA sectors, in sectors */
|
||||
uint64_t drive_sectors;
|
||||
|
||||
/*
|
||||
* The current chromeos kernel index in partition table. -1 means not
|
||||
* found on drive.
|
||||
*/
|
||||
int current_kernel;
|
||||
int current_priority;
|
||||
|
||||
/* If set, the flags partition has been modified and needs to be flushed */
|
||||
int modified;
|
||||
|
||||
/* Internal variables */
|
||||
MtdDiskLayout primary;
|
||||
} MtdData;
|
||||
|
||||
|
||||
/* APIs are documented in cgptlib.h & cgptlib_internal.h */
|
||||
int MtdInit(MtdData *mtd);
|
||||
int MtdCheckParameters(MtdData *mtd);
|
||||
|
||||
int MtdNextKernelEntry(MtdData *gpt, uint64_t *start_sector, uint64_t *size);
|
||||
int MtdUpdateKernelEntry(MtdData *gpt, uint32_t update_type);
|
||||
|
||||
int MtdGetEntryPriority(const MtdDiskPartition *e);
|
||||
int MtdGetEntryTries(const MtdDiskPartition *e);
|
||||
int MtdGetEntrySuccessful(const MtdDiskPartition *e);
|
||||
int MtdGetEntryType(const MtdDiskPartition *e);
|
||||
int MtdIsKernelEntry(const MtdDiskPartition *e);
|
||||
void MtdSetEntrySuccessful(MtdDiskPartition *e, int successful) ;
|
||||
void MtdSetEntryPriority(MtdDiskPartition *e, int priority);
|
||||
void MtdSetEntryTries(MtdDiskPartition *e, int tries);
|
||||
void MtdSetEntryType(MtdDiskPartition *e, int type);
|
||||
|
||||
void MtdModified(MtdData *mtd);
|
||||
int MtdGptInit(MtdData *mtd);
|
||||
int MtdIsPartitionValid(const MtdDiskPartition *part);
|
||||
int MtdCheckEntries(MtdDiskPartition *entries, MtdDiskLayout *h);
|
||||
int MtdSanityCheck(MtdData *disk);
|
||||
void MtdRepair(MtdData *gpt);
|
||||
void MtdGetCurrentKernelUniqueGuid(MtdData *gpt, void *dest);
|
||||
uint32_t MtdHeaderCrc(MtdDiskLayout *h);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user