作者:沈永勝,技術(shù)副哩,晶心科技股份有限公司 EDM安全存取是AndesCoreTM內(nèi)建的功能(option),應(yīng)用在安全存取的控管。EDM安全存取有二種的控管方式:debug access indication和EDM access restriction。第一種控管方式(debug access indication)提供了一個(gè)sideband signal用于指示從調(diào)試器(Debug host)的請(qǐng)求。第二種控管方式, 控制AndesCoreTM的input port(edm_restrict_access )達(dá)到EDM存取的限制。更詳細(xì)的內(nèi)容在后續(xù)章節(jié)會(huì)有更深入的介紹。 1. EDM功能介紹 一個(gè)debug system包含一個(gè)debug host和一個(gè)target system。EDM主要的功能就是translate debug host發(fā)出的TAP指令來存取系統(tǒng)memory或是CPU。下圖為基本的debug系統(tǒng)方塊圖。 ![]() 圖表1 基本的debug系統(tǒng)方塊圖 下圖說明TAP 指令的種類 ![]() 圖表2 TAP 指令的種類 2. 控制EDM存取的限制 使用EDM的訪問方式會(huì)被一個(gè)sideband signal (edm_restrict_access) 所影響。當(dāng)這個(gè)signal值是high,僅僅只能對(duì)EDM MISC registers做讀取的動(dòng)作。而想要存取CPU/System Bus/Local Memory的動(dòng)作將會(huì)被封鎖住并且會(huì)得到下面的結(jié)果: 讀為零寫忽略 不正確的JTAG instruction(JTAG ICE debugger會(huì)timeout) 下圖說明EDM限制存取方塊圖。 ![]() 圖表3 EDM限制存取方塊圖 在啟用存取限制功能后,下圖說明出每個(gè)TAP指令的行為。 ![]() 圖表4 在啟用存取限制功能后,下圖說明出每個(gè)TAP指令的行為 如何實(shí)現(xiàn)EDM存取限制,在系統(tǒng)設(shè)計(jì)上有很多種實(shí)現(xiàn)方法,以控制edm restrict access的signal。兩種基本的設(shè)計(jì)方案說明如下: eFUSE方式使用Chip重新編程管理控制 SOC方式使用軟件管理控制 hardware實(shí)現(xiàn)控制edm_restrict_access的示意圖如下: ![]() 圖表5 hardware實(shí)現(xiàn)控制edm_restrict_access的示意圖 software實(shí)現(xiàn)控制edm_restrict_access的例子如下: sethi $r2,#0x80000 ori $r2,$r2,#0x8c sethi $r3,#0x04030 ori $r3,$r3,#0x201 swi $r3,[$r2+#0] 3. EDM 存取指示 AndesCoreTM增加一個(gè)額外的sideband signal,xdebug_access(active-high),根據(jù)此sideband signal來決定request的host是否為EDM。而device就能根據(jù)此sideband signal決定是否要把request的data內(nèi)容傳回到host。 sideband signal的名稱根據(jù)bus interface的類型而有所不同。對(duì)于AndesCoreTM處理器,基本的信號(hào)名稱如下所示: AHB/AHB-Lite => hdebug_access APB => pdebug_access EILM => eilm_debug_access EDLM => edlm_debug_access 3.1.debug存取識(shí)別信號(hào)控制 當(dāng)debug exception發(fā)生后,CPU將進(jìn)入debug mode。然后CPU將會(huì)留在debug access mode直到CPU執(zhí)行到IRET instruction并且trusted_debug_exit 是處于high后CPU將離開debug access mode,反之trusted_debug_exit如果是low,CPU將會(huì)保留在debug access mode。 實(shí)現(xiàn)控制trusted_debug_exit信號(hào),有二種可供選擇的方式如下: trusted_debug_exit信號(hào)總是給high 增加一個(gè)權(quán)限管理邏輯去控制trusted_debug_exit信號(hào)是high或是low權(quán)限管理邏輯方塊圖如下所示: ![]() 圖表6 權(quán)限管理邏輯方塊圖 如何控制trusted_debug_exit信號(hào)時(shí)序圖如下所示: ![]() 圖表7 如何控制trusted_debug_exit信號(hào)時(shí)序圖 如下例子說明了如何產(chǎn)生trusted_debug_exit控制信號(hào)的verilog code: The code example (Verilog) of trusted_debug_exit generation is described below: // //--- Utilize passcode to generate trusted_debug_exit in AHB Bus Controller //* assume zero-wait-state AHB access … parameter AUTH_CODE = 32’h0a0b0c0d; ... always @(posedge hclk or negedge hreset_n) begin if (!hreset_n) begin passcode_reg <= 32'd0; end else if (passcode_wen) begin //debugger enters passcode through debug access passcode_reg <= hwdata[31:0]; end end … //validate passcode to generate trusted_debug_exit assign trusted_debug_exit = (passcode_reg == AUTH_CODE); 3.2.debug存取指示應(yīng)用 下圖說明AHB bus如何使用hdebug_access和驗(yàn)證邏輯來防止惡意的debug存取 ![]() 圖表8 AHB bus如何使用hdebug_access和驗(yàn)證邏輯來防止惡意的debug存取 如下verilog code說明了如何使用hdebug_access信號(hào): //--- Use hdebug_access to prevent malicious debug access in AHB Bus Controller //* assume zero-wait-state AHB access … parameter IRRELEVANT_DATA = 32’hcafe0001; parameter AUTH_CODE = 32’h01020304; … always @(posedge hclk or negedge hreset_n) begin if (!hreset_n) begin dbg_acc_d1 <= 1'b0; end else begin // data phase indication of debug access dbg_acc_d1 <= hdebug_access; end end ... always @(posedge hclk or negedge hreset_n) begin if (!hreset_n) begin passcode_reg <= 32'd0; end else if (passcode_wen) begin //debugger enters passcode through debug access passcode_reg <= hwdata[31:0]; end end … //validate passcode to check authentication assign auth_check_fail = (passcode_reg != AUTH_CODE); //return irrelevant data if the authentication check of debug access fails assign hrdata_out = {32{data_read_en}} & ((dbg_acc_d1 & auth_check_fail) IRRELEVANT_DATA : normal_data_out); 4. 實(shí)際的應(yīng)用 用戶經(jīng)由上面的介紹完成了權(quán)限管理邏輯后,并且掛在AndesCoreTMAHB bus上,再經(jīng)由仿真器(Cadence)仿真此權(quán)限管理邏輯的行為,如下面幾張圖所示: edm_restrict_access信號(hào)控制 下圖說明由sw code把edm_restrict_access signal disable ![]() 圖表9 由sw code把edm_restrict_access signal disable trusted_debug_exit信號(hào)控制 ![]() 圖表10 經(jīng)由debug access把trusted_debug_exit signal設(shè)定成high debug_access信號(hào) 下圖說明經(jīng)由debug host來做存取時(shí),debug_access signal會(huì)從low變成high ![]() 圖表11 經(jīng)由debug host來做存取時(shí),debug_access signal會(huì)從low變成high 下圖說明經(jīng)由執(zhí)行IRTE instruction時(shí),debug_access signal會(huì)從high變成low ![]() 圖表12 經(jīng)由執(zhí)行IRTE instruction時(shí),debug_access signal會(huì)從high變成low 5. 結(jié)語 EDM安全存取是AndesCoreTM保護(hù)周邊裝置內(nèi)容不被竊取的功能,也因?yàn)樵絹碓蕉嗫蛻羰褂玫酱斯δ埽宰珜懘思夹g(shù)文章讓客戶更能進(jìn)一步了解到此功能的用途,讓客戶能夠很快速的上手,并且使用晶心開發(fā)的EDM安全存取是一件愉快與簡單的工作。 |