2016-11-02 10:24:25 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Intel Corporation.
|
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-11-02 10:24:25 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
Introduce new sized integer typedefs
This is a start to move away from the C99 {u}int{8,16,32,64}_t types to
Zephyr defined u{8,16,32,64}_t and s{8,16,32,64}_t. This allows Zephyr
to define the sized types in a consistent manor across all the
architectures we support and not conflict with what various compilers
and libc might do with regards to the C99 types.
We introduce <zephyr/types.h> as part of this and have it include
<stdint.h> for now until we transition all the code away from the C99
types.
We go with u{8,16,32,64}_t and s{8,16,32,64}_t as there are some
existing variables defined u8 & u16 as well as to be consistent with
Zephyr naming conventions.
Jira: ZEP-2051
Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-19 23:32:08 +08:00
|
|
|
#include <zephyr/types.h>
|
2016-11-02 10:24:25 +08:00
|
|
|
#include <misc/__assert.h>
|
|
|
|
#include <disk_access.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#define RAMDISK_SECTOR_SIZE 512
|
|
|
|
|
|
|
|
#if defined(CONFIG_USB_MASS_STORAGE)
|
|
|
|
/* A 16KB initialized RAMdisk which will fit on most target's RAM. It
|
|
|
|
* is initialized with a valid file system for validating USB mass storage.
|
|
|
|
*/
|
|
|
|
#include "fat12_ramdisk.h"
|
|
|
|
#else
|
|
|
|
/* A 96KB RAM Disk, which meets ELM FAT fs's minimum block requirement. Fit for
|
|
|
|
* qemu testing (as it may exceed target's RAM limits).
|
|
|
|
*/
|
|
|
|
#define RAMDISK_VOLUME_SIZE (192 * RAMDISK_SECTOR_SIZE)
|
2017-04-21 22:36:04 +08:00
|
|
|
static u8_t ramdisk_buf[RAMDISK_VOLUME_SIZE];
|
2016-11-02 10:24:25 +08:00
|
|
|
#endif
|
|
|
|
|
2017-04-21 22:36:04 +08:00
|
|
|
static void *lba_to_address(u32_t lba)
|
2016-11-02 10:24:25 +08:00
|
|
|
{
|
|
|
|
__ASSERT(((lba * RAMDISK_SECTOR_SIZE) < RAMDISK_VOLUME_SIZE),
|
2016-12-01 05:27:42 +08:00
|
|
|
"FS bound error");
|
|
|
|
|
2016-11-02 10:24:25 +08:00
|
|
|
return &ramdisk_buf[(lba * RAMDISK_SECTOR_SIZE)];
|
|
|
|
}
|
|
|
|
|
|
|
|
int disk_access_status(void)
|
|
|
|
{
|
|
|
|
return DISK_STATUS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int disk_access_init(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-04-21 22:36:04 +08:00
|
|
|
int disk_access_read(u8_t *buff, u32_t sector, u32_t count)
|
2016-11-02 10:24:25 +08:00
|
|
|
{
|
|
|
|
memcpy(buff, lba_to_address(sector), count * RAMDISK_SECTOR_SIZE);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-04-21 22:36:04 +08:00
|
|
|
int disk_access_write(const u8_t *buff, u32_t sector, u32_t count)
|
2016-11-02 10:24:25 +08:00
|
|
|
{
|
|
|
|
memcpy(lba_to_address(sector), buff, count * RAMDISK_SECTOR_SIZE);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-04-21 22:36:04 +08:00
|
|
|
int disk_access_ioctl(u8_t cmd, void *buff)
|
2016-11-02 10:24:25 +08:00
|
|
|
{
|
|
|
|
switch (cmd) {
|
|
|
|
case DISK_IOCTL_CTRL_SYNC:
|
|
|
|
break;
|
|
|
|
case DISK_IOCTL_GET_SECTOR_COUNT:
|
2017-04-21 22:36:04 +08:00
|
|
|
*(u32_t *)buff = RAMDISK_VOLUME_SIZE / RAMDISK_SECTOR_SIZE;
|
2016-11-02 10:24:25 +08:00
|
|
|
break;
|
|
|
|
case DISK_IOCTL_GET_SECTOR_SIZE:
|
2017-04-21 22:36:04 +08:00
|
|
|
*(u32_t *)buff = RAMDISK_SECTOR_SIZE;
|
2016-11-02 10:24:25 +08:00
|
|
|
break;
|
|
|
|
case DISK_IOCTL_GET_ERASE_BLOCK_SZ:
|
2017-04-21 22:36:04 +08:00
|
|
|
*(u32_t *)buff = 1;
|
2016-11-02 10:24:25 +08:00
|
|
|
break;
|
|
|
|
case DISK_IOCTL_GET_DISK_SIZE:
|
2017-04-21 22:36:04 +08:00
|
|
|
*(u32_t *)buff = RAMDISK_VOLUME_SIZE;
|
2016-11-02 10:24:25 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|