/*
* MX25L6406Es
* 2016 01 11
* ȲŒº¿¬,ÀÌ»óŒ·
*/
#define F_CPU 16000000UL
#include <avr/io.h>
#include <string.h>
#include <util/delay.h>
#include <stdio.h>
#define SPI_DDR DDRB
#define SPI_PORT PORTB
#define SS PB0
#define SCK PB1
#define MOSI PB2
#define MISO PB3
void put_c(char data){
while(!(UCSR0A & 0x20));
UDR0 = data;
}
void Puts(char *data)
{
int i;
for(i=0; i<strlen(data); i++)
{
while(!(UCSR0A & 0x20));
UDR0 = data[i];
}
}
void SPI_init_master()
{
SPI_PORT |= (1 << SS);
SPI_DDR |= ((1 << SS) | (1 << SCK) | (1 << MOSI) | (1 << MISO));
SPCR = 0x51; // 0x40 = 16MHz
}
void init_uart()
{
// initializing UART
UCSR0A = 0x00;
UCSR0B = 0x98;
UCSR0C = 0x06;
UBRR0H = 0;
UBRR0L = 8; // 115200
}
char SPI_IO(char data, int ins)
{
SPDR = data; /* µ¥ÀÌÅÍžŠ ºž³»°í */
while(!(SPSR & 0x80)); /* ŽÙ ºž³»Áú ¶§ ±îÁö ±âŽÙž®°í */
data = SPDR; /* ¹ÞÀº µ¥ÀÌÅÍžŠ ÀúÀåÇÑŽÙ */
if ( ins == 0 ){
char str[80]={0,};
sprintf(str, "%02x", data);
Puts(str);
}
return data;
}
int main(void)
{
char str[80];
unsigned long i, y;
int cnt, one_byte, one_bit;
// 1:CS 2:SI 3:SO 4:SCLK 5:WP 6:RESET 7:VCC(°øÀ¯±âÀÚÃŒ) 8:GND(ºžµåÀÚÃŒ)
// A port žŠ Ãâ·Â¿ëÀž·Î ¿ëÀž·Î »ç¿ëÇÏ°ÚŽÙ¶ó°í ÁöÁ€
DDRA = 0xFF; // CS
SPI_init_master();
// INIT : CS goes high & clock low
// œÇÁŠ·Î ÀüŸÐÀž·Î Á֎°Í
PORTA = 0xFF;
// INIT : UART INIT
init_uart();
Puts("delay start \r\n");
_delay_ms(5000);
Puts("delay end \r\n");
// START !!
// /CSÇÉ LOW change `
PORTA = 0x00;
Puts("Read ID start!\r\n");
/////////////////////////////////////////////////////////////////////////
//TODO Read ID // KT : 90H == read ID // return 8C 14 or 14 8C
SPI_IO(0x90,1);
SPI_IO(0x00,1);
SPI_IO(0x00,1);
SPI_IO(0x00,1);
SPI_IO(0x00,0);
SPI_IO(0x00,0);
Puts("\r\nRead ID finish\n");
PORTA = 0xFF;
Puts("######## end ########");
/////////////////////////////////////////////////////////////////////////
Puts("\r\n Getting dump code start! \r\n");
_delay_ms(5000);
////////////////////////////////////////////////////////////////////////
// Read (33Mhz)
PORTA = 0x00;
SPI_IO(0x03,1);
SPI_IO(0x00,1);
SPI_IO(0x00,1);
SPI_IO(0x00,1);
for ( i = 0; i < 640000000; i++){
SPI_IO(0x00,0);
}
// /CSÇÉ HIGH change `
PORTA = 0xFF;
Puts("######## end ########");
while(1)
{
_delay_ms(10000);
}
}
'System_Hacking' 카테고리의 다른 글
32bit linux shellcode (/bin/sh) (0) | 2016.05.17 |
---|---|
[검색용][python] Remote exploit 할때 기본 포멧 (0) | 2016.05.06 |
QEMU 돌릴때 포트포워딩 옵션 (0) | 2016.02.21 |
Shellcode 뽑아내는 깨알 팁. (0) | 2015.12.21 |
call, leave, ret assembly (0) | 2015.09.11 |