Files
OpenCellular/cgpt/flash_ts_drv.c
Albert Chaulk 92f22e7c2a Bugfixes & MTD create command
Fix some bugs in the cgpt implementation of the flash I/O functions & load
logic, it was validating too much at load time.

Implement the create command for MTD

BUG=chromium:221745
TEST=MTD version of run_cgpt_tests.sh passes
BRANCH=none

Original-Change-Id: I2f52637d82962f4d805aa827c5c37685f10e76ea
Reviewed-on: https://gerrit.chromium.org/gerrit/47172
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>
(cherry picked from commit 931544744ba410dad267064b87d504b0b4c24772)

Change-Id: If9364155fb2c030645adc6ee6f3fbe5373bcc153
Reviewed-on: https://gerrit.chromium.org/gerrit/49793
Commit-Queue: Albert Chaulk <achaulk@chromium.org>
Reviewed-by: Albert Chaulk <achaulk@chromium.org>
Tested-by: Albert Chaulk <achaulk@chromium.org>
2013-06-24 15:44:41 -07:00

73 lines
1.9 KiB
C

/* 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.
*
* Utility for ChromeOS-specific GPT partitions, Please see corresponding .c
* files for more details.
*/
#include "flash_ts.h"
#include "cgpt.h"
#include "errno.h"
#include "stdio.h"
#include "string.h"
inline int page_to_sector(const nand_geom *nand, int page) {
return page * (nand->szofpg / nand->szofsector);
}
int nand_read_page(const nand_geom *nand, int page, void *buf, int size) {
uint8_t *page_buff;
if (Load((struct drive *)nand->user, &page_buff,
page_to_sector(nand, page), nand->szofsector,
(size + nand->szofsector - 1) / nand->szofsector)) {
// page may be not erased. return default data.
memset(buf, 0xff, size);
return 0;
}
memcpy(buf, page_buff, size);
free(page_buff);
return 0;
}
int nand_write_page(const nand_geom *nand,
int page, const void *buf, int buf_size) {
void *page_buff;
int ret;
int sectors = (buf_size + nand->szofsector - 1) / nand->szofsector;
int size = nand->szofsector * sectors;
page_buff = malloc(size);
if (!page_buff)
return -1;
memset(page_buff, 0xff, size);
memcpy(page_buff, buf, buf_size);
ret = Save((struct drive *)nand->user, page_buff, page_to_sector(nand, page),
nand->szofsector, sectors);
free(page_buff);
return ret;
}
int nand_erase_block(const nand_geom *nand, int block) {
int sector = block * (nand->szofblk / nand->szofsector);
int res;
void *erase_buff = malloc(nand->szofblk);
if (!erase_buff)
return -1;
memset(erase_buff, 0xff, nand->szofblk);
res = Save((struct drive *)nand->user, erase_buff, sector,
nand->szofsector, nand->szofblk / nand->szofsector);
free(erase_buff);
return res;
}
int nand_is_bad_block(const nand_geom *nand, int block) {
return 0;
}