#include <string.h>
#include <unistd.h>
#include <stdlib.h>
-#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <inttypes.h>
target_t *target = mflash_bank->target;
int ret;
- // remove alternate function.
+ /* remove alternate function. */
mask = 0x3u << (gpio.num & 0xF)*2;
addr = PXA270_GAFR0_L + (gpio.num >> 4) * 4;
if ((ret = target_write_u32(target, addr, value)) != ERROR_OK)
return ret;
- // set direction to output
+ /* set direction to output */
mask = 0x1u << (gpio.num & 0x1F);
addr = PXA270_GPDR0 + (gpio.num >> 5) * 4;
return mflash_bank->gpio_drv->set_gpio_output_val(mflash_bank->rst_pin, level);
}
-static int mg_dump_task_reg (void)
-{
- target_t *target = mflash_bank->target;
- u32 address = mflash_bank->base + MG_REG_OFFSET + MG_REG_ERROR;
- u8 value, i;
- char *reg_name[9] = {
- "error ",
- "sector count ",
- "sector num (LBA 7- 0) ",
- "cyl. low (LBA 15- 8) ",
- "cyl. high (LBA 23-16) ",
- "drv/head ",
- "status ",
- "dev control ",
- "burst control "
- };
-
- for (i = 0; i < 9; i++) {
- target_read_u8(target, address + i * 2, &value);
- LOG_INFO("%s : 0x%2.2x", reg_name[i], value);
- }
-
- return ERROR_OK;
-
-}
static int mflash_init_gpio (void)
{
mflash_gpio_drv_t *gpio_drv = mflash_bank->gpio_drv;
duration_start_measure(&duration);
- while (time) {
-
- target_read_u8(target, mg_task_reg + MG_REG_STATUS, &status);
-
- if (status & mg_io_rbit_status_busy)
- {
- if (wait == mg_io_wait_bsy)
- return ERROR_OK;
- } else {
- switch(wait)
- {
- case mg_io_wait_not_bsy:
- return ERROR_OK;
- case mg_io_wait_rdy_noerr:
- if (status & mg_io_rbit_status_ready)
- return ERROR_OK;
- break;
- case mg_io_wait_drq_noerr:
- if (status & mg_io_rbit_status_data_req)
- return ERROR_OK;
- break;
- default:
- break;
- }
-
- // Now we check the error condition!
- if (status & mg_io_rbit_status_error)
- {
- target_read_u8(target, mg_task_reg + MG_REG_ERROR, &error);
-
- if (error & mg_io_rbit_err_bad_sect_num) {
- LOG_ERROR("sector not found");
- return ERROR_FAIL;
- }
- else if (error & (mg_io_rbit_err_bad_block | mg_io_rbit_err_uncorrectable)) {
- LOG_ERROR("bad block");
- return ERROR_FAIL;
- } else {
- LOG_ERROR("disk operation fail");
- return ERROR_FAIL;
- }
- }
-
- switch (wait)
- {
- case mg_io_wait_rdy:
- if (status & mg_io_rbit_status_ready)
- return ERROR_OK;
-
- case mg_io_wait_drq:
- if (status & mg_io_rbit_status_data_req)
- return ERROR_OK;
-
- default:
- break;
- }
- }
-
- duration_stop_measure(&duration, NULL);
-
- t=duration.duration.tv_usec/1000;
- t+=duration.duration.tv_sec*1000;
+ while (time) {
+
+ target_read_u8(target, mg_task_reg + MG_REG_STATUS, &status);
+
+ if (status & mg_io_rbit_status_busy)
+ {
+ if (wait == mg_io_wait_bsy)
+ return ERROR_OK;
+ } else {
+ switch(wait)
+ {
+ case mg_io_wait_not_bsy:
+ return ERROR_OK;
+ case mg_io_wait_rdy_noerr:
+ if (status & mg_io_rbit_status_ready)
+ return ERROR_OK;
+ break;
+ case mg_io_wait_drq_noerr:
+ if (status & mg_io_rbit_status_data_req)
+ return ERROR_OK;
+ break;
+ default:
+ break;
+ }
+
+ /* Now we check the error condition! */
+ if (status & mg_io_rbit_status_error)
+ {
+ target_read_u8(target, mg_task_reg + MG_REG_ERROR, &error);
+
+ if (error & mg_io_rbit_err_bad_sect_num) {
+ LOG_ERROR("sector not found");
+ return ERROR_FAIL;
+ }
+ else if (error & (mg_io_rbit_err_bad_block | mg_io_rbit_err_uncorrectable)) {
+ LOG_ERROR("bad block");
+ return ERROR_FAIL;
+ } else {
+ LOG_ERROR("disk operation fail");
+ return ERROR_FAIL;
+ }
+ }
+
+ switch (wait)
+ {
+ case mg_io_wait_rdy:
+ if (status & mg_io_rbit_status_ready)
+ return ERROR_OK;
+
+ case mg_io_wait_drq:
+ if (status & mg_io_rbit_status_data_req)
+ return ERROR_OK;
+
+ default:
+ break;
+ }
+ }
+
+ duration_stop_measure(&duration, NULL);
+
+ t=duration.duration.tv_usec/1000;
+ t+=duration.duration.tv_sec*1000;
if (t > time)
- break;
- }
+ break;
+ }
- LOG_ERROR("timeout occured");
- return ERROR_FAIL;
+ LOG_ERROR("timeout occured");
+ return ERROR_FAIL;
}
static int mg_dsk_srst(u8 on)
residue = sect_cnt % 256;
for (i = 0; i < quotient; i++) {
- LOG_DEBUG("sect num : %u buff : 0x%8.8x", sect_num, (u32)buff_ptr);
+ LOG_DEBUG("sect num : %u buff : 0x%0lx", sect_num,
+ (unsigned long)buff_ptr);
mg_mflash_do_read_sects(buff_ptr, sect_num, 256);
sect_num += 256;
buff_ptr += 256 * MG_MFLASH_SECTOR_SIZE;
}
if (residue) {
- LOG_DEBUG("sect num : %u buff : %8.8x", sect_num, (u32)buff_ptr);
+ LOG_DEBUG("sect num : %u buff : %0lx", sect_num,
+ (unsigned long)buff_ptr);
mg_mflash_do_read_sects(buff_ptr, sect_num, residue);
}
residue = sect_cnt % 256;
for (i = 0; i < quotient; i++) {
- LOG_DEBUG("sect num : %u buff : %8.8x", sect_num, (u32)buff_ptr);
+ LOG_DEBUG("sect num : %u buff : %0lx", sect_num,
+ (unsigned long)buff_ptr);
mg_mflash_do_write_sects(buff_ptr, sect_num, 256);
sect_num += 256;
buff_ptr += 256 * MG_MFLASH_SECTOR_SIZE;
}
if (residue) {
- LOG_DEBUG("sect num : %u buff : %8.8x", sect_num, (u32)buff_ptr);
+ LOG_DEBUG("sect num : %u buff : %0lx", sect_num,
+ (unsigned long)buff_ptr);
mg_mflash_do_write_sects(buff_ptr, sect_num, residue);
}
LOG_DEBUG("copies %u byte", end_addr - cur_addr);
}
-
}
free(sect_buff);
}
mg_mflash_write_sects(sect_buff, sect_num, 1);
-
}
if (cur_addr < end_addr) {
memcpy(sect_buff, buff_ptr, end_addr - cur_addr);
LOG_DEBUG("copies %u byte", end_addr - cur_addr);
mg_mflash_write_sects(sect_buff, sect_num, 1);
-
}
-
}
free(sect_buff);
{
u32 address, buf_cnt;
u8 *buffer;
- // TODO : multi-bank support, large file support
+ /* TODO : multi-bank support, large file support */
fileio_t fileio;
duration_t duration;
char *duration_text;
mg_mflash_probe();
}
-
if (fileio_open(&fileio, args[1], FILEIO_READ, FILEIO_BINARY) != ERROR_OK) {
return ERROR_FAIL;
}
{
u32 address, size_written, size;
u8 *buffer;
- // TODO : multi-bank support
+ /* TODO : multi-bank support */
fileio_t fileio;
duration_t duration;
char *duration_text;