📄 mx1-load-tagimage.c
字号:
/******************************************************************* MX1-Loader - DragonBall M9328/MX1 loader mx1-load-tagimage.c - Linux kernel ATAG style image (C) Copyright 2004 by Pavel Pisa - project originator http://cmp.felk.cvut.cz/~pisa (C) Copyright 2004 PiKRON Ltd. http://www.pikron.com (C) Copyright 2004 Roman Bartosinski (bartosr@centrum.cz) The MX1-Loader project can be used and distributed in compliance with any of next licenses - GPL - GNU Public License See file COPYING for details. - LGPL - Lesser GNU Public License - MPL - Mozilla Public License - and other licenses added by project originator Code can be modified and re-distributed under any combination of the above listed licenses. If contributor does not agree with some of the licenses, he/she can delete appropriate line. WARNING: if you delete all lines, you are not allowed to distribute code or sources in any form. *******************************************************************/#define _GNU_SOURCE#include <stdlib.h>#include <stdio.h>#include <string.h>#include <ctype.h>#include <termios.h>#include <sys/time.h>#include <sys/types.h>#include <errno.h>#include <unistd.h>#include <fcntl.h>#include <inttypes.h>#include "universal-load.h"#ifndef __u8 #define __u8 uint8_t#endif#ifndef __u16 #define __u16 uint16_t#endif#ifndef __u32 #define __u32 uint32_t#endif#include "linux_setup.h"int tagimage_setup(uniload_alg_info_t *algi){ /*int fd=algi->dev_fd;*/ return 0;}int tagimage_mem_write(uniload_alg_info_t *algi, int mem_type, unsigned long start, unsigned long len, const char *buff){ int fd=algi->dev_fd; long len4 = (len+3) & ~3l; uint32_t u[4]; u[0] = (len4>>2) + 4; u[1] = ATAG_MEMDATA; u[2] = start; u[3] = len; write(fd,u,4*4); write(fd,buff,len4); return 0;}int tagimage_mem_read(uniload_alg_info_t *algi, int mem_type, unsigned long start, unsigned long len, char *buff){ /* int fd=algi->dev_fd; */ return -1;}int tagimage_go_addr(uniload_alg_info_t *algi, unsigned long addr){ int fd=algi->dev_fd; uint32_t u[6]; int i; unsigned long val; char regname[4]; regname[0]='r'; regname[1]='0'; regname[2]=0; u[0] = 6; u[1] = ATAG_JUMP; u[2] = addr; u[3] = 0; u[4] = 0; u[5] = 0; for(i=0;i<3;i++){ regname[1]='0'+i; if(uniload_extprop_get_ulong(algi, regname, &val)>0){ u[i+3]=val; } } write(fd,u,6*4); return 0;}int tagimage_masserase(uniload_alg_info_t *algi, unsigned long mode){ /*int fd=algi->dev_fd;*/ return -1;}int tagimage_regerase(uniload_alg_info_t *algi, unsigned long addr, unsigned long len){ /*int fd=algi->dev_fd;*/ return 0;}int tagimage_release(uniload_alg_info_t *algi){ int res; int fd=algi->dev_fd; res = close(fd); return res;}uniload_alg_ops_t tagimage_alg_ops={ .setup=tagimage_setup, .mem_write=tagimage_mem_write, .mem_read=tagimage_mem_read, .go_addr=tagimage_go_addr, .release=tagimage_release, .masserase=tagimage_masserase, .regerase=tagimage_regerase,};#ifndef O_BINARY#define O_BINARY 0#endifint mx1_tagimage_open(uniload_alg_info_t *algi, char *fname, int mode){ int fd; /* Open image file device */ open(fname, O_WRONLY|O_TRUNC|O_BINARY|O_CREAT,S_IRUSR|S_IWUSR); if ((fd = open(fname, O_RDWR | O_TRUNC | O_BINARY | O_CREAT, S_IRUSR | S_IWUSR)) == -1) { fprintf(stderr,"Cannot open serial device %s\n",fname); return -1; } algi->dev_name=fname; algi->dev_fd=fd; algi->alg_ops=&tagimage_alg_ops; if(!algi->max_blksize){ algi->max_blksize=0x1000000; } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -