GCC想把特定的函数不优化怎么玩?
大家好, 我在用户空间影射/dev/mem. 做了个用户空间的驱动来更新存放u-boot二进制的FLASH.
但是我GDB了一下发现顺序老被优化了. 我要写SST 的FLASH的状态机滴! 不能顺序不对.
虽然我申明成 volatile了
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
编译的时候加个-fno-strict-aliasing 看看还会不会被打乱顺序
volatile怎么加的?我想看看源码
搞定了, 不是顺序被优化了. 是我系统的usleep() 精度达不到. 所以狂满无比. 最小的sleep就是10ms. 所以自己写个循环搞搞
int update_bootrom(struct cli *cli, char *src_file)
{
int ret = CLI_SUCCESS;
int mem_fd, src_fd;
uint8_t *bootrom_phyaddr, a_byte;
off_t file_len, i;
mem_fd = open("/dev/mem", O_RDWR | O_SYNC);
if(mem_fd < 0)
{
CHSM_DBG_ERR("open /dev/mem failed\n");
ret = CLI_ERROR;
goto ERROR1;
}
bootrom_phyaddr = (uint8_t *)mmap(NULL, BOOTROMSIZE, PROT_READ|PROT_WRITE,
MAP_SHARED, mem_fd, BOOTROMADDR);
if(bootrom_phyaddr < 0)
{
CHSM_DBG_ERR("mmap bootrom error\n");
ret = CLI_ERROR;
goto ERROR2;
}
src_fd = open(src_file, O_RDONLY);
if(src_fd < 0)
{
CHSM_DBG_ERR("open boot src file failed\n");
cli_out(cli,"open boot src file failed\n");
ret = CLI_ERROR;
goto ERROR3;
}
if( check_boot_bin(src_fd) != 0)
{
CHSM_DBG_ERR("check bootrom bin failed\n");
cli_out(cli,"check bootrom bin faile\n");
ret = CLI_ERROR;
goto ERROR4;
}
/* get src file len */
lseek(src_fd, 0, SEEK_END);
file_len = lseek(src_fd, 0, SEEK_CUR);
lseek(src_fd, 0, SEEK_SET);
/* SST39VF040 chip erase: datasheet page 6 */
U8(bootrom_phyaddr + 0x5555) = 0xAA;
U8(bootrom_phyaddr + 0x2AAA) = 0x55;
U8(bootrom_phyaddr + 0x5555) = 0x80;
U8(bootrom_phyaddr + 0x5555) = 0xAA;
U8(bootrom_phyaddr + 0x2AAA) = 0x55;
U8(bootrom_phyaddr + 0x5555) = 0x10;
/* Chip errase time 70 ms typical: datasheet page 1 */
usleep(80*1000);
/* byte program 14us: datasheet page 1 */
for(i = 0; i < file_len; i++)
{
read(src_fd, &a_byte, 1);
U8(bootrom_phyaddr + 0x5555) = 0xAA;
U8(bootrom_phyaddr + 0x2AAA) = 0x55;
U8(bootrom_phyaddr + 0x5555) = 0xA0;
U8(bootrom_phyaddr + i) = a_byte;
UDELAY(15);
}
lseek(src_fd, 0, SEEK_SET);
for(i = 0; i < file_len; i++)
{
read(src_fd, &a_byte, 1);
if( a_byte != U8(bootrom_phyaddr + i) )
{
CHSM_DBG_ERR("write boot rom failed\n");
cli_out(cli, "write boot rom failed %d %d %d\n", i, a_byte, U8(bootrom_phyaddr + i));
ret = CLI_ERROR;
goto ERROR4;
}
}
ret = CLI_SUCCESS;
ERROR4:
close(src_fd);
ERROR3:
munmap(bootrom_phyaddr, BOOTROMSIZE);
ERROR2:
close(mem_fd);
ERROR1:
return ret;
}
顶一下