53 #define PXA270_GAFR0_L 0x40E00054 54 #define PXA270_GAFR3_U 0x40E00070 55 #define PXA270_GAFR3_U_RESERVED_BITS 0xfffc0000u 56 #define PXA270_GPDR0 0x40E0000C 57 #define PXA270_GPDR3 0x40E0010C 58 #define PXA270_GPDR3_RESERVED_BITS 0xfe000000u 59 #define PXA270_GPSR0 0x40E00018 60 #define PXA270_GPCR0 0x40E00024 69 mask = 0x3u << (gpio.
num & 0xF)*2;
86 mask = 0x1u << (gpio.
num & 0x1F);
108 mask = 0x1u << (gpio.
num & 0x1F);
126 #define S3C2440_GPACON 0x56000000 127 #define S3C2440_GPADAT 0x56000004 128 #define S3C2440_GPJCON 0x560000d0 129 #define S3C2440_GPJDAT 0x560000d4 133 uint32_t data,
mask, gpio_con;
137 if (gpio.
port[0] >=
'a' && gpio.
port[0] <=
'h')
139 else if (gpio.
port[0] ==
'j')
149 if (gpio.
port[0] ==
'a') {
150 mask = 1 << gpio.
num;
153 mask = 3 << gpio.
num * 2;
155 data |= (1 << gpio.
num * 2);
165 uint32_t data,
mask, gpio_dat;
169 if (gpio.
port[0] >=
'a' && gpio.
port[0] <=
'h')
171 else if (gpio.
port[0] ==
'j')
181 mask = 1 << gpio.
num;
213 uint8_t status, error;
232 switch (wait_local) {
253 LOG_ERROR(
"mflash: io error 0x%02x", error);
258 switch (wait_local) {
276 LOG_ERROR(
"mflash: duration measurement failed: %d", ret);
345 LOG_INFO(
"mflash: read drive info");
427 "mflash (total %" PRIu32
" sectors) found at 0x%8.8" PRIx32
"",
440 uint8_t *buff_ptr = buff;
451 for (i = 0; i < sect_cnt; i++) {
468 LOG_DEBUG(
"mflash: %" PRIu32
" (0x%8.8" PRIx32
") sector read", sect_num + i,
473 LOG_INFO(
"mflash: read %" PRIu32
"'th sectors", sect_num + i);
483 uint32_t quotient, residue, i;
484 uint8_t *buff_ptr = buff;
487 quotient = sect_cnt >> 8;
488 residue = sect_cnt % 256;
490 for (i = 0; i < quotient; i++) {
491 LOG_DEBUG(
"mflash: sect num : %" PRIu32
" buff : %p",
502 LOG_DEBUG(
"mflash: sect num : %" PRIx32
" buff : %p",
516 uint8_t *buff_ptr = buff;
527 for (i = 0; i < sect_cnt; i++) {
544 LOG_DEBUG(
"mflash: %" PRIu32
" (0x%8.8" PRIx32
") sector write", sect_num + i,
549 LOG_INFO(
"mflash: wrote %" PRIu32
"'th sectors", sect_num + i);
564 uint32_t quotient, residue, i;
565 uint8_t *buff_ptr = buff;
568 quotient = sect_cnt >> 8;
569 residue = sect_cnt % 256;
571 for (i = 0; i < quotient; i++) {
572 LOG_DEBUG(
"mflash: sect num : %" PRIu32
"buff : %p", sect_num,
583 LOG_DEBUG(
"mflash: sect num : %" PRIu32
" buff : %p", sect_num,
593 uint8_t *buff_ptr = buff;
595 uint32_t cur_addr, next_sec_addr, end_addr, cnt, sect_num;
600 end_addr = addr + len;
610 if (end_addr < next_sec_addr) {
612 sect_buff + (cur_addr & MG_MFLASH_SECTOR_SIZE_MASK),
613 end_addr - cur_addr);
615 "mflash: copies %" PRIu32
" byte from sector offset 0x%8.8" PRIx32
"",
621 sect_buff + (cur_addr & MG_MFLASH_SECTOR_SIZE_MASK),
622 next_sec_addr - cur_addr);
624 "mflash: copies %" PRIu32
" byte from sector offset 0x%8.8" PRIx32
"",
625 next_sec_addr - cur_addr,
627 buff_ptr += (next_sec_addr - cur_addr);
628 cur_addr = next_sec_addr;
632 if (cur_addr < end_addr) {
637 while (next_sec_addr <= end_addr) {
651 if (cur_addr < end_addr) {
658 memcpy(buff_ptr, sect_buff, end_addr - cur_addr);
659 LOG_DEBUG(
"mflash: copies %u byte", (
unsigned)(end_addr - cur_addr));
668 uint8_t *buff_ptr = buff;
670 uint32_t cur_addr, next_sec_addr, end_addr, cnt, sect_num;
675 end_addr = addr + len;
685 if (end_addr < next_sec_addr) {
686 memcpy(sect_buff + (cur_addr & MG_MFLASH_SECTOR_SIZE_MASK),
688 end_addr - cur_addr);
690 "mflash: copies %" PRIu32
" byte to sector offset 0x%8.8" PRIx32
"",
695 memcpy(sect_buff + (cur_addr & MG_MFLASH_SECTOR_SIZE_MASK),
697 next_sec_addr - cur_addr);
699 "mflash: copies %" PRIu32
" byte to sector offset 0x%8.8" PRIx32
"",
700 next_sec_addr - cur_addr,
702 buff_ptr += (next_sec_addr - cur_addr);
703 cur_addr = next_sec_addr;
711 if (cur_addr < end_addr) {
716 while (next_sec_addr <= end_addr) {
730 if (cur_addr < end_addr) {
737 memcpy(sect_buff, buff_ptr, end_addr - cur_addr);
738 LOG_DEBUG(
"mflash: copies %" PRIu32
" byte", end_addr - cur_addr);
748 uint32_t address, cnt, res, i;
782 for (i = 0; i < cnt; i++) {
785 goto mg_write_cmd_err;
788 goto mg_write_cmd_err;
795 goto mg_write_cmd_err;
798 goto mg_write_cmd_err;
803 "in %fs (%0.3f kB/s)", filesize,
CMD_ARGV[1],
821 uint32_t address, size, cnt, res, i;
849 for (i = 0; i < cnt; i++) {
852 goto mg_dump_cmd_err;
855 goto mg_dump_cmd_err;
862 goto mg_dump_cmd_err;
865 goto mg_dump_cmd_err;
870 "size %" PRIu32
") to file %s in %fs (%0.3f kB/s)",
908 double v2 = CLK_OUT * NO;
910 if (v1 < 1000000 || v1 > 15000000 || v2 < 100000000 || v2 > 500000000)
920 for (i = 1, M = 0; i < 512; i <<= 1, feedback_div >>= 1)
921 M += (feedback_div & 1) * i;
930 for (i = 1, N = 0; i < 32; i <<= 1, input_div >>= 1)
931 N += (input_div & 1) * i;
940 for (i = 0, NO = 1; i < 2; ++i, output_div >>= 1)
956 if (is_approximate) {
970 CLK_OUT = XIN * ((double)M / N) / NO;
972 if ((
int)((CLK_OUT + ROUND) / DIV)
1012 for (j = 0; j < 10; j++) {
1013 for (i = 0; i < MG_MFLASH_SECTOR_SIZE >> 1; i++)
1028 for (i = 0; i < MG_MFLASH_SECTOR_SIZE >> 1; i++) {
1030 LOG_ERROR(
"mflash: verify interface fail");
1036 LOG_INFO(
"mflash: verify interface ok");
1041 'G',
'm',
'n',
'i',
'-',
'e',
'e',
'S',
'g',
'a',
'e',
'l',
1042 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
1046 'F',
'X',
'L',
'T',
'2',
'v',
'0',
'.' 1050 'F',
'X',
'A',
'L',
'H',
'S',
'2', 0x20,
'0',
'0',
's',
'7',
1051 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
1052 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
1053 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
1132 memset(pSegIdDrvInfo->
reserved3, 0x00, 22);
1156 memset(pSegIdDrvInfo->
reserved6, 0x00, 68);
1162 memset(pSegIdDrvInfo->
reserved7, 0x00, 190);
1184 LOG_INFO(
"mflash: storage config ok");
1197 memset(buff, 0xff, 512);
1202 *((uint32_t *)(
void *)(buff + 4)) = 0;
1212 LOG_INFO(
"mflash: boot config ok");
1221 memset(buff, 0xff, 512);
1223 memcpy(buff, &pll->
lock_cyc,
sizeof(uint32_t));
1224 memcpy(buff + 4, &pll->
feedback_div,
sizeof(uint16_t));
1282 else if (!strcmp(
CMD_ARGV[1],
"storage"))
1294 LOG_ERROR(
"mflash: input freq. is too large");
1301 LOG_ERROR(
"mflash: cannot generate valid pll");
1305 LOG_INFO(
"mflash: Fout=%" PRIu32
" Hz, feedback=%u," 1306 "indiv=%u, outdiv=%u, lock=%u",
1327 .handler = mg_probe_cmd,
1329 .help =
"Detect bank configuration information",
1333 .handler = mg_write_cmd,
1336 .usage =
"bank_num filename address",
1337 .help =
"Write binary file at the specified address.",
1341 .handler = mg_dump_cmd,
1344 .usage =
"bank_num filename address size",
1345 .help =
"Write specified number of bytes from a binary file " 1346 "to the specified, address.",
1350 .handler = mg_config_cmd,
1352 .help =
"Configure MFLASH options.",
1353 .usage =
"('boot'|'storage'|'pll' frequency)",
1370 static bool mflash_initialized;
1371 if (mflash_initialized) {
1372 LOG_INFO(
"'mflash init' has already been called");
1375 mflash_initialized =
true;
1377 LOG_DEBUG(
"Initializing mflash devices...");
1390 if (target ==
NULL) {
1395 mflash_bank = calloc(
sizeof(
struct mflash_bank), 1);
1402 tolower((
unsigned)str[0]);
1404 mflash_bank->
target = target;
1406 for (i = 0; mflash_gpio[i]; i++) {
1408 mflash_bank->
gpio_drv = mflash_gpio[i];
1422 .handler = mg_bank_cmd,
1424 .help =
"configure a mflash device bank",
1425 .usage =
"soc_type base_addr pin_id target",
1430 .handler = handle_mflash_init_command,
1431 .help =
"initialize mflash devices",
1440 .help =
"mflash command group",
mg_io_uint16 total_user_addressable_sectors_hi
struct mg_drv_info * drv_info
static int mg_dsk_drv_info(void)
#define MG_PLL_STD_LOCKCYCLE
int fileio_size(struct fileio *fileio, size_t *size)
FIX!!!!
static struct mflash_gpio_drv s3c2440_gpio
#define LOG_DEBUG(expr...)
static const struct command_registration mflash_config_command_handlers[]
#define PXA270_GAFR3_U_RESERVED_BITS
int target_write_u8(struct target *target, uint32_t address, uint8_t value)
static int mg_set_feature(mg_feature_id feature, mg_feature_val config)
mg_io_uint16 capabilities
mg_io_uint16 req_time_for_security_er_done
static int mg_set_pll(mg_pll_t *pll)
#define ERROR_MG_UNSUPPORTED_SOC
static int mg_mflash_read_sects(void *buff, uint32_t sect_num, uint32_t sect_cnt)
int register_commands(struct command_context *cmd_ctx, struct command *parent, const struct command_registration *cmds)
Register one or more commands in the specified context, as children of parent (or top-level commends...
int duration_measure(struct duration *duration)
Update the duration->elapsed field to finish the duration measurment.
static int s3c2440_set_gpio_to_output(struct mflash_gpio_num gpio)
#define MG_PLL_STD_INPUTCLK
struct mflash_gpio_drv * gpio_drv
int target_write_memory(struct target *target, uint32_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Write count items of size bytes to the memory of target at the address given.
#define PXA270_GPDR3_RESERVED_BITS
mg_io_uint8 maximum_block_transfer
mg_io_uint16 req_time_for_enhan_security_er_done
static int pxa270_set_gpio_to_output(struct mflash_gpio_num gpio)
static double mg_calc_pll(double XIN, mg_pll_t *p_pll_val)
struct target * get_target(const char *id)
mg_io_uint8 vendor_unique2
mg_io_uint8 reserved7[186]
#define LOG_INFO(expr...)
mg_io_uint8 pio_cycle_timing_mode
static int mg_mflash_write(uint32_t addr, uint8_t *buff, uint32_t len)
static int mg_pll_get_M(unsigned short feedback_div)
static int mg_verify_interface(void)
static int s3c2440_set_gpio_output_val(struct mflash_gpio_num gpio, uint8_t val)
#define ERROR_MG_INVALID_PLL
mg_io_uint16 minor_ver_num
mg_io_uint16 unformatted_bytes_per_sector
mg_io_uint16 feature_cmd_set_suprt2
mg_io_uint16 total_user_addressable_sectors_lo
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
int(* set_gpio_to_output)(struct mflash_gpio_num gpio)
#define MG_MFLASH_SECTOR_SIZE_SHIFT
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
mg_io_uint8 vendor_unique3
mg_io_uint16 current_sector_capacity_lo
static int mg_pll_get_N(unsigned char input_div)
mg_io_uint16 number_of_cylinders
int mflash_register_commands(struct command_context *cmd_ctx)
static int mg_hdrst(uint8_t level)
static const struct command_registration mflash_exec_command_handlers[]
mg_io_uint16 number_of_current_heads
static int mg_mflash_do_write_sects(void *buff, uint32_t sect_num, uint32_t sect_cnt, uint8_t cmd)
static const char g_strSEG_SerialNum[20]
mg_io_uint16 number_of_heads
#define ERROR_MG_INTERFACE
mg_io_uint8 single_dma_transfer_active
mg_io_uint16 feature_cmd_set_suprt0
static const char g_strSEG_ModelNum[40]
mg_io_uint16 unformatted_bytes_per_track
int target_read_memory(struct target *target, uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer)
Read count items of size bytes from the memory of target at the address given.
static int mg_mflash_write_sects(void *buff, uint32_t sect_num, uint32_t sect_cnt)
#define COMMAND_PARSE_NUMBER(type, in, out)
parses the string in into out as a type, or prints a command error and passes the error code to the c...
mg_io_uint16 feature_cmd_set_suprt1
mg_io_uint16 number_of_ecc_bytes
#define MG_PLL_MAX_INPUTDIV_VAL
static int mg_dsk_io_cmd(uint32_t sect_num, uint32_t cnt, uint8_t cmd)
static void mg_gen_ataid(mg_io_type_drv_info *pSegIdDrvInfo)
mg_io_uint16 adv_pio_mode
int target_read_u32(struct target *target, uint32_t address, uint32_t *value)
mg_io_uint16 major_ver_num
static int mg_storage_config(void)
mg_io_type_drv_info drv_id
mg_io_uint16 recommend_dma_cyc
static struct device_config config
static const char g_strSEG_FWRev[8]
mg_io_uint16 general_configuration
mg_io_uint8 multi_dma_modes_supported
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
mg_io_uint16 cfa_pwr_mode
#define LOG_ERROR(expr...)
#define ERROR_COMMAND_SYNTAX_ERROR
static int mg_init_gpio(void)
int target_read_u8(struct target *target, uint32_t address, uint8_t *value)
float duration_elapsed(const struct duration *duration)
mg_io_uint16 sectors_per_track
static int mg_erase_nand(void)
mg_io_uint8 reserved6[68]
int(* set_gpio_output_val)(struct mflash_gpio_num gpio, uint8_t val)
static int mg_boot_config(void)
int fileio_read(struct fileio *fileio, size_t size, void *buffer, size_t *size_read)
mg_io_uint8 firmware_revision[8]
static const struct command_registration mflash_command_handler[]
#define CMD_CTX
Use this macro to access the context of the command being handled, rather than accessing the variable...
struct mflash_gpio_num rst_pin
static double mg_do_calc_pll(double XIN, mg_pll_t *p_pll_val, int is_approximate)
mg_io_uint8 single_dma_modes_supported
#define MG_MFLASH_SECTOR_SIZE_MASK
mg_io_uint8 dma_cycle_timing_mode
mg_io_uint16 translation_fields_valid
static struct mflash_gpio_drv * mflash_gpio[]
float duration_kbps(const struct duration *duration, size_t count)
enum _mg_feature_val mg_feature_val
enum _mg_feature_id mg_feature_id
mg_io_uint8 multi_dma_transfer_active
static int mg_mflash_read(uint32_t addr, uint8_t *buff, uint32_t len)
static int mg_dsk_srst(uint8_t on)
static int pxa270_set_gpio_output_val(struct mflash_gpio_num gpio, uint8_t val)
mg_io_uint16 adv_pwr_mgm_lvl_val
enum _mg_io_type_wait mg_io_type_wait
#define MG_PLL_MAX_OUTPUTDIV_VAL
mg_io_uint16 min_pio_cyc_no_iordy
mg_io_uint8 multi_sector_setting_valid
COMMAND_HANDLER(mg_probe_cmd)
mg_io_uint16 security_stas
#define MG_PLL_MAX_FEEDBACKDIV_VAL
void command_print(struct command_context *context, const char *format,...)
mg_io_uint16 number_of_current_cylinders
#define MG_OEM_DISK_WAIT_TIME_NORMAL
static struct mflash_gpio_drv pxa270_gpio
mg_io_uint8 multi_sector_count
static int mg_mflash_probe(void)
#define ERROR_COMMAND_NOTFOUND
mg_io_uint16 feature_cmd_set_en1
mg_io_uint16 current_sector_capacity_hi
static int mg_dsk_wait(mg_io_type_wait wait_local, uint32_t time_var)
mg_io_uint8 model_number[40]
int target_write_u32(struct target *target, uint32_t address, uint32_t value)
mg_io_uint16 vendor_unique1[3]
static int mg_mflash_do_read_sects(void *buff, uint32_t sect_num, uint32_t sect_cnt)
static struct mflash_bank * mflash_bank
int fileio_close(struct fileio *fileio)
#define ERROR_MG_INVALID_OSC
mg_io_uint16 feature_cmd_set_en0
int fileio_write(struct fileio *fileio, size_t size, const void *buffer, size_t *size_written)
static int mg_pll_get_NO(unsigned char output_div)
mg_io_uint16 current_sectors_per_track
static int mg_mflash_rst(void)
static int mflash_init_drivers(struct command_context *cmd_ctx)
static int mg_is_valid_pll(double XIN, int N, double CLK_OUT, int NO)
int fileio_open(struct fileio **fileio, const char *url, enum fileio_access access_type, enum fileio_type type)
#define MG_OEM_DISK_WAIT_TIME_LONG
#define MG_MFLASH_SECTOR_SIZE
mg_io_uint8 vendor_unique4
mg_io_uint8 vendor_uniq_bytes[62]
mg_io_uint8 reserved3[22]
mg_io_uint8 serial_number[20]
mg_io_uint16 feature_cmd_set_en2
int duration_start(struct duration *duration)
Update the duration->start field to start the duration measurement.
mg_io_uint16 min_pio_cyc_with_iordy
mg_io_uint16 buffer_sector_size
unsigned short feedback_div
#define MG_UNLOCK_OTP_AREA