altera CPLD通过nios在线升级
一,生成hex文件
邏輯工程的qsys編譯好以后會生成sopcinfo文件,software里面首先generate bsp,然后編譯software,編譯完成后右鍵software->make targets build,選擇mem_init_generate->build,然后就會生成hex文件
二,生成sof文件
重新編譯整個邏輯工程,或者如果邏輯工程已經編譯過了,僅僅更新nios,為了節省時間可以采用如下步驟:
1,在quartus里面processing->update memory initialization file
2,processing->start->start assemble
就能生成sof文件了
三,生成升級所用的bin文件
此處需要.sh文件,放到software目錄下,內容為:
echo Generate application binary file.sof2flash --input=".\..\..\qii\output_files\power.sof" --output="hw.flash" --epcs --verbose objcopy -I srec -O binary hw.flash hw.bin #bin2flash --input="hw.bin" --output="NiosEMIF.flash" --location=0x100000 bin2flash --input="hw.bin" --output="NiosEMIF.flash" --location=0x0#sof2flash --input="..\..\prj\output_files\NiosEMIF.sof" --output="NiosEMIF.flash" --epcs --verboserm hw.flash然后跟生成hex一樣調用一下這個腳本,生成bin文件
四,通過上位機實現flash寫入
升級代碼如下:
void setImg(UpDateBag *UpDateData) {if( 1 ) //{soflength = UpDateData->length;// resetif(UpDateData->faddr == 0){bufpoint = 0;sofOffset = 0;erase_cnt = 0;erase_size = 0;if (epcs_flash == NULL)epcs_flash = alt_flash_open_dev(EPCS_FLASH_CONTROLLER_0_NAME);}dataBuffer = UpDateData->data;bufpoint = bufpoint + UpDateData->flen;if (UpDateData->flen > erase_size){alt_erase_flash_block(epcs_flash, erase_cnt*FLASH_BLOCK_SIZE + APP1_IMAGE_BASE, FLASH_BLOCK_SIZE);erase_size += FLASH_BLOCK_SIZE; erase_cnt++;}if ((bufpoint + sofOffset) >= soflength){if(epcs_flash)alt_write_flash_block(epcs_flash, APP1_IMAGE_BASE+sofOffset/FLASH_BLOCK_SIZE*FLASH_BLOCK_SIZE, APP1_IMAGE_BASE+sofOffset, dataBuffer, bufpoint);erase_size -= bufpoint;sofOffset += bufpoint;bufpoint = 0;}else{if(bufpoint == 1024){if(epcs_flash)alt_write_flash_block(epcs_flash, APP1_IMAGE_BASE+sofOffset/FLASH_BLOCK_SIZE*FLASH_BLOCK_SIZE, APP1_IMAGE_BASE+sofOffset, dataBuffer, bufpoint);erase_size -= bufpoint;sofOffset += bufpoint;bufpoint = 0;}}}if(sofOffset == soflength ){replyCmdBuf[PACKET_HEAD_LEN>>2] = LVDS_CMD_OK;ReplyMessage(4);usleep(20000);#ifdef BOOT_MODErsu_factory_trigger_reconfig(RSU_CYCLONE4_0_BASE, (APP_IMAGE_BASE)>>2, 0x00);#elsersu_app_trigger_reconfig(RSU_CYCLONE4_0_BASE);#endif}// if(sofOffset == soflength ) // { // replyCmdBuf[PACKET_HEAD_LEN>>2] = LVDS_CMD_OK; // ReplyMessage(4); // // usleep(20000); // IOWR(REMOTE_UPDATE_0_BASE, 0x4, 1); // // //Trigger reconfiguration // IOWR(REMOTE_UPDATE_0_BASE, 0x6, 1); // } }與之對應的升級模塊為qsys里面添加 epcs_flash_controller,flash對應的幾個引腳有的片子要求連上,有的片子不用連(只能是那幾個引腳)
需要注意的是代碼寫入成功后的跳轉模塊,有的片子需要用rsu_cyslcone4模塊跳轉,有的需要用remote update模塊實現跳轉。
五,制作boot程序
boot升級那塊跟應用程序一樣,只不過main函數剛跑起來多一個app跳轉功能,代碼如下
void SwitchToApp(void) {rsu_factory_get_previous_reconfig_status(RSU_CYCLONE4_0_BASE,&condition_1,&condition_2,&boot_address_1,&boot_address_2);if(condition_1 <= 1){rsu_factory_trigger_reconfig(RSU_CYCLONE4_0_BASE,//REMOTE_UPDATE_CONTROLLER_BASE, // alt_u32 rsu_base,(APP_IMAGE_BASE)>>2,//( HW_APP1_IMAGE_BASE + HEADER_LENGTH ) >> 2, // alt_u32 boot_address_value, // MSB 22-bits of 24-bit address0x00//hw1_header_g.res_wd_tmo // alt_u32 watch_dog_value // MSB 12-bits of 29-bit timeout count);} }固化boot程序需要做jic文件,就是在生成sof以后通過 quartus->file->convert programming files
做好jic文件以后通過bluster燒錄固化進去
六 沒有nios只有邏輯的情況下的jic
生成sof以后方式跟上面一樣,只是沒把hex加進sof而已。沒有nios的情況如何遠程升級我還沒學會,學會再加。
展示一下兩個sof做到同一個jic里
總結
以上是生活随笔為你收集整理的altera CPLD通过nios在线升级的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 8051单片机内部结构
- 下一篇: 麻将听牌,胡牌算法