Esempio n. 1
0
void Main(void)
{
    int count = 0;
    while (1)
    {
        if (eventq_get_count()) {
            count = 0;
            CMD_T cmd;
            eventq_get(&cmd);
            if (cmd.cmd_type == READ) {
                ftl_read(cmd.lba, cmd.sector_count);
            } else {
                if (cmd.cmd_type == WRITE) {
                    if(cmd.lba == 0x3FFFFFFF) {
                        ftl_trim(0, cmd.sector_count);
                    } else {
                        ftl_write(cmd.lba, cmd.sector_count);
                    }
                } else {
                    //uart_print_level_1("-\r\n");
                }
            }
        } else {
            if (g_sata_context.slow_cmd.status == SLOW_CMD_STATUS_PENDING) {
                //uart_print_level_1("*\r\n");
                void (*ata_function)(UINT32 lba, UINT32 sector_count);
                slow_cmd_t* slow_cmd = &g_sata_context.slow_cmd;
                slow_cmd->status = SLOW_CMD_STATUS_BUSY;
                ata_function = search_ata_function(slow_cmd->code);
                ata_function(slow_cmd->lba, slow_cmd->sector_count);
                slow_cmd->status = SLOW_CMD_STATUS_NONE;
            } else {
                count ++;
                if (count == 100000000) {
                    //uart_print_level_1(".\r\n");
                    count = 0;
                    //uart_print_level_1("Warning waiting too long in SATA main loop\r\n");
                    for (int i=0; i<NUM_BANKS; i++) {
                        if (_BSP_FSM(REAL_BANK(i)) == BANK_TAKE) {
                            uart_print_level_1("Bank "); uart_print_level_1_int(i);
                            uart_print_level_1(" (real bank "); uart_print_level_1_int(REAL_BANK(i));
                            uart_print_level_1(") in state: "); uart_print_level_1_int((UINT8)_BSP_FSM(REAL_BANK(i))); uart_print_level_1("\r\n");
                            //uart_print_level_1("Try reset\r\n");
                            //flash_reset_one_bank(i);
                            //break;
                        }
                    }
                }
            }
        }
    }
}
Esempio n. 2
0
void cmd_bdev_read(int argc, char** argv) {
	if(argc < 4) {
		bufferPrintf("Usage: %s <address> <offset> <bytes>\r\n", argv[0]);
		return;
	}

	uint32_t address = parseNumber(argv[1]);
	uint32_t offset = parseNumber(argv[2]);
	uint32_t bytes = parseNumber(argv[3]);

	bufferPrintf("Reading %d bytes, starting at %d into 0x%x\r\n", bytes, offset, address);
	bufferPrintf("ftl_read: %x\r\n", ftl_read((uint8_t*) address, offset, bytes));
}
Esempio n. 3
0
int ali_ftl_readsect(unsigned long block, unsigned long len, char *buffer)   //for TDS
{
	UINT32 nsect;
	int ret=0;

	nsect = len;
	for (; nsect > 0; nsect--, block++, buffer += 512) {
		ret=ftl_read(aliFTLDevice, block, buffer);
		if (ret) 
			return ret;
	}

	return 0;
}
Esempio n. 4
0
int bdev_setup() {
	if(HasBDevInit)
		return 0;

	ftl_setup();

	NANDData* Data = nand_get_geometry();
	BLOCK_SIZE = Data->bytesPerPage;

	ftl_read(&MBRData, 0, sizeof(MBRData));
	MBRPartitionRecord* record = MBRData.partitions;

	int id = 0;
	while(record->type != 0) {
		bufferPrintf("bdev: partition id: %d, type: %x, sectors: %d - %d\r\n", id, record->type, record->beginLBA, record->beginLBA + record->numSectors);
		record++;
		id++;
	}

	HasBDevInit = TRUE;

	return 0;
}
Esempio n. 5
0
static void tc_write_rand(const UINT32 start_lsn, const UINT32 io_num, const UINT32 sector_size)
{
    UINT32 i, j, wr_buf_addr, rd_buf_addr, data, r_data;
    UINT32 lba, num_sectors = sector_size;
    UINT32 io_cnt = io_num;

    /* UINT32 volatile g_barrier = 0; while (g_barrier == 0); */
    led(0);
    srand(RANDOM_SEED);

    for (UINT32 loop = 0; loop < 1; loop++) {
        wr_buf_addr = WR_BUF_ADDR;
        data = 0;
        uart_printf("test loop cnt: %d", loop);

        for (i = 0; i < io_cnt; i++) {
            do {
                lba = rand() % IO_LIMIT;
            }while(lba + num_sectors >= IO_LIMIT);

            wr_buf_addr = WR_BUF_PTR(g_ftl_write_buf_id) + ((lba % SECTORS_PER_PAGE) * BYTES_PER_SECTOR);
            r_data = data;

            for (j = 0; j < num_sectors; j++) {
                mem_set_dram(wr_buf_addr, data, BYTES_PER_SECTOR);

                wr_buf_addr += BYTES_PER_SECTOR;

                if (wr_buf_addr >= WR_BUF_ADDR + WR_BUF_BYTES) {
                    wr_buf_addr = WR_BUF_ADDR;
                }
                data++;
            }
/*             ptimer_start(); */
            ftl_write(lba, num_sectors);
/*             ptimer_stop_and_uart_print(); */
            rd_buf_addr = RD_BUF_PTR(g_ftl_read_buf_id) + ((lba % SECTORS_PER_PAGE) * BYTES_PER_SECTOR);
/*             ptimer_start(); */
            ftl_read(lba, num_sectors);
/*             ptimer_stop_and_uart_print(); */

            flash_finish();

            for (j = 0; j < num_sectors; j++) {
                UINT32 sample = read_dram_32(rd_buf_addr);

                if (sample != r_data) {
                    uart_printf("ftl test fail...io#: %d, %d", lba, num_sectors);
                    uart_printf("sample data %d should be %d", sample, r_data);
                    led_blink();
                }
                rd_buf_addr += BYTES_PER_SECTOR;

                if (rd_buf_addr >= RD_BUF_ADDR + RD_BUF_BYTES) {
                    rd_buf_addr = RD_BUF_ADDR;
                }
                r_data++;
            }
        } // end for
    }
    ftl_flush();
}
Esempio n. 6
0
static void tc_write_seq(const UINT32 start_lsn, const UINT32 io_num, const UINT32 sector_size)
{
    UINT32 i, j, wr_buf_addr, rd_buf_addr, data;
    UINT32 lba, num_sectors = sector_size;
    UINT32 io_cnt = io_num;
    UINT32 const start_lba = start_lsn;

    /* UINT32 volatile g_barrier = 0; while (g_barrier == 0); */
    led(0);

    // STEP 1 - write
    for (UINT32 loop = 0; loop < 5; loop++)
    {
        wr_buf_addr = WR_BUF_ADDR;
        data = 0;
        lba  = start_lba;

        uart_print_32(loop); uart_print("");

        for (i = 0; i < io_cnt; i++)
        {
            wr_buf_addr = WR_BUF_PTR(g_ftl_write_buf_id) + ((lba % SECTORS_PER_PAGE) * BYTES_PER_SECTOR);
            for (j = 0; j < num_sectors; j++)
            {
                mem_set_dram(wr_buf_addr, data, BYTES_PER_SECTOR);

                wr_buf_addr += BYTES_PER_SECTOR;

                if (wr_buf_addr >= WR_BUF_ADDR + WR_BUF_BYTES)
                {
                    wr_buf_addr = WR_BUF_ADDR;
                }
                data++;
            }
	    if( i == 0x0000081C)
		    i = i;
            ptimer_start();
            ftl_write(lba, num_sectors);
            ptimer_stop_and_uart_print();

            lba += num_sectors;

            if (lba >= (UINT32)NUM_LSECTORS)
            {
                uart_print("adjust lba because of out of lba");
                lba = 0;
            }
        }

        // STEP 2 - read and verify
        rd_buf_addr = RD_BUF_ADDR;
        data = 0;
        lba  = start_lba;
        num_sectors = MIN(num_sectors, NUM_RD_BUFFERS * SECTORS_PER_PAGE);

        for (i = 0; i < io_cnt; i++)
        {
            rd_buf_addr = RD_BUF_PTR(g_ftl_read_buf_id) + ((lba % SECTORS_PER_PAGE) * BYTES_PER_SECTOR);
            /* ptimer_start(); */
	    if( i == 0x0000081C)
		    i = i;
            ftl_read(lba, num_sectors);

            flash_finish();
            /* ptimer_stop_and_uart_print(); */

            for (j = 0; j < num_sectors; j++)
            {
                UINT32 sample = read_dram_32(rd_buf_addr);

                if (sample != data)
                {
                    uart_printf("ftl test fail...io#: %d, %d", lba, num_sectors);
                    uart_printf("sample data %d should be %d", sample, data);
                    led_blink();
                }

                rd_buf_addr += BYTES_PER_SECTOR;

                if (rd_buf_addr >= RD_BUF_ADDR + RD_BUF_BYTES)
                {
                    rd_buf_addr = RD_BUF_ADDR;
                }
                data++;
            }

            lba += num_sectors;

            if (lba >= IO_LIMIT + num_sectors)
            {
                lba = 0;
            }
        }
    }
    ftl_flush();
}
Esempio n. 7
0
int bdevRead(io_func* io, off_t location, size_t size, void *buffer) {
	MBRPartitionRecord* record = (MBRPartitionRecord*) io->data;
	//bufferPrintf("bdev: attempt to read %d sectors from partition %d, sector %Ld to 0x%x\r\n", size, ((uint32_t)record - (uint32_t)MBRData.partitions)/sizeof(MBRPartitionRecord), location, buffer);
	return ftl_read(buffer, location + record->beginLBA * BLOCK_SIZE, size);
}