CubieBoard中文论坛

 找回密码
 立即注册
搜索
热搜: unable
12
返回列表 发新帖
楼主: jiangdou

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

[复制链接]
 楼主| 发表于 2014-12-24 20:00:31 | 显示全部楼层
本帖最后由 jiangdou 于 2014-12-25 09:23 编辑
肝火旺 发表于 2014-12-24 19:50
./mksunxiboot uart.bin usb_uart.bin
bash: ./mksunxiboot: 无法执行二进制文件

请确认的ubuntu是64位的!!!!

@Ubuntu12:~/dou_work/lins/allwiner_A10_luoben_leds$ ls
clock.c  clock.h  leds_main.c  leds_Makefile  lib.c  lib.h  main.c  Makefile  mksunxiboot  README  start.S  uart.c  uart.h
@Ubuntu12:~/dou_work/lins/allwiner_A10_luoben_leds$ ls
clock.c  clock.h  leds_main.c  leds_Makefile  lib.c  lib.h  main.c  Makefile  mksunxiboot  README  start.S  uart.c  uart.h
@Ubuntu12:~/dou_work/lins/allwiner_A10_luoben_leds$ ll

@Ubuntu12:~/dou_work/lins/allwiner_A10_luoben_leds$ chmod +x mksunxiboot
/dou_work/lins/allwiner_A10_luoben_leds$ ./mksunxiboot uart.bin led.bin
File size: 0x3f0
Load size: 0x3f0
Read 0x3f0 bytes
Write 0x600 bytes
。。。。。。。。。。。
。。。。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-12-25 09:32:35 | 显示全部楼层
本帖最后由 jiangdou 于 2014-12-25 09:56 编辑
肝火旺 发表于 2014-12-24 19:50
./mksunxiboot uart.bin usb_uart.bin
bash: ./mksunxiboot: 无法执行二进制文件

//此工具需要ubuntu-64bit     !!!!!!(源码,重新编译, 也可以32位)
1, readme file ->  README
  1. This program make a arm binary file can be loaded by Allwinner A10 and releated
  2. chips from storage media such as nand and mmc.

  3. To compile this program, just type make, you will get 'mksunxiboot'.

  4. To use it,
  5. $./mksunxiboot u-boot.bin u-boot-mmc.bin
  6. then you can write it to a mmc card with dd.
  7. $sudo dd if=u-boot-mmc.bin of=/dev/sdb bs=1024 seek=8
  8. then insert your mmc card to your A10 tablet, you can boot from mmc card.
复制代码
2,makefile  ->  Makefile
  1. # Makefile for mksunxiboot
  2. CC = gcc
  3. CFLAGS = -Wall -Wextra -O2
  4. PROG = mksunxiboot
  5. all: $(PROG)
  6. clean:
  7. rm -rf *.o $(PROG)
复制代码
3,C file ->    mksunxiboot.c
  1. /*
  2. * (C) Copyright 2007-2011
  3. * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
  4. * Tom Cubie <tangliang@allwinnertech.com>
  5. *
  6. * a simple tool to generate bootable image for sunxi platform.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */

  23. #include <fcntl.h>
  24. #include <stdio.h>
  25. #include <unistd.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <errno.h>
  29. #include <sys/types.h>
  30. #include <sys/stat.h>

  31. typedef unsigned char u8;
  32. typedef unsigned int u32;

  33. /* boot head definition from sun4i boot code */
  34. typedef struct boot_file_head
  35. {
  36.         u32  jump_instruction;   // one intruction jumping to real code
  37.         u8   magic[8];           // ="eGON.BT0" or "eGON.BT1",  not C-style string.
  38.         u32  check_sum;          // generated by PC
  39.         u32  length;             // generated by PC
  40.         u32  pub_head_size;      // the size of boot_file_head_t
  41.         u8   pub_head_vsn[4];    // the version of boot_file_head_t
  42.         u8   file_head_vsn[4];   // the version of boot0_file_head_t or boot1_file_head_t
  43.         u8   Boot_vsn[4];        // Boot version
  44.         u8   eGON_vsn[4];        // eGON version
  45.         u8   platform[8];        // platform information
  46. }boot_file_head_t;

  47. #define BOOT0_MAGIC                     "eGON.BT0"
  48. #define STAMP_VALUE                     0x5F0A6C39
  49. /* check sum functon from sun4i boot code */
  50. int gen_check_sum( void *boot_buf )
  51. {
  52.         boot_file_head_t  *head_p;
  53.         u32 length;
  54.         u32 *buf;
  55.         u32 loop;
  56.         u32 i;
  57.         u32 sum;

  58.         head_p = (boot_file_head_t *)boot_buf;
  59.         length = head_p->length;
  60.         if( ( length & 0x3 ) != 0 )                   // must 4-byte-aligned
  61.                 return -1;
  62.         buf = (u32 *)boot_buf;
  63.         head_p->check_sum = STAMP_VALUE;              // fill stamp
  64.         loop = length >> 2;
  65.         /* calculate the sum */
  66.         for( i = 0, sum = 0;  i < loop;  i++ )
  67.                 sum += buf[i];

  68.         /* write back check sum */
  69.         head_p->check_sum = sum;

  70.         return 0;
  71. }

  72. #define ALIGN(x,a)      __ALIGN_MASK((x),(typeof(x))(a)-1)
  73. #define __ALIGN_MASK(x,mask)    (((x)+(mask))&~(mask))

  74. #define SUN4I_SRAM_SIZE (24 * 1024)
  75. #define SRAM_LOAD_MAX_SIZE (SUN4I_SRAM_SIZE - sizeof(boot_file_head_t))
  76. #define BLOCK_SIZE 512
  77. struct boot_img {
  78.         boot_file_head_t header;
  79.         char code[SRAM_LOAD_MAX_SIZE];
  80.         char pad[BLOCK_SIZE];
  81. };

  82. int main(int argc, char * argv[])
  83. {
  84.         int fd_in, fd_out;
  85.         struct boot_img img;
  86.         unsigned file_size, load_size;
  87.         int count;

  88.         if(argc < 2) {
  89.                 printf("\tThis program makes an input bin file to sun4i bootable image.\n"
  90.                                 "\tUsage: %s input_file out_putfile\n", argv[0]);
  91.                 return EXIT_FAILURE;
  92.         }

  93.         fd_in = open(argv[1], O_RDONLY);
  94.         if(fd_in < 0) {
  95.                 perror("Open input file:");
  96.                 return EXIT_FAILURE;
  97.         }

  98.         fd_out = open(argv[2], O_WRONLY|O_CREAT, 0666);
  99.         if(fd_out < 0) {
  100.                 perror("Open output file:");
  101.                 return EXIT_FAILURE;
  102.         }

  103.         memset((void *)img.pad, 0, BLOCK_SIZE);

  104.         /* get input file size */
  105.         file_size = lseek(fd_in, 0, SEEK_END);
  106.         printf("File size: 0x%x \n", file_size);

  107.         if(file_size > SRAM_LOAD_MAX_SIZE) {
  108.                 load_size = SRAM_LOAD_MAX_SIZE;
  109.         } else {
  110.                 load_size = ALIGN(file_size, sizeof(int));
  111.         }
  112.         printf("Load size: 0x%x \n", load_size);

  113.         /* read file to buffer to calculate checksum */
  114.         lseek(fd_in, 0, SEEK_SET);
  115.         count = read(fd_in, img.code, load_size);
  116.         printf("Read 0x%x bytes\n", count);

  117.         /* fill the header */
  118.         img.header.jump_instruction =    /* b instruction */
  119.                         0xEA000000 |             /* jump to the first instruction after the header */
  120.                         (
  121.                                 (sizeof(boot_file_head_t) / sizeof(int) - 2)
  122.                                 & 0x00FFFFFF
  123.                         );
  124.         memcpy(img.header.magic, BOOT0_MAGIC, 8);    /* no '0' termination */
  125.         img.header.length = ALIGN(load_size + sizeof(boot_file_head_t), BLOCK_SIZE);
  126.         gen_check_sum((void *)&img);

  127.         count = write(fd_out, (void *)&img, img.header.length);
  128.         printf("Write 0x%x bytes\n", count);

  129.         close(fd_in);
  130.         close(fd_out);

  131.         return EXIT_SUCCESS;
  132. }
复制代码
回复 支持 反对

使用道具 举报

发表于 2014-12-25 10:09:02 | 显示全部楼层
A10真是一块高级的单片机啊,哈哈
回复 支持 反对

使用道具 举报

发表于 2014-12-26 11:54:32 | 显示全部楼层
呵呵,高手
回复 支持 反对

使用道具 举报

发表于 2015-3-15 18:32:48 | 显示全部楼层
这个没开mmu  速度大为限制
如果要跑其他系统 mmu是必须开的
否则 那速度慢的蜗牛一样
回复 支持 反对

使用道具 举报

发表于 2015-4-9 21:52:11 | 显示全部楼层
太强了 牛人啊
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-30 19:16 , Processed in 0.024139 second(s), 13 queries .

Powered by Discuz! X3.4

© 2001-2012 Comsenz Inc. | Style by Coxxs

返回顶部