Unknown syntax error in HCS08 MCU - c

I'm programming a freescale MCU and I'm using codewarrior version 10.5. I just downloaded some code from the distributor's web page, and I'm getting this syntax error in the next lines. Any help wold be appreciated!
/* Initialization of the CPU registers in FLASH */
/* NVPROT: FPS=0x7F,FPDIS=1 */
const volatile NVPROTSTR _NVPROT #0x0000FFBD = { 0xFF };
/* NVOPT: KEYEN=0,FNORED=1,SEC01=1,SEC00=0 */
const volatile NVOPTSTR _NVOPT #0x0000FFBF = { 0x7E };
Also I don't understand the use of # here. Is it any special register? Is it an address?
This is what I get in the console:
**** Build of configuration FLASH for project qg8_test ****
"C:\\Freescale\\CW MCU v10.5\\gnu\\bin\\mingw32-make" -j8 all
'Building file: ../Sources/MCUinit.c'
'Executing target #1 ../Sources/MCUinit.c'
'Invoking: HCS08 Compiler'
"C:/Freescale/CW MCU v10.5/MCU/prog/chc08" -ArgFile"Sources/MCUinit.args" -ObjN="Sources/MCUinit_c.obj" "../Sources/MCUinit.c" -Lm="Sources/MCUinit_c.d" -LmCfg=xilmou
../Sources/MCUinit.c
Command Line: '-ArgFile"Sources/MCUinit.args" -ObjN="Sources/MCUinit_c.obj" "../Sources/MCUinit.c" -Lm="Sources/MCUinit_c.d" -LmCfg=xilmou'
C:/Users/oskra/workspace/qg8_test/Project_Headers\../Sources\MCUinit.c
C:/Users/oskra/workspace/qg8_test/Project_Headers\MC9S08QG8.h
Option -Lm Update: Create new dependency file
Option -Lm: Adding make info to 'Sources/MCUinit_c.d'
C:/Users/oskra/workspace/qg8_test/Project_Headers\../Sources\MCUinit.c:135:error:C2450 Expected: ~ ( IDENT
mingw32-make: *** [Sources/MCUinit_c.obj] Error 1

Related

Using config.ini variables in ldscript.ld

In my config.ini file I have defined these variables:
# Where will system be loaded when started (for which address to prepare it)
LOAD_ADDR = 0x100000
RAM_ADDR = 0x300000
ROM_ADDR = 0x200000
STACK_ADDR = 0x600000
Which I then use in the .data section of the linker script ldscript.ld:
SECTIONS {
.code LOAD_ADDR :
{ /* This is line 9 */
kernel_code_addr = .;
/* instructions */
*?/boot/startup.asm.o ( .text* )
*( .text* )
}
.data RAM_ADDR : AT(ROM_ADDR)
{
kernel_data_addr = .;
/* read only data (constants), initialized global variables */
* ( .rodata* .data* )
}
.bss :
{
*( .bss* COMMON* )
. = ALIGN (4096);
}
/* ... */
}
But running make fails while linking with this error:
[linking build/04_Debugging.elf]
ld:build/ldscript.ld:9: non constant or forward reference address expression for section .data
make: *** [Makefile:87: build/04_Debugging.elf] Error 1
When I replace RAM_ADDR and ROM_ADDR in the code with their values, make finishes nicely and everything works.
What causes this error? Why can I use LOAD_ADDR with no errors?
The linker does not seem to load the variables you defined in config.ini.
You can use INCLUDE in your linker script to include another file.
From https://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_chapter/ld_3.html
INCLUDE filename
Include the linker script filename at this point. The file will be searched for in the current directory, and in any directory specified with the -L option. You can nest calls to INCLUDE up to 10 levels deep.
So if you add INCLUDE config.ini to the start of your linker script it should work.
Another approach is to use the C preprocessor to generate your linker script.
You can use -imacros to load a config.h that defines the symbols you want, then use them in the linkerscript.ld.h and generate the linker script before using it to link
gcc -imacros config.h -E linkerscript.ld.h -o linkerscript.ld

why cannot open source input file "ARMCM3.h":? with ST-link and STM32F103ZET6

When I tried to build the following project with those code, the error happened like this !
#include <stm32f10x.h>
#include "stm32f10x_gpio.h"
#include "stm32f10x_rcc.h"
void LED_GPIO_Config(void){
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_SetBits(GPIOB, GPIO_Pin_5);
}
//delay
void delay_nms(u16 time){
u16 i = 0;
while(time--){
i = 12000;
while(i--);
}
}
//main
int main(void){
SystemInit();
LED_GPIO_Config();
while(1){
GPIO_SetBits(GPIOB, GPIO_Pin_5);
delay_nms(1000);
GPIO_ResetBits(GPIOB, GPIO_Pin_5);
delay_nms(1000);
}
}
The output like this:
*** Using Compiler 'V5.06 update 2 (build 183)', folder: 'C:\Keil_v5\ARM\ARMCC\Bin'
Rebuild target 'Target 1'
compiling ControllerFunctions.c...
compiling BayesFunctions.c...
compiling FastMathFunctions.c...
compiling DistanceFunctions.c...
compiling ComplexMathFunctions.c...
compiling BasicMathFunctions.c...
compiling main.c...
compiling LED_MCBSTM32E.c...
compiling MatrixFunctions.c...
assembling irq_cm3.s...
compiling cmsis_os1.c...
compiling SVMFunctions.c...
compiling StatisticsFunctions.c...
compiling SupportFunctions.c...
compiling rtx_lib.c...
compiling rtx_evr.c...
compiling rtx_delay.c...
compiling rtx_evflags.c...
compiling rtx_kernel.c...
compiling CommonTables.c...
compiling rtx_memory.c...
compiling rtx_mempool.c...
compiling rtx_mutex.c...
compiling rtx_semaphore.c...
compiling rtx_system.c...
compiling rtx_msgqueue.c...
compiling RTX_Config.c...
compiling RV_Framework.c...
D:\u_version projects\ZET6\LED_1\RTE\CMSIS_RTOS_Validation\RV_Config.h(10): error: #5: cannot open
source input file "ARMCM3.h": No such file or directory
#include "ARMCM3.h"
C:\Keil_v5\ARM\PACK\ARM\CMSIS-RTOS_Validation\1.1.0\Source\RV_Framework.c: 0 warnings, 1 error
compiling RV_Report.c...
D:\u_version projects\ZET6\LED_1\RTE\CMSIS_RTOS_Validation\RV_Config.h(10): error: #5: cannot open
source input file "ARMCM3.h": No such file or directory
#include "ARMCM3.h"
C:\Keil_v5\ARM\PACK\ARM\CMSIS-RTOS_Validation\1.1.0\Source\RV_Report.c: 0 warnings, 1 error
compiling RV_Timer.c...
D :\u_version projects\ZET6\LED_1\RTE\CMSIS_RTOS_Validation\RV_Config.h(10): error: #5: cannot open
source input file "ARMCM3.h": No such file or directory
#include "ARMCM3.h"
C:\Keil_v5\ARM\PACK\ARM\CMSIS-RTOS_Validation\1.1.0\Source\RV_Timer.c: 0 warnings, 1 error
compiling RV_WaitFunc.c...
D:\u_version projects\ZET6\LED_1\RTE\CMSIS_RTOS_Validation\RV_Config.h(10): error: #5: cannot open
source input file "ARMCM3.h": No such file or directory
#include "ARMCM3.h"
C:\Keil_v5\ARM\PACK\ARM\CMSIS-RTOS_Validation\1.1.0\Source\RV_WaitFunc.c: 0 warnings, 1 error
compiling cmsis_rv.c...
D:\u_version projects\ZET6\LED_1\RTE\CMSIS_RTOS_Validation\RV_Config.h(10): error: #5: cannot open
source input file "ARMCM3.h": No such file or directory
#include "ARMCM3.h"
C:\Keil_v5\ARM\PACK\ARM\CMSIS-RTOS_Validation\1.1.0\Source\cmsis_rv.c: 0 warnings, 1 error
compiling rtx_timer.c...
compiling rtx_thread.c...
compiling os_systick.c...
assembling startup_stm32f10x_hd.s...
compiling FilteringFunctions.c...
compiling TransformFunctions.c...
compiling misc.c...
compiling stm32f10x_gpio.c...
compiling DMA_STM32F10x.c...
compiling stm32f10x_rcc.c...
compiling GPIO_STM32F10x.c...
compiling system_stm32f10x.c...
".\Objects\LED.axf" - 5 Error(s), 0 Warning(s).
Target not created.
Build Time Elapsed: 00:00:05
Load "D:\\u_version projects\\ZET6\\LED_1\\Objects\\LED.axf"
_____^
*** error 56: cannot open file
Error: Flash Download failed - Could not load file 'D:\u_version
projects\ZET6\LED_1\Objects\LED.axf'
Flash Load finished at 11:00:32
Besides, I am using st-link with stm32f103zet6!
I do not know why it ccould not find the file and I also did not find the file either!
Is that because some packages were broken or how to solve this?
Thank you!
Probably you miss a define needed to import the right headers. Try to pass STM32F103xE symbol to the compiler. The file may be not located in the project folder but could be imported from an another include path outside the project.

How to enable clang static analyzer's "alpha.security.taint check" checker

I am trying to execute clang static analyzer (version 3.8) on some of the examples shown in its documentation (https://clang-analyzer.llvm.org/alpha_checks.html#security_alpha_checkers).
I created a small C program, as follows:
// note: requires alpha.security.taint check turned on.
void test() {
char s[] = "abc";
int x = getchar();
char c = s[x]; // warn: index is tainted
}
I am executing following command to analyze the above code:
/usr/lib/llvm-3.8/bin/scan-build -enable-checker alpha.security.taint.TaintPropagation clang -c example.c
The above command generates following error report:
scan-build: Using '/usr/lib/llvm-3.8/bin/clang' for static analysis
example.c:5:8: warning: Value stored to 'c' during its initialization is never read
char c = s[x]; // warn: index is tainted
^ ~~~~
1 warning generated.
scan-build: 1 bug found.
scan-build: Run 'scan-view /tmp/scan-build-2018-04-09-143549-15413-1' to examine bug reports.
I was expecting clang SA will complain about possible buffer overflow and buffer underflow at line 5, but it seems like taint analysis is not performed.
Can someone please suggest how to enable "alpha.security.taint" check?
To get a warning when using a tainted array index, you have to enable alpha.security.ArrayBoundV2 and alpha.security.taint.TaintPropagation:
$ ~/bld/llvm-project/build/bin/scan-build -enable-checker \
alpha.security.taint.TaintPropagation,alpha.security.ArrayBoundV2 \
gcc -c taint2.c
scan-build: Using '/home/scott/bld/llvm-project/build/bin/clang-9' for static analysis
taint2.c:6:10: warning: Value stored to 'c' during its initialization is never read
char c = s[x]; // warn: index is tainted
^ ~~~~
taint2.c:6:14: warning: Out of bound memory access (index is tainted)
char c = s[x]; // warn: index is tainted
^~~~
2 warnings generated.
scan-build: 2 bugs found.
scan-build: Run 'scan-view /tmp/scan-build-2019-09-11-204837-97704-1' to examine bug reports.
The TaintPropagation checker reports some things by itself, for example, passing tainted data to system(). It also exports tainting information for other checkers to use.
(I discovered this information primarily by looking at the source code, and secondarily through trial and error. The documentation isn't much help.)

Referencing symbols in other files using PPC assembly

How can you reference a symbol external to the current file in ppc assembly? I've tried looking at the .extern keyword as well as adding a new symbol in the linker file but with no success.
I have two ppc assembly files that are part of a larger project. I wish to reference a symbol (__head) in file1 from file2 in this way:
file1.S:
.section ".head","ax"
. = 0
.global __head
__head:
file2.S:
.section ".head","ax"
...
LOAD_32(%r3, file2_symbol_name - __head)
where LOAD_32 is
#define LOAD_32(r, e) \
lis r,(e)#h; \
ori r,r,(e)#l;
...but am getting the following error:
file2.S: Assembler messages:
file2.S:113: Error: can't resolve `file2_symbol_name' {.head section} - `__head' {*UND* section}
file2.S:113: Error: expression too complex
When used in file1 LOAD_32(%r3, file1_symbol_name - __head) works just fine so I know I'm not importing the symbol name correctly. How can I do this?
EDIT:
I have reduced my problem to the bare minimum parts so that I am clear about the problem. Below is all of the code, linker file, Makefile, and the terminal output for "make quick".
NB: When I comment out line 9 of other.S the project compiles without error.
head.S:
#include "asm-defines.h"
.section ".head","ax"
.align 0x10
. = 0x0
.global __head
__head:
LOAD_32(%r3, file1_symbol_name - __head)
b .
file1_symbol_name:
b .
other.S
#include "asm-defines.h"
.section ".head","ax"
.align 0x10
.global other
other:
LOAD_32(%r3, file2_symbol_name)
LOAD_32(%r3, file2_symbol_name - __head)
b .
file2_symbol_name:
b .
asm-defines.h:
#ifndef ASM_DEFINES_H
#define ASM_DEFINES_H
/* Load an immediate 32-bit value into a register */
#define LOAD_32(r, e) \
lis r,(e)#h; \
ori r,r,(e)#l;
#endif //ASM_DEFINES_H
quick.lds
ENTRY(__head);
Makefile
CC=$(CROSS)gcc
QFLAGS := -Wl,--oformat,elf64-powerpc -pie -m64 -mbig-endian -nostdlib
quick:
$(CC) $(QFLAGS) -T quick.lds head.S other.S -o quick.o
$(CROSS) is a path to the cross compiler which I have omitted.
The CC is powerpc64le-buildroot-linux-gnu-gcc
Terminal
$ make quick
powerpc64le-buildroot-linux-gnu-gcc -Wl,--oformat,elf64-powerpc -pie -m64 -mbig-endian -nostdlib -T quick.lds head.S other.S -o quick.o
other.S: Assembler messages:
other.S:9: Error: can't resolve `.head' {.head section} - `__head' {*UND* section}
other.S:9: Error: expression too complex
other.S:9: Error: can't resolve `.head' {.head section} - `__head' {*UND* section}
other.S:9: Error: expression too complex
make: *** [quick] Error 1
The assembler cannot know the placement / relative position of head.S and other.S at assembly time to be able to compute the relative displacement of the file2_symbol_name and __head labels. This is a general assembly language question, not PPC specific.
Regarding David's response, see https://sourceware.org/binutils/docs/as/Infix-Ops.html#Infix-Ops, where it specifies: "Subtraction. If the right argument is absolute, the result has the section of the left argument. If both arguments are in the same section, the result is absolute. You may not subtract arguments from different sections." The error message indicates that the assembler has no idea which section contains __head, which indeed it cannot, since the symbol and its section are not defined in filescope.
You might be able to get what you want by using the .weak and/or .weakref directives so that the symbol can be defined in two files, with the strong reference overriding the weak one at link time. I haven't experimented with this. See the manual (https://sourceware.org/binutils/docs/as/) and hunt for .weak.
Some background information on weak symbols is here: https://en.wikipedia.org/wiki/Weak_symbol.

How to fail the build based on the conditional values of linker variables defined in linker script?

How to fail the build based on the conditional values of linker variables defined in linker script?
I am compiling C code using GCC. I defined a linker variable BINARY_TEST. If Value of BINARY_TEST > 32KB, then i want to Fail the build. How to write a conditional test and fail the build using linker script?
Please suggest any script.
SECTIONS
{
. = 0x0000 ;
.text :
{
*(.text)
*(.rdata)
}
.data :
{
*(*.data)
*(*.bss)
}
BINARY_TEST = . ;
/*Want something like below */
if (BINARY_TEST > 32KB)
Throw Error and stop
/* ******* */
END = . ;
}
How to write a conditional test and fail the build using linker script?
It seems to me that you could trivially implement the failure as a post-link step. E.g. in your Makefile:
foo.exe: foo.o
$(CC) -o foo.exe ...
nm foo.exe | grep BINARY_TEST | \
... commands to verify that symbol value < 32K, or fail
Here is one way to do this:
CHECK_BOOTLOADER_SIZE = 1 / (. <= 32768);
If the current position is beyond the limit, this will give an error message:
linker.ld:33 / by zero
Not the clearest error message but at least it includes the line number so that user can read the comments.

Resources