📄 mxc_nb_crcgen.c
字号:
/* * Copyright 2004 Freescale Semiconductor, Inc. All Rights Reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *//*! * @file mxc_nb_crcgen.c * * @brief This is an utility program to write crc and image size in Linux kernel * image. * * This program reads Linux kernel image and generates 'Addition CRC'. It * writes the 4 bytes of size and generated crc value at the beginning of the * Linux kernel image. * * @ingroup NANDboot */#include<stdio.h>typedef unsigned int U32;typedef unsigned char U8;int main(void){ U32 crc = 0; U32 i = 0; U8 ch; FILE *frd, *fwt; fpos_t *pos; char *imgcrc = "./bin/Image_crc"; char *img = "./image/Image"; /* create new image 'Image_crc' with the size and crc written on it */ fwt = fopen(imgcrc, "wb"); if (!fwt) { printf("Failed to create %s\n", imgcrc); return 1; } /* open to read the Linux kernel image from image folder */ frd = fopen(img, "rb"); if (frd) { while (fread(&ch, 1, 1, frd)) { /* * generate crc by adding each byte from the Linux * kernel image file. The CRC is addition checksum. */ crc += ch; i++; } printf("Image size %d crc %d\n", i, crc); /* write 4 bytes of size at the beginning of new image */ fwrite(&i, 4, 1, fwt); /* write 4 bytes of crc after size at the beginning of image */ fwrite(&crc, 4, 1, fwt); /* set the file pointer at start of the file */ rewind(frd); /* copy the Linux kernel image byte by byte to image */ while (fread(&ch, 1, 1, frd)) { fwrite(&ch, 1, 1, fwt); } fclose(frd); /* close file */ } else { printf("Failed to open %s\n", img); return 1; } fclose(fwt); /* close file */ return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -