CubieBoard中文论坛

 找回密码
 立即注册
搜索
热搜: unable
查看: 21392|回复: 15

CB_A10裸奔代码,A10当单片机用,屌爆了有木有,收益.....

[复制链接]
发表于 2014-8-11 15:54:39 | 显示全部楼层 |阅读模式
本帖最后由 jiangdou 于 2015-6-25 10:05 编辑

CB_A10裸奔代码,A10当单片机用大家都来瞧一瞧看一看,收益匪浅



此代码不需要内存可以运行
4afbfbedab64034fa6b9e0d2afc379310b551de9.jpg


源码下载:
a, A10_私服下载地址:http://www.jiangdoudou.uni.me:8111/A10_luoben_LED


b, github链接:https://github.com/jiangdoudou/allwiner_A10_luoben_leds


视频展示:

used :  使用方法:
/*
* Platform  for: allwiner  A10
* author  by jiangdou
* you  have anything,plese to QQ:344283973
* time  at: 2012-0801
*
*
*/

How to compile ....

make  && make clean

use TF card to boot......
$ chmod +x  mksunxiboot     //此工具需要ubuntu-64bit     !!!!!!(源码,重新编译,32位就可以运行,请参考本帖12楼)
$ ./mksunxiboot led.bin xx.bin   //给执行文件加头部,目的让A10芯片上的BROM程序识别到TF的程序
  
$ dd if=xx.bin of=/dev/sdX bs=1024 seek=8




modify  file 1st  -> main.c
  1. #include "clock.h"
  2. #include "uart.h"
  3. #include "lib.h"
  4. #define PB_CFG2          (*(volatile unsigned int *)0x01c2082c)
  5. #define PE_DAT          (*(volatile unsigned int *)0x01c208A0)
  6. #define PE_CFG          (*(volatile unsigned int *)0x01c20890)

  7. /*
  8. void delay(void)
  9. {
  10.         puts("delay open for leds on and off\n\r");
  11.         int i,a;
  12.         for (i=1;i<1000;i++)
  13.           for (a=1;a<1000;a++);
  14.         

  15. }
  16. */

  17. /*内嵌,精准延时...........此处是亮点!!!!!!!!!*/
  18. static inline void delay(unsigned long loops)
  19. {
  20.         puts("delay open for leds on and off\n\r");
  21.         __asm__ volatile ("1:\n"
  22.                         "subs %0, %1, #1\n"
  23.                         "bne 1b":"=r" (loops):"0" (loops));
  24. }

  25. void gpio_init()
  26. {
  27.   /*bit[30:28]:PB23_SELECT 010:UART0_RX
  28.    *bit[26:24]:PB22_SELECT 010:UART0_TX
  29.    */
  30.   PB_CFG2 |= ((0x2<<24)|(0x2<<28));
  31.   /**/
  32.   PE_CFG |= ((0x1<<20)|(0x1<<24)|(0x1<<28));
  33. }
  34. int main(void)
  35. {
  36.         char c;
  37.         clock_init(); /* 初始化时钟 */
  38.         gpio_init();
  39.         uart_init(); /* 初始化UART0 */
  40.         puts("\n\r#####################################\n\r");
  41.         puts("The board:Inet_97F_REV03\n\r");
  42.         puts("The NAND: 4096MB\n\r");
  43.         puts("The SRAM:HY x4 512MB\n\r");
  44.         puts("just bootloader led.        date: 2012.10.20;by jiangdou\n\r");
  45.         puts("#####################################\n");

  46.         while (1)
  47.         {
  48.                 PE_DAT = 0x80;
  49.                 puts("GPIO_PE LED 1\n\r");
  50.                 delay(80000000);
  51.                 PE_DAT = 0x00;
  52.                 delay(80000000);
  53.                 PE_DAT = (0x1<<5);
  54.                 puts("GPIO_PE LED 2\n\r");
  55.                 delay(80000000);
  56.                 PE_DAT = (0x5<<5);
  57.                 puts("GPIO_PE LED 3\n\r");
  58.                 delay(80000000);
  59.                 PE_DAT = (0x2<<5);
  60.                 puts("GPIO_PE LED 4\n\r");
  61.                 delay(80000000);
  62.                 PE_DAT = (0x6<<5);
  63.                 puts("GPIO_PE LED 5\n\r");
  64.                 delay(80000000);
  65.                 PE_DAT = (0x3<<5);
  66.                 puts("GPIO_PE LED 6\n\r");
  67.                 delay(80000000);
  68.                 PE_DAT = (0x7<<5);
  69.                 puts("GPIO_PE LED 7\n\r");
  70.                 delay(80000000);
  71.                 PE_DAT = (0x0<<5);
  72.                 puts("GPIO_PE LED 8\n\r");
  73.         }
  74.         return 0;
  75. }
复制代码
1.file 1 -> main.c
  1. /*
  2. * Platform  for: allwiner  A10
  3. * author  by jiangdou
  4. * time  at: 2012-0801
  5. *
  6. *
  7. */

  8. /*****deleted****/
复制代码
2.file 2 -> start.S
  1. /*
  2. * Platform  for: allwiner  A10
  3. * author  by jiangdou
  4. * time  at: 2012-0801
  5. *
  6. *
  7. */




  8. .global _start
  9. _start:
  10.         ldr r0,=0x1c20890        
  11.         ldr r1,=0x1000000
  12.         str r1,[r0]
  13.         
  14.         ldr r0,=0x1c208a0
  15.         ldr r1,=0x40
  16.         str r1,[r0]
  17.         ldr sp, =0x00007f00 //条用C程序之前设置好堆栈
  18.         b main
复制代码
3.file 3 -> uart.c
  1. /*
  2. * Platform  for: allwiner  A10
  3. * author  by jiangdou
  4. * time  at: 2012-0801
  5. *
  6. *
  7. */




  8. #define UART0_LCR   (*(volatile unsigned int *)0x01C2800C)
  9. #define UART0_DLH   (*(volatile unsigned int *)0x01C28004)
  10. #define UART0_DLL   (*(volatile unsigned int *)0x01C28000)
  11. #define UART0_LSR   (*(volatile unsigned int *)0x01C28014)
  12. #define UART0_THR   (*(volatile unsigned int *)0x01C28000)
  13. #define UART0_RBR   (*(volatile unsigned int *)0x01C28000)

  14. void uart_init(void)
  15. {
  16.   /*select dll dlh*/
  17.   /*bit7:Divisor Latch Access Bit
  18.    *0:Select RX Buffer Register(RBR)/TX Holding Register(THR)and Interrupt Enable register(IER)
  19.    *1:Select Divisor Latch LS Register(DLL) and Divisor Latch MS Register(DLM)
  20.    */
  21.   UART0_LCR = 0x80;
  22.   /*set baudrate*/
  23.   UART0_DLH = 0x0;
  24.   /*bit[7:0]:Divisor Latch Low
  25.    *baud rate=(serial clock freq)/(16*divisor)
  26.    *divisor=24M/16/115200=13.02083
  27.    */
  28.   UART0_DLL = 0xd;
  29.   /*set line control*/
  30.   /*bit3:Parity Enable 0:parity disable 1:parity enable
  31.    *bit2:Number of stop bits
  32.    *0:1 stop bit;1:1.5 stop bits when DLS(LCR[1:0]is zero,else 2 stop bits)
  33.    *bit[1:0] Data Length Select 00:5bits;01:6bits;10:7bits;11:8bits
  34.    */
  35.   UART0_LCR = ((0<<3)|(0<<2)|0x3);
  36. }

  37. char getc(void)
  38. {
  39.         char c;
  40.         while (!(UART0_LSR & (1<<0)));
  41.         c = UART0_RBR;
  42.         return c;
  43. }

  44. void putc(char c)
  45. {

  46.         while (!(UART0_LSR & (1<<6)));
  47.         UART0_THR = c;
  48.         return;
  49. }
  50. void puts(char *str)
  51. {
  52.         int i = 0;
  53.         while (str[i])
  54.         {
  55.                 putc(str[i]);
  56.                 i++;
  57.         }
  58. }
复制代码
4.file 4 ->  clock.c
  1. /*
  2. * Platform  for: allwiner  A10
  3. * author  by jiangdou
  4. * time  at: 2012-0801
  5. *
  6. *
  7. */






  8. #define CPU_AHB_APB0_CFG   (*(volatile unsigned int *)0x01c20054)
  9. #define PLL1_CFG          (*(volatile unsigned int *)0x01c20000)
  10. #define APB1_CLK_DIV_CFG   (*(volatile unsigned int *)0x01c20058)
  11. #define APB1_GATE          (*(volatile unsigned int *)0x01c2006C)
  12. void sdelay(unsigned long loops)
  13. {
  14.   __asm__ volatile("1:\n" "subs %0, %1, #1\n"
  15.   "bne 1b":"=r" (loops):"0"(loops));
  16. }
  17. void clock_init(void)
  18. {
  19.   /*AXI_DIV_1[1:0]  AXI_CLK_DIV_RATIO 00:/1 AXI Clock source is CPU clock
  20.    *AHB_DIV_2[5:4]  AHP_CLK_DIV_RATIO 01:/2 AHB Clock source is AXI CLOCK
  21.    *APB0_DIV_1[9:8] APB0_CLK_RATIO    00:/2 APB0 clock source is AHB2 clock
  22.    *CPU_CLK_SRC_OSC24M[17:16] CPU_CLK_SRC_SEL 01:OSC24M
  23.    */
  24.    CPU_AHB_APB0_CFG = ((0<<0)|(0x1<<4)|(0<<8)|(1<<16));

  25.    /*bit31:PLL1_Enable 1:Enable
  26.     *bit25:EXG_MODE 0x0:Exchange mode
  27.     *bit[17:16]:PLL1_OUT_EXT_DIVP 0x0:P=1
  28.     *bit[12:8]:PLL1_FACTOR_N 0x10:Factor=16,N=16
  29.     *bit[5:4]:PLL1_FACTOR_K 0x0:K=1
  30.     *bit3:SIG_DELT_PAT_IN 0x0
  31.     *bit2:SIG_DELT_PAT_EN 0x0
  32.     *bit[1:0]PLL1_FACTOR_M 0x0:M=1
  33.     *The PLL1 output=(24M*N*K)/(M*P)=(24M*16*1)/(1*1)=384M is for the coreclk
  34.     */
  35.    PLL1_CFG = 0xa1005000;
  36.    sdelay(200);

  37.    CPU_AHB_APB0_CFG = ((0<<0)|(0x1<<4)|(0<<8)|(2<<16));//CPU_CLK_SRC_SEL 10:PLL1

  38.    /*uart clock source is apb1,config apb1 clock*/
  39.    /*bit[25:24]:APB1_CLK_SRC_SEL 00:OSC24M
  40.     *bit[17:16]:CLK_RAT_N 0X0:1 The select clock source is pre-divided by 2^1
  41.     *bit[4:0]:CLK_RAT_M 0x0:1 The pre-devided clock is divided by(m+1)
  42.     */
  43.    APB1_CLK_DIV_CFG = ((0<<5)|(0<<16)|(0<<24));
  44.    /*open the clock for uart0*/
  45.    /*bit16:UART0_APB_GATING 1:pass 0:mask*/
  46.    APB1_GATE = (0x1<<16);
  47. }
复制代码
5.file 5 ->  lib.c

  1. /*
  2. * Platform  for: allwiner  A10
  3. * author  by jiangdou
  4. * time  at: 2012-0801
  5. *
  6. *
  7. */



  8. int putchar(int c)
  9. {
  10.         if (c == '\n')
  11.         putc('\r');
  12.         putc(c);
  13.         return 0;
  14. }
复制代码
6.file 6 ->  Makefile
  1. #/*
  2. #* Platform  for: allwiner  A10
  3. #* author  by jiangdou
  4. #* time  at: 2012-0801
  5. #*
  6. #*
  7. #*/


  8. uart.bin:start.S main.c uart.c clock.c lib.c
  9.         arm-linux-gnueabihf-gcc -nostdlib -c start.S -o start.o
  10.         arm-linux-gnueabihf-gcc -nostdlib -c main.c -o main.o
  11.         arm-linux-gnueabihf-gcc -nostdlib -c uart.c -o uart.o
  12.         arm-linux-gnueabihf-gcc -nostdlib -c lib.c -o lib.o
  13.         arm-linux-gnueabihf-gcc -nostdlib -c clock.c -o clock.o
  14.         arm-linux-gnueabihf-ld -Ttext 0x00000020 start.o main.o uart.o lib.o clock.o  -o uart_elf
  15.         arm-linux-gnueabihf-objcopy -O binary -S uart_elf uart.bin
  16. clean:
  17.         rm -rf *.o *.bin uart_elf *.dis
复制代码
反编译效果  $ arm-linux-gnueabihf-objdump -S uart_elf > uart_.S

2014-12-25 11:13:40的屏幕截图.png
反汇编led.bin,看看mksunxiboot  工具增加什么内容呢????
$$ arm-linux-gnueabihf-objdump -D -b binary -m arm led.bin > led.asm
ddr.png

....................
...

2014-12-25 11:32:17的屏幕截图.png
回复

使用道具 举报

发表于 2014-8-11 17:41:38 | 显示全部楼层
这个要怎么用呢?烧到SD卡上?还是在bootloader中调用?JTAG?
回复 支持 反对

使用道具 举报

发表于 2014-8-12 09:02:19 | 显示全部楼层
你的A10好惨,变单片机了
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-8-12 16:37:31 | 显示全部楼层
使用方法:
/*
* Platform  for: allwiner  A10
* author  by jiangdou
* you  have anything,plese to QQ:344283973
* time  at: 2012-0801
*
*
*/

How to compile ....

make  && make clean

use TF card to boot......

./mksunxiboot uart.bin xx.bin

dd if=xx.bin of=/dev/sdX bs=1024 seek=8
回复 支持 反对

使用道具 举报

发表于 2014-8-13 02:51:03 | 显示全部楼层
以前玩的s5pv210的时候也干过这事
回复 支持 反对

使用道具 举报

发表于 2014-8-14 12:23:10 | 显示全部楼层
有空玩下
回复 支持 反对

使用道具 举报

发表于 2014-8-15 08:22:47 | 显示全部楼层
有不需要内存的程序??
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-9-15 21:05:50 | 显示全部楼层
lknlfy 发表于 2014-8-15 08:22
有不需要内存的程序??

你试试,真的不需要
回复 支持 反对

使用道具 举报

发表于 2014-11-19 19:32:41 | 显示全部楼层
lknlfy 发表于 2014-8-15 08:22
有不需要内存的程序??

你的手表不错....................

那是因为把程序load到soc里面的sram上运行,所不需要,大程序就不行了......
回复 支持 反对

使用道具 举报

发表于 2014-12-24 19:50:42 | 显示全部楼层
./mksunxiboot uart.bin usb_uart.bin
bash: ./mksunxiboot: 无法执行二进制文件


-rwxrwxr-x

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|粤ICP备13051116号|cubie.cc---深刻的嵌入式技术讨论社区

GMT+8, 2024-3-29 22:59 , Processed in 0.031360 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2012 Comsenz Inc. | Style by Coxxs

返回顶部