全志V5平台升级uboot分区Demo

最近接到领导需求,需要将sys_config.fex的修改透过网络,单独烧写分区的方式将修改升级到板上。研究了下全志的开发文档,sys_config.fex转成2进制文件后打包到uboot升级文件中,所以我们需要升级uboot分区。之前有过升级bootlogo分区的经验,接下来和之前差不多,不过需要注意的是,uboot分区所在emmc上的地址是有偏移的,不多说,直接上代码

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <termios.h>
#include <fcntl.h>
#include <string.h>

#define     INT8    char
#define         INT32   int


#define     FILE_NAME          "/mnt/nfs/boot_package.fex"
//#define     FILE_NAME          "/mnt/nfs/u-boot.fex"
#define     PARTITION_NAME          "/dev/mmcblk0"
#define UBOOT_START_SECTOR_IN_SDMMC             (32800)
#define SECTOR_SIZE	            				512

int mywrite(char * FileName,char * DevName)
{
	FILE	*fp = NULL;
	int  flash_handle = 0;
	INT8 *ptBuff = NULL;
	INT32 niReadLen = 0;
	INT32 niWriteLen = 0;

	if(FileName == NULL || DevName == NULL)
	{
		printf("UpdateExt4File  input  invalid!!!\n");
		return -1;
	}
	ptBuff = (INT8  *)malloc(4*1024*1024);
	if(ptBuff)
	{
		fp = fopen(FileName, "r");
		if (NULL != fp)
		{

			flash_handle = open(DevName,O_RDWR);
			 if(flash_handle < 0)
			 {
			 	printf("open  %s failed!!!\n",DevName);
			}

			niReadLen =fread(ptBuff,1,4*1024*1024,fp);
#if 1
	if (lseek(flash_handle, 0, SEEK_SET) == -1) {
		printf("Failed to SEEK_SET 0 mmcblk0 device\n");
		return -1;
	}

	if (lseek(flash_handle, UBOOT_START_SECTOR_IN_SDMMC * SECTOR_SIZE, SEEK_CUR) == -1) {
		printf("Failed to SEEK_SET %d mmcblk0 device\n", UBOOT_START_SECTOR_IN_SDMMC * SECTOR_SIZE);
		return -1;
	}
#endif				
				if(niReadLen > 0)
				{
					niWriteLen = write(flash_handle,ptBuff,niReadLen);
					if(niWriteLen != niReadLen)
					{
						printf("Write %s failed  niWriteLen: %d,niReadLen: %d !!!!\n",DevName,niWriteLen,niReadLen);
					}
				}

			fdatasync(flash_handle);
			close(flash_handle);
			fclose(fp);
		}
		else
		{
			printf("UpdateExt4File  fopen %s failed!!!\n",FileName);
			return -3;
		}
		free(ptBuff);
		ptBuff = NULL;
		printf("write uboot Partition OK !! \n");
	}
	else
	{
		printf("UpdateExt4File  malloc failed!!!\n");
		return -2;
	}
	return 0;
}

int main(int argc, char **argv)
{
	printf("Main start !!\n");
	mywrite(FILE_NAME,PARTITION_NAME);
	 
    return 0;
}

/dev/mmcblk0 是指emmc设备,而全志uboot的起始地址就是37800*512

以上

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值