Git Product home page Git Product logo

openlab's Issues

sscanf messes up the stack

Using 'sscanf' in a application multiple times crashes the node.
On M3 nodes I get a stack overflow, and on agile-fox I get a HARD FAULT.

The following code can reproduce the problem.

#include <string.h>
#include "platform.h"
#include "printf.h"
#include "scanf.h"

static void test_task(void *param)
{
    int i = 0;
    int a;
    while (1) {
        printf("%d\n", i++);
        sscanf("1", "%d", &a);
        soft_timer_delay_ms(10);
    }
}

int main()
{
    platform_init();
    xTaskCreate(test_task, (const signed char *const) "test_task",
            configMINIMAL_STACK_SIZE, NULL, 1, NULL);
    platform_run();
    return 0;
}

I kept the soft_timer_delay here, because the problem did not appear using the hikob last revision on M3 nodes build using RELEASE=0. It's only a matter of 'luck' according to the tests I run, as the node crashes whithout the soft_timer_delay in RELEASE=2 mode.

On a fox node:

[100%] Built target flash_test_stack_overflow_scanf
Platform starting in 1...
GO!
FreeRTOS Heap Free: 20680
0
1
2
3
4
5
6
7
8
9
10
11
12
13
1

******** HARD FAULT *********
Caused at pc:   8000FC8 lr: FFFFFFFD
        r0: 0
        r1: 460E90
        r2: 200009D8
        r3: 200009F0
*****************************
Looking for Memory Management fault...
done!
*****************************
Looking for Bus fault...
        Precise Data Bus Error
        Faulty Address: 460E90
done!
*****************************
Looking for Usage fault...
done!
*****************************
Debugging Queues...
Queue #0 Current event:  00000000 (00000000), 0 waiting:
Queue #1 Current event:  00000000 (00000000), 0 waiting:
Debugging soft timer (now: 164312):
        FIRST->
        NULL 

On a M3 node:

Platform starting in 1... 
GO!
FreeRTOS Heap Free: 20680
0
1
2
3
4
5
6
7
.....
154
155
[in vApplicationStackOverflowHook() ERROR] Task 'test_ta' has stack OVERFLOWED!
Debugging Queues...
Queue #0 Current event:  00000000 (00000000), 0 waiting:
Queue #1 Current event:  00000000 (00000000), 0 waiting:
Debugging soft timer (now: 149861):
    FIRST->
    NULL

The problem first appeared in a more complex application based of the event queues where the function call was only done once per event. I changed to this version to get a cleaner code.

PATCH: remove scsi build warnings

I found two remaining warnings while compiling all the code in the repository

build $ make
....
In file included from /home/harter/work/openlab/lib/libusb.h:43:0, from /home/harter/work/openlab/platform/agile-fox/agilefox_usb.c:33:
/home/harter/work/openlab/lib/usb/scsi.h:108:22: warning: 'params' defined but not used [-Wunused-variable]
...
/home/harter/work/openlab/lib/usb/scsi.c:84:1: warning: useless storage class specifier in empty declaration [enabled by default]

With the following patch, all the repository can build without errors for platforms agile-fox, fiteco-a8, fiteco-m3 and fiteco-gwt.
It can then be compiled with -Werror.

diff --git a/lib/usb/msc.c b/lib/usb/msc.c
index 2396913..5058880 100644
--- a/lib/usb/msc.c
+++ b/lib/usb/msc.c
@@ -601,6 +601,8 @@ int usb_msc_scsi_handler(bool firstcall)
     scsi_status_t  status;
     uint32_t       datalen;
     static uint8_t cnum;
+    scsi_params_t params;
+

     /*
      * Do the actual SCSI Command
diff --git a/lib/usb/scsi.c b/lib/usb/scsi.c
index a7772fa..d9010d2 100644
--- a/lib/usb/scsi.c
+++ b/lib/usb/scsi.c
@@ -71,7 +71,7 @@ typedef enum {


 //power types used for start_stop_unit (table 169 in Seagate)
-typedef enum{
+typedef enum {
        START_VALID     = 0x00,
        ACTIVE          = 0x01,
        IDLE            = 0x02,
@@ -81,7 +81,7 @@ typedef enum{
        FORCE_ILDE_0    = 0x0A,
        FORCE_STANDBY_0 = 0x0B,
        //all others are reserved
-};
+} scsi_cdb_power_t;

 typedef enum {
     SCSI_TEST_UNIT_READY              = 0x00,
diff --git a/lib/usb/scsi.h b/lib/usb/scsi.h
index 5e2c330..8a0048e 100644
--- a/lib/usb/scsi.h
+++ b/lib/usb/scsi.h
@@ -103,9 +103,7 @@ typedef struct{
     uint32_t       datamax;
     uint32_t      *datalen;
     scsi_status_t *status;
-}scsi_params_t;
-
-static scsi_params_t params;
+} scsi_params_t;

 typedef enum {
     USB_MSC_NONE,

cmake build fails (vanilla xubuntu 13.10)

Fresh git clone:

fambon@carolus:~$ git clone https://github.com/hikob/openlab.git
Cloning into 'openlab'...
remote: Reusing existing pack: 1378, done.
remote: Total 1378 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (1378/1378), 1.40 MiB | 399.00 KiB/s, done.
Resolving deltas: 100% (649/649), done.
Checking connectivity... done

fambon@carolus:~$ cd openlab
fambon@carolus:~/openlab$ mkdir build
fambon@carolus:~/openlab$ cd build/

fambon@carolus:~/openlab/build$ cmake .. -DPLATFORM=agile-fox
-- The C compiler identification is GNU 4.8.1
-- The CXX compiler identification is unknown
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
CMake Error: your CXX compiler: "CMAKE_CXX_COMPILER-NOTFOUND" was not found.   Please set CMAKE_CXX_COMPILER to a valid compiler path or name.
-- Found Doxygen: /usr/bin/doxygen (found version "1.8.4") 
-- Configuring incomplete, errors occurred!

Environment:

fambon@carolus:~/openlab/build$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 13.10
Release:    13.10
Codename:   saucy

fambon@carolus:~/openlab/build$ cmake --version
cmake version 2.8.11.2

fambon@carolus:~/openlab/build$ which arm-none-eabi-gcc
/home/fambon/gcc-arm-none-eabi-4_8-2013q4/bin/arm-none-eabi-gcc

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.