-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
9,004 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
.POSIX: | ||
|
||
export PLATFORM ?=qemu_virt4 | ||
export ROOT :=${abspath ../..} | ||
export BUILD :=${abspath build/${PLATFORM}} | ||
export S3K_CONF_H :=${abspath s3k_conf.h} | ||
|
||
include ${ROOT}/tools.mk | ||
|
||
APPS=app0 | ||
|
||
ELFS:=${patsubst %, ${BUILD}/%.elf, kernel ${APPS}} | ||
|
||
all: kernel ${APPS} | ||
|
||
clean: | ||
rm -rf ${BUILD} | ||
|
||
common: | ||
@${MAKE} -C ${ROOT}/common | ||
|
||
kernel: common | ||
@${MAKE} -C ${ROOT}/kernel | ||
|
||
${APPS}: common | ||
@${MAKE} -f ../build.mk PROGRAM=$@ | ||
|
||
qemu: kernel ${APPS} | ||
@ELFS="${ELFS}" ${ROOT}/scripts/qemu.sh -drive file=fs.img,if=none,format=raw,id=x0 -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0 | ||
|
||
qemu-gdb: kernel ${APPS} | ||
@ELFS="${ELFS}" ${ROOT}/scripts/qemu.sh -gdb tcp::3333 -S -drive file=fs.img,if=none,format=raw,id=x0 -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0 | ||
|
||
gdb: kernel ${APPS} | ||
@ELFS="${ELFS}" ${ROOT}/scripts/gdb.sh | ||
|
||
gdb-openocd: kernel ${APPS} | ||
@ELFS="${ELFS}" ${ROOT}/scripts/gdb-openocd.sh | ||
|
||
size: ${ELFS} | ||
${SIZE} ${ELFS} | ||
|
||
.PHONY: all clean size qemu qemu-gdb gdb kernel common ${APPS} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
MEMORY { | ||
RAM (rwx) : ORIGIN = 0x80010000, LENGTH = 0x10000 | ||
} | ||
|
||
__stack_size = 1024; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef BUF_H_ | ||
#define BUF_H_ | ||
|
||
// FS specific | ||
#define BSIZE 512 // block size | ||
|
||
struct buf { | ||
int valid; // has data been read from disk? | ||
int disk; // does disk "own" buf? | ||
uint dev; | ||
uint blockno; | ||
/* struct sleeplock lock; */ | ||
uint refcnt; | ||
struct buf *prev; // LRU cache list | ||
struct buf *next; | ||
uchar data[BSIZE]; | ||
}; | ||
|
||
#endif // BUF_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
/*-----------------------------------------------------------------------*/ | ||
/* Low level disk I/O module SKELETON for FatFs (C)ChaN, 2019 */ | ||
/*-----------------------------------------------------------------------*/ | ||
/* If a working storage control module is available, it should be */ | ||
/* attached to the FatFs via a glue function rather than modifying it. */ | ||
/* This is an example of glue functions to attach various exsisting */ | ||
/* storage control modules to the FatFs module with a defined API. */ | ||
/*-----------------------------------------------------------------------*/ | ||
|
||
#include "ff.h" /* Obtains integer types */ | ||
#include "diskio.h" /* Declarations of disk functions */ | ||
#include "virtio_disk.h" | ||
#include <string.h> | ||
|
||
/* Definitions of physical drive number for each drive */ | ||
#define DEV_VIRTIO 0 /* Example: Map Virtiodisk to physical drive 0 */ | ||
|
||
|
||
/*-----------------------------------------------------------------------*/ | ||
/* Get Drive Status */ | ||
/*-----------------------------------------------------------------------*/ | ||
|
||
DSTATUS disk_status ( | ||
BYTE pdrv /* Physical drive nmuber to identify the drive */ | ||
) | ||
{ | ||
switch (pdrv) { | ||
case DEV_VIRTIO : | ||
if (virtio_disk_status()) | ||
return 0; | ||
} | ||
return STA_NOINIT; | ||
} | ||
|
||
|
||
|
||
/*-----------------------------------------------------------------------*/ | ||
/* Inidialize a Drive */ | ||
/*-----------------------------------------------------------------------*/ | ||
|
||
DSTATUS disk_initialize ( | ||
BYTE pdrv /* Physical drive nmuber to identify the drive */ | ||
) | ||
{ | ||
switch (pdrv) { | ||
case DEV_VIRTIO : | ||
virtio_disk_init(); | ||
return disk_status(pdrv); | ||
} | ||
|
||
return STA_NOINIT; | ||
} | ||
|
||
|
||
|
||
/*-----------------------------------------------------------------------*/ | ||
/* Read Sector(s) */ | ||
/*-----------------------------------------------------------------------*/ | ||
|
||
DRESULT disk_read ( | ||
BYTE pdrv, /* Physical drive nmuber to identify the drive */ | ||
BYTE *buff, /* Data buffer to store read data */ | ||
LBA_t sector, /* Start sector in LBA */ | ||
UINT count /* Number of sectors to read */ | ||
) | ||
{ | ||
switch (pdrv) { | ||
case DEV_VIRTIO : | ||
// translate the arguments here | ||
if (disk_status(pdrv) & STA_NOINIT) return RES_NOTRDY; | ||
|
||
struct buf buffer; | ||
do { | ||
buffer.blockno = sector; | ||
memset(buffer.data, 0, sizeof(buffer.data)); | ||
virtio_disk_rw(&buffer, 0); | ||
memcpy(buff, buffer.data, 512); | ||
buff += 512; | ||
} while (--count); | ||
return RES_OK; | ||
} | ||
|
||
return RES_PARERR; | ||
} | ||
|
||
|
||
|
||
/*-----------------------------------------------------------------------*/ | ||
/* Write Sector(s) */ | ||
/*-----------------------------------------------------------------------*/ | ||
|
||
#if FF_FS_READONLY == 0 | ||
|
||
DRESULT disk_write ( | ||
BYTE pdrv, /* Physical drive nmuber to identify the drive */ | ||
const BYTE *buff, /* Data to be written */ | ||
LBA_t sector, /* Start sector in LBA */ | ||
UINT count /* Number of sectors to write */ | ||
) | ||
{ | ||
switch (pdrv) { | ||
case DEV_VIRTIO : | ||
// translate the arguments here | ||
if (disk_status(pdrv) & STA_NOINIT) return RES_NOTRDY; | ||
|
||
struct buf buffer; | ||
do { | ||
buffer.blockno = sector; | ||
memcpy(buffer.data, buff, 512); | ||
virtio_disk_rw(&buffer, 1); | ||
buff += 512; | ||
} while (--count); | ||
return RES_OK; | ||
} | ||
|
||
return RES_PARERR; | ||
} | ||
|
||
#endif | ||
|
||
|
||
/*-----------------------------------------------------------------------*/ | ||
/* Miscellaneous Functions */ | ||
/*-----------------------------------------------------------------------*/ | ||
|
||
DRESULT disk_ioctl ( | ||
BYTE drv, /* Physical drive nmuber (0) */ | ||
BYTE ctrl, /* Control code */ | ||
void *buff /* Buffer to send/receive control data */ | ||
) | ||
{ | ||
DRESULT res; | ||
|
||
|
||
if (disk_status(drv) & STA_NOINIT) return RES_NOTRDY; /* Check if card is in the socket */ | ||
|
||
res = RES_ERROR; | ||
switch (ctrl) { | ||
case CTRL_SYNC : /* Make sure that no pending write process */ | ||
return RES_OK; | ||
break; | ||
|
||
case GET_SECTOR_SIZE : /* Get number of sectors on the disk (DWORD) */ | ||
*(DWORD*)buff = 512; | ||
return RES_OK; | ||
break; | ||
|
||
case GET_SECTOR_COUNT : /* Get number of sectors on the disk (DWORD) */ | ||
*(LBA_t*)buff = 10*1024*1024/512; | ||
return RES_OK; | ||
break; | ||
|
||
case GET_BLOCK_SIZE : /* Get erase block size in unit of sector (DWORD) */ | ||
*(DWORD*)buff = 1; | ||
res = RES_OK; | ||
break; | ||
|
||
default: | ||
res = RES_PARERR; | ||
} | ||
|
||
return res; | ||
} | ||
|
||
DWORD get_fattime (void) { | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/*-----------------------------------------------------------------------/ | ||
/ Low level disk interface modlue include file (C)ChaN, 2019 / | ||
/-----------------------------------------------------------------------*/ | ||
|
||
#ifndef _DISKIO_DEFINED | ||
#define _DISKIO_DEFINED | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/* Status of Disk Functions */ | ||
typedef BYTE DSTATUS; | ||
|
||
/* Results of Disk Functions */ | ||
typedef enum { | ||
RES_OK = 0, /* 0: Successful */ | ||
RES_ERROR, /* 1: R/W Error */ | ||
RES_WRPRT, /* 2: Write Protected */ | ||
RES_NOTRDY, /* 3: Not Ready */ | ||
RES_PARERR /* 4: Invalid Parameter */ | ||
} DRESULT; | ||
|
||
|
||
/*---------------------------------------*/ | ||
/* Prototypes for disk control functions */ | ||
|
||
|
||
DSTATUS disk_initialize (BYTE pdrv); | ||
DSTATUS disk_status (BYTE pdrv); | ||
DRESULT disk_read (BYTE pdrv, BYTE* buff, LBA_t sector, UINT count); | ||
DRESULT disk_write (BYTE pdrv, const BYTE* buff, LBA_t sector, UINT count); | ||
DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff); | ||
|
||
|
||
/* Disk Status Bits (DSTATUS) */ | ||
|
||
#define STA_NOINIT 0x01 /* Drive not initialized */ | ||
#define STA_NODISK 0x02 /* No medium in the drive */ | ||
#define STA_PROTECT 0x04 /* Write protected */ | ||
|
||
|
||
/* Command code for disk_ioctrl fucntion */ | ||
|
||
/* Generic command (Used by FatFs) */ | ||
#define CTRL_SYNC 0 /* Complete pending write process (needed at FF_FS_READONLY == 0) */ | ||
#define GET_SECTOR_COUNT 1 /* Get media size (needed at FF_USE_MKFS == 1) */ | ||
#define GET_SECTOR_SIZE 2 /* Get sector size (needed at FF_MAX_SS != FF_MIN_SS) */ | ||
#define GET_BLOCK_SIZE 3 /* Get erase block size (needed at FF_USE_MKFS == 1) */ | ||
#define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at FF_USE_TRIM == 1) */ | ||
|
||
/* Generic command (Not used by FatFs) */ | ||
#define CTRL_POWER 5 /* Get/Set power status */ | ||
#define CTRL_LOCK 6 /* Lock/Unlock media removal */ | ||
#define CTRL_EJECT 7 /* Eject media */ | ||
#define CTRL_FORMAT 8 /* Create physical format on the media */ | ||
|
||
/* MMC/SDC specific ioctl command */ | ||
#define MMC_GET_TYPE 10 /* Get card type */ | ||
#define MMC_GET_CSD 11 /* Get CSD */ | ||
#define MMC_GET_CID 12 /* Get CID */ | ||
#define MMC_GET_OCR 13 /* Get OCR */ | ||
#define MMC_GET_SDSTAT 14 /* Get SD status */ | ||
#define ISDIO_READ 55 /* Read data form SD iSDIO register */ | ||
#define ISDIO_WRITE 56 /* Write data to SD iSDIO register */ | ||
#define ISDIO_MRITE 57 /* Masked write data to SD iSDIO register */ | ||
|
||
/* ATA/CF specific ioctl command */ | ||
#define ATA_GET_REV 20 /* Get F/W revision */ | ||
#define ATA_GET_MODEL 21 /* Get model name */ | ||
#define ATA_GET_SN 22 /* Get serial number */ | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif |
Oops, something went wrong.