# Not able to upload programs expect in safe boot mode

**URL:** <https://forums.sifive.com/t/not-able-to-upload-programs-expect-in-safe-boot-mode/362>\
**Category:** HiFive1 Rev B\
**Created:** [February 24, 2017, 1:33pm UTC](https://forums.sifive.com/t/not-able-to-upload-programs-expect-in-safe-boot-mode/362 "2017-02-24T13:33:03Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![nonerkao](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/nonerkao/32/194_2.png) [@nonerkao](https://forums.sifive.com/u/nonerkao)\
**Post date:** [February 24, 2017, 1:33pm UTC](https://forums.sifive.com/t/not-able-to-upload-programs-expect-in-safe-boot-mode/362/1 "2017-02-24T13:33:04Z")

</div>

Hi,

I bought two hifive1s. One was the early version, and the other board is a normal one. I just got the latter one and do some test with it. The result is somehow weird.

I success uploading the hello program to it, but then when I try any other programs, messages like

```auto
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
adapter speed: 10000 kHz
Info : auto-selecting first available session transport "jtag". To override use 'transport select <transport>'.
Info : ftdi: if you experience problems at higher adapter clocks, try the command "ftdi_tdo_sample_edge falling"
Info : clock speed 10000 kHz
Info : JTAG tap: riscv.cpu tap/device found: 0x10e31913 (mfg: 0x489 (<unknown>), part: 0x0e31, ver: 0x1)
Error: Wrote 0xffe04493 to Debug RAM at 0, but read back 0xfff04493
Error: Debug RAM 0x0: 0xffe04493
Error: Debug RAM 0x1: 0x01f4d493
Error: Debug RAM 0x2: 0x40902023
Error: Debug RAM 0x3: 0x01f4d493
Error: Debug RAM 0x4: 0x40902223
Error: Debug RAM 0x5: 0x3f00006f
Error: Debug RAM 0x6: 0x060c1218
Error: Debug RAM 0x7: 0xf3efffff
Error: Debug RAM 0x8: 0x00000000
Error: Debug RAM 0x9: 0x00000000
Error: Debug RAM 0xa: 0x00000000
Error: Debug RAM 0xb: 0x00000000
Error: Debug RAM 0xc: 0x00000000
Error: Debug RAM 0xd: 0x00000000
Error: Debug RAM 0xe: 0x00000000
Error: Debug RAM 0xf: 0x00000000
Error: Target not examined yet

```

appears, and fails.

Getting into the safe mode does allow me to upload a new program, but then the same situation repeats, while the first hifive1 I got never showed these behaviors.

So I would like to know that how should I fix this problem? Is there more information you need to help me with this? Thanks.

---

<div class="post-metadata">

**Author:** ![brucehoult](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/brucehoult/32/24_2.png) [@brucehoult](https://forums.sifive.com/u/brucehoult)\
**Post date:** [February 24, 2017, 2:04pm UTC](https://forums.sifive.com/t/not-able-to-upload-programs-expect-in-safe-boot-mode/362/2 "2017-02-24T14:04:03Z")

</div>

Have you changed the clock speed at all? Does it work at 16 MHz in the Arduino IDE?

---

<div class="post-metadata">

**Author:** ![nonerkao](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/nonerkao/32/194_2.png) [@nonerkao](https://forums.sifive.com/u/nonerkao)\
**Post date:** [February 24, 2017, 2:14pm UTC](https://forums.sifive.com/t/not-able-to-upload-programs-expect-in-safe-boot-mode/362/3 "2017-02-24T14:14:57Z")

</div>

Thanks for your reply.

I use the SDK directly and I don’t have an Arduino IDE.  
What should I do to change the clock speed correctly? I have check the getting start guide and find nothing about clock speed.

---

<div class="post-metadata">

**Author:** ![mwachs5](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/mwachs5/32/13_2.png) [@mwachs5](https://forums.sifive.com/u/mwachs5)\
**Post date:** [February 24, 2017, 4:41pm UTC](https://forums.sifive.com/t/not-able-to-upload-programs-expect-in-safe-boot-mode/362/4 "2017-02-24T16:41:34Z")

</div>

Hmm, sounds like things are spotty on the debug/JTAG connection, it reports a 1 bit error but then reads the right thing later. This could be a clock speed issue, but let’s try to get to the bottom of what’s going on. Bunch of questions for you, answer whatever you’re comfortable with.

- If you upload a program in safe mode, does the program itself run successfully?

- All the programs in the SDK boost the clock frequency to 256 kHz or so and print it over the UART. I’m curious what speed yours is at, can you see the message?

- Is the error message always _exactly_ the same? Is the 1-bit error always in the same place, or is it wrong in various ways?

- You can prevent the SDK from boosting the clock frequency by adding ‘-DNO\_INIT’ while you’re compiling, by adding it to the program’s Makefile (see [https://github.com/sifive/freedom-e-sdk/blob/master/software/double\_tap\_dontboot/Makefile#L3](https://github.com/sifive/freedom-e-sdk/blob/master/software/double_tap_dontboot/Makefile#L3) for an example). You could try adding that flag to freedom-e-sdk/software/led\_fade/Makefile for example, and see if it impacts the ability to upload the next program.

- are you using the same USB cable you were using before? We’ve noticed the boards are sensitive to older/flaky USB cables ( [these from Amazon](https://www.amazon.com/gp/product/B013PVKQHC/ref=s9_acsd_zgift_hd_bw_b1woE_c_x_w?pf_rd_m=ATVPDKIKX0DER&pf_rd_s=merchandised-search-5&pf_rd_r=RPSRFPWZYJX0JP4VD95N&pf_rd_t=101&pf_rd_p=605a4b89-b795-58c5-aa4f-24d9842532ff&pf_rd_i=464394) have a noticeably tighter fit than some others we had lying around the lab).

- You could try reducing the adapter speed (in freedom-e-sdk/bsp/env/freedom-e300-hifive1/openocd.cfg) : [https://github.com/sifive/freedom-e-sdk/blob/master/bsp/env/freedom-e300-hifive1/openocd.cfg#L1](https://github.com/sifive/freedom-e-sdk/blob/master/bsp/env/freedom-e300-hifive1/openocd.cfg#L1)

Let us know what you’re seeing and we can figure out what’s going on.

Quite frankly I am always pleasantly surprised when things work _without_ the safe bootloader… I was planning to change the OpenOCD config to do the “double tap” itself to force the processor to be in a safe mode before it tries to reprogram, but until now it hasn’t proven to be necessary.

Thanks for reporting this!  
Megan

---

<div class="post-metadata">

**Author:** ![nonerkao](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/nonerkao/32/194_2.png) [@nonerkao](https://forums.sifive.com/u/nonerkao)\
**Post date:** [February 26, 2017, 12:19pm UTC](https://forums.sifive.com/t/not-able-to-upload-programs-expect-in-safe-boot-mode/362/5 "2017-02-26T12:19:43Z")

</div>

Thanks for your debugging questions and instructions. I will try to reply all of them below.

> If you upload a program in safe mode, does the program itself run successfully?

Yes. `hello`, `demo_gpio` and some others are tested and OK.

> All the programs in the SDK boost the clock frequency to 256 kHz or so and print it over the UART. I’m curious what speed yours is at, can you see the message?

Do you mean the line of `Info: clock speed: 10000 kHz` ?  
[This](http://www.m100.nthu.edu.tw/~s100062539/normal.log) log is shown when success,  
and [This](http://www.m100.nthu.edu.tw/~s100062539/fail.log) log when it fails.

> Is the error message always exactly the same? Is the 1-bit error always in the same place, or is it wrong in various ways?

There is always some line like `Error: Wrote 0xffe04493 to Debug RAM at 0, but read back 0xfff04493`. The 1-bit error remains.

> You can prevent the SDK from boosting the clock frequency by adding ‘-DNO\_INIT’ while you’re compiling, by adding it to the program’s Makefile (see [https://github.com/sifive/freedom-e-sdk/blob/master/software/double\_tap\_dontboot/Makefile#L3](https://github.com/sifive/freedom-e-sdk/blob/master/software/double_tap_dontboot/Makefile#L3) for an example). You could try adding that flag to freedom-e-sdk/software/led\_fade/Makefile for example, and see if it impacts the ability to upload the next program.

It seems no effect adding this added flag.

> are you using the same USB cable you were using before? We’ve noticed the boards are sensitive to older/flaky USB cables ( these from Amazon1 have a noticeably tighter fit than some others we had lying around the lab).

Yes. It’s a new cable.

> You could try reducing the adapter speed (in freedom-e-sdk/bsp/env/freedom-e300-hifive1/openocd.cfg) : [https://github.com/sifive/freedom-e-sdk/blob/master/bsp/env/freedom-e300-hifive1/openocd.cfg#L1](https://github.com/sifive/freedom-e-sdk/blob/master/bsp/env/freedom-e300-hifive1/openocd.cfg#L1)

I tried 5000 kHz and 1000kHz, but it seems no effect. The output remains like the fail log above.

I hope the information helps, thanks!

---

<div class="post-metadata">

**Author:** ![brucehoult](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/brucehoult/32/24_2.png) [@brucehoult](https://forums.sifive.com/u/brucehoult)\
**Post date:** [February 26, 2017, 2:43pm UTC](https://forums.sifive.com/t/not-able-to-upload-programs-expect-in-safe-boot-mode/362/6 "2017-02-26T14:43:40Z")

</div>

> [@nonerkao](#):
>
> Do you mean the line of Info: clock speed: 10000 kHz ?This log is shown when success,and This log when it fails.

I believe @mwachs5 meant the output on USB serial when you run the program. e.g.

In your console:

```
 bruce:~/freedom-e-sdk$ make upload PROGRAM=led_fade

```

On USB serial (e.g. in GNU screen or etc as described in “Getting started”

```
core freq at 263156531 Hz

                SIFIVE, INC.

         5555555555555555555555555
        5555 5555
       5555 5555
      5555 5555
     5555 5555555555555555555555
    5555 555555555555555555555555
   5555 5555
  5555 5555
 5555 5555
5555555555555555555555555555 55555
 55555 555555555 55555
   55555 55555 55555
     55555 5 55555
       55555 55555
         55555 55555
           55555 55555
             55555 55555
               55555 55555
                 555555555
                   55555
                     5

               'led_fade' Demo 

55555555555555555555555555555555555555555555555
5555555 Are the LEDs Changing? [y/n] 555555555
55555555555555555555555555555555555555555555555
y
PASS

```

The first line above.

---

<div class="post-metadata">

**Author:** ![nonerkao](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/nonerkao/32/194_2.png) [@nonerkao](https://forums.sifive.com/u/nonerkao)\
**Post date:** [February 27, 2017, 2:01am UTC](https://forums.sifive.com/t/not-able-to-upload-programs-expect-in-safe-boot-mode/362/7 "2017-02-27T02:01:27Z")

</div>

Thanks for your tips.

Some samples here (There is a pre-loaded `hello` example in the board, and I just push the reset several times):

```auto
core freq at 259601203 Hz
hello world!

Progam has exited with code:0x00000000
core freq at 258854092 Hz
hello world!

Progam has exited with code:0x00000000
core freq at 258811494 Hz
hello world!

Progam has exited with code:0x00000000
core freq at 258726297 Hz
hello world!

Progam has exited with code:0x00000000
core freq at 258939289 Hz
hello world!

Progam has exited with code:0x00000000
...

```

---

<div class="post-metadata">

**Author:** ![mwachs5](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/mwachs5/32/13_2.png) [@mwachs5](https://forums.sifive.com/u/mwachs5)\
**Post date:** [February 27, 2017, 4:44pm UTC](https://forums.sifive.com/t/not-able-to-upload-programs-expect-in-safe-boot-mode/362/8 "2017-02-27T16:44:17Z")

</div>

Thanks for all your answers!

I’m still intrigued by this. We would of course be happy to just exchange your board (email [info@sifive.com](mailto:info@sifive.com) if you want to go that route), but that will mean a wait for you and I’m still wondering if there is something simple going on.

If you’re willing, could you try a few more things:

- Can you make sure you have the latest versions of the tools? Especially for OpenOCD, we fixed several issues related to programming since the Founders Editions boards came out.

- If you just reset your board (just hit the button once) and then reprogram it, do you still have the issue? Or you really must use the “safe” loader?

- I’m wondering if the -DNO\_INIT flag was applied, as that will mean your board is running at ~16MHz instead of 260MHz when you try to reprogram it. Can you try applying the -DNO\_INIT flag and then look at the output of “hello” as you did before? You should NOT see the “core freq” message.

---

<div class="post-metadata">

**Author:** ![brucehoult](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/brucehoult/32/24_2.png) [@brucehoult](https://forums.sifive.com/u/brucehoult)\
**Post date:** [February 27, 2017, 5:19pm UTC](https://forums.sifive.com/t/not-able-to-upload-programs-expect-in-safe-boot-mode/362/9 "2017-02-27T17:19:51Z")

</div>

I tried that and saw “hello world!” without core freq header … once … and then when I reset the board I saw nothing. What serial settings do you get with -DNO\_INIT ?

---

<div class="post-metadata">

**Author:** ![mwachs5](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/mwachs5/32/13_2.png) [@mwachs5](https://forums.sifive.com/u/mwachs5)\
**Post date:** [February 27, 2017, 5:22pm UTC](https://forums.sifive.com/t/not-able-to-upload-programs-expect-in-safe-boot-mode/362/10 "2017-02-27T17:22:05Z")

</div>

Good point. I need to double check that it would still work.

---

<div class="post-metadata">

**Author:** ![mwachs5](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/mwachs5/32/13_2.png) [@mwachs5](https://forums.sifive.com/u/mwachs5)\
**Post date:** [February 27, 2017, 6:09pm UTC](https://forums.sifive.com/t/not-able-to-upload-programs-expect-in-safe-boot-mode/362/11 "2017-02-27T18:09:50Z")

</div>

Ah, @brucehoult you’re right. If you add the -DNO\_INIT flag, the uart\_init() doesn’t get called. The message prints the first time because the settings are still set from your previously running code, but once you hit reset they get wiped out and aren’t restored.

But, I remembered that the `led_fade` demo actually sets the clock source back to the 16Mhz crystal and configures the UART itself. So @nonerkao can you reprogram without safe boot mode if the previous program was ‘led\_fade’:

```auto
make software upload PROGRAM=led_fade
(hit reset button just once)
make software upload PROGRAM=led_fade

```

---

<div class="post-metadata">

**Author:** ![nonerkao](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/nonerkao/32/194_2.png) [@nonerkao](https://forums.sifive.com/u/nonerkao)\
**Post date:** [February 28, 2017, 5:04am UTC](https://forums.sifive.com/t/not-able-to-upload-programs-expect-in-safe-boot-mode/362/12 "2017-02-28T05:04:23Z")

</div>

> If you’re willing, could you try a few more things:

> 

> - Can you make sure you have the latest versions of the tools? Especially for OpenOCD, we fixed several issues related to programming since the Founders Editions boards came out.

Yes, I got stuck on this problem right after I updated the whole SDK.

> - If you just reset your board (just hit the button once) and then reprogram it, do you still have the issue? Or you really must use the “safe” loader?

Both yes. The issue remains when simply resetting it. The safe loader is required.  
But according to @brucehoult 's suggestion, using Arduino IDE with correct setup can somehow bypass the situation “sometimes”. I mean, a re-upload of those samples has roughly 50% chance to success.

> - I’m wondering if the -DNO\_INIT flag was applied, as that will mean your board is running at ~16MHz instead of 260MHz when you try to reprogram it. Can you try applying the -DNO\_INIT flag and then look at the output of “hello” as you did before? You should NOT see the “core freq” message.

The flag was not applied to the makefile of `hello`. After correctly apply the flag to both `hello` and `led_fade`, something interesting happens!  
I found that after a successful upload, the next try must fail; after the fail, the next upload successes, for both sample program in any sequence.

I hope the information helps.

> So @nonerkao can you reprogram without safe boot mode if the previous program was ‘led\_fade’:  
> make software upload PROGRAM=led\_fade  
> (hit reset button just once)  
> make software upload PROGRAM=led\_fade

The behavior of the board follows the rules I described above. Exact one of the consecutive uploads successes, no matter when to insert the reset.

Thanks for helping me for this. At least now I can reprogram it without the safe boot, just need a additional upload.
