SSW logo Blog - Michael's Musings

Wed, 03 Feb 2016

How to Flash OpenWSN to OpenMote with SEGGER JLink

I have an OpenMote device. One I bought prior to July 2014, so it's got a bootloader that won't let you install via serial UART, so it has to be JTAG'ed in, and in any case, you might toast yourself and have to start over, or you might want GDB.

First, my setup. It's not a windows laptop with a USB cable. That would be... cramped and really inefficient to work with.

I have a desktop, it's called obiwan. It does Linux desktop things like run multiple monitors, play music and keep browsers going. And does it without fan noise, and I like that a lot.

I have a build server, it's called herring. It has lots of cross-compilers installed, three-way RAID mirror (because: consumer grade disks suck), and it's in the other room where it can make as much noise as it wants, and it does NFS to the other machines.

I have a table/desk full of stuff, with a small form factor (fanless) PIII running

Devone, with two USB hubs connected. It's called "lando". (Stupid muse/pybloxsom has no idea how to set width= on images)

SOHO IoT/6tisch/ROLL lab
SOHO IoT/6tisch/ROLL lab

The old 10/100 8-port switch screwed up in the picture was the original idea, but dammit, I ran out of ports, and so the old Dell 24-port 10/100 is there too, with a fan making noise and pissing me off.

It turns out the RPI model Bs have PHYs that just don't do the MII dance correctly with more modern PHYs when driven by uBoot, so the RPI are still plugged into the 15 year old 10/100 switch.

I installed the SEGGER software on lando, as it's got the USB cable to the JLink. I extracted the 6tisch Golden image, which can be found from the page:

https://github.com/openwsn-berkeley/openwsn-fw/releases/tag/GD_REL-1.2.0

as the Download links marked "source code" at the bottom of the page:

https://github.com/openwsn-berkeley/openwsn-fw/archive/GD_REL-1.2.0.tar.gz

I extracted this on my build server, because that's where my arm GDB is installed:

herring-[projects/pandora/openmote/images-GD_REL-1.2.0] mcr 1003 %ls -lta
total 1556
drwxr-xr-x 4 mcr mcr   4096 Feb  3 12:22 ../
drwxr-xr-x 2 mcr mcr   4096 Jan 28 11:21 ./
-rw-r--r-- 1 mcr mcr 524256 Jan 28 11:21 GD_ROOT.bin
-rw-r--r-- 1 mcr mcr 524256 Jan 28 11:21 GD_ROOT_SEC.bin
-rw-r--r-- 1 mcr mcr 524256 Jan 28 11:21 GD_SNIFFER.bin

On lando I started JLinkGDBServer:

lando-[~] mcr 10001 %sudo /opt/SEGGER/JLink/JLinkGDBServer -device CC2538SF53
[sudo] password for mcr:
SEGGER J-Link GDB Server V5.10j Command Line Version

JLinkARM.dll V5.10j (DLL compiled Feb  2 2016 19:31:34)

-----GDB Server start settings-----
GDBInit file:                  none
GDB Server Listening port:     2331
SWO raw output listening port: 2332
Terminal I/O port:             2333
Accept remote connection:      yes
Generate logfile:              off
Verify download:               off
Init regs on start:            off
Silent mode:                   off
Single run mode:               off
Target connection timeout:     0 ms
------J-Link related settings------
J-Link Host interface:         USB
J-Link script:                 none
J-Link settings file:          none
------Target related settings------
Target device:                 CC2538SF53
Target interface:              JTAG
Target interface speed:        1000kHz
Target endian:                 little

Connecting to J-Link...
J-Link is connected.
Firmware: J-Link V9 compiled Feb  2 2016 18:43:46
Hardware: V9.30
S/N: 269305618
OEM: SEGGER-EDU
Feature(s): FlashBP, GDB
Checking target voltage...
Target voltage: 3.31 V
Listening on TCP/IP port 2331
Connecting to target...
J-Link found 2 JTAG devices, Total IRLen = 10
JTAG ID: 0x4BA00477 (Cortex-M3)
Connected to target
Waiting for GDB connection...

Then on herring I started the GDB, as explained at:

http://www.openmote.com/blog/getting-started-with-contiki-and-openmote.html

I thought to load the GD_ROOT.bin directly using:

(gdb) restore GD_ROOT.bin binary 0x200000
Restoring binary file GD_ROOT.bin into memory (0x200000 to 0x27ffe0)

but this didn't work, so I followed the instructions to create hello-world. my copy of which is at:

http://www.sandelman.ca/SSW/contiki/openmote/hello-world-3.0-20160203.elf

(gdb) target remote lando:2331
Remote debugging using lando:2331
warning: Architecture rejected target-supplied description
0x00216752 in ?? ()
(gdb) monitor interface jtag
Select JTAG as target interface
(gdb) monitor speed 5000
Target interface speed set to 5000 kHz
(gdb) monitor endian little
Target endianess set to "little endian"
(gdb) monitor flash download = 1
Flash download enabled
(gdb) monitor flash breakpoints = 1
Flash breakpoints enabled
(gdb) monitor reset
Resetting target
(gdb) load /corp/projects/contiki/contiki-3.0/examples/hello-world/hello-world.elf
Loading section .text, size 0xab53 lma 0x200000
Loading section .data, size 0x1be lma 0x20ab54
Loading section .ARM.exidx, size 0x10 lma 0x20ad14
Loading section .flashcca, size 0x2c lma 0x27ffd4
Start address 0x200000, load size 44365
Transfer rate: 1883 KB/sec, 7394 bytes/write.

This is what my J-Link said:

Firmware: J-Link V9 compiled Feb  2 2016 18:43:46
Hardware: V9.30
S/N: 269305618
OEM: SEGGER-EDU
Feature(s): FlashBP, GDB
Checking target voltage...
Target voltage: 3.31 V
Listening on TCP/IP port 2331
Connecting to target...
J-Link found 2 JTAG devices, Total IRLen = 10
JTAG ID: 0x4BA00477 (Cortex-M3)
Connected to target
Waiting for GDB connection...Connected to 172.30.2.231
Reading all registers
Read 4 bytes @ address 0x00216752 (Data = 0xBF204770)
Select JTAG as target interface
Target interface speed set to 5000 kHz
Target endianess set to "little endian"
Flash download enabled
Flash breakpoints enabled
Resetting target
Downloading 16112 bytes @ address 0x00200000
Downloading 16048 bytes @ address 0x00203EF0
Downloading 11699 bytes @ address 0x00207DA0
Downloading 446 bytes @ address 0x0020AB54
Downloading 16 bytes @ address 0x0020AD14
Downloading 44 bytes @ address 0x0027FFD4
Writing register (PC = 0x00200000)
Reading register (XPSR = 0x01000000)

The reset button on my unit seems broken, but you can do the same with the JTAG interface with "monitor reset", and I get:

Contiki-2.6-2325-g7df05ce
TI SmartRF06 + cc2538EM
Net: sicslowpan
MAC: CSMA
RDC: Contiki MAC
Rime configured with address 00:12:4b:00:03:a5:70:05
Hello, world

using minicom on the ttyUSB3 (my situation) at 115200 baud on my lando machine. With the JTAG attached I can probably work on the device entirely remotely.

Wed, 27 Jan 2016

PostgresQL Foreign data wrappers and rails

Rails' discovers available tables and the attributes of those tables when it starts. It has no problems with views, but it turns out that foreign data wrappers do not turn up in that list, and so if one of your tables is really a foreign data wrapper (fdw), rails just doesn't believe it exists.

I was using the mysql_fdw to merge the customer lists of a CRM, a ticket system and the SG1 management application. The CRM uses MySQL (only!) while our preferred database is PostgreSQL; mysql_fdw makes them all see a few tables in common, but the the auto-discovery did not like it in staging.

Solution: add a layer of indirection! Move the original fdw into a schema, and then:

CREATE OR REPLACE VIEW public.crm_accounts AS (SELECT * FROM suitecrm.crm_accounts);

and lo-and-behold! it all works as expected.

Tue, 26 Jan 2016

Setting pepper in staging/production

The devise authentication plug for rails has been a standard piece of instructure for me for years. One of those things you should not roll on your own. https://github.com/plataformatec/devise

In setting up the staging system for the IP4B SG2 system, I wanted to be able to copy bits of the production database to the staging system so that we can see real data. Logins were not working, and I was mystified until I realized that the pepper values in the config/initializers/devise.rb were different as I upgraded the devise, and started with a new file. I had set a longer pepper in the new revision, probably too long actually as it might prevent the per-user salt from having any effect.

I then realized that I don't want this pepper value into the git tree it all, it should be set by the production.rb, or better the secrets.yml. I didn't find a clear way to do this, so I had to Use The Source, Luke (curiously, in the Percy Jackson novels, Luke is a bad guy)

I used bundle show devise to tell me where devise was installed, and then I went into that directory with Emacs, and used grep -R for "pepper". I was also looking for where the Device.setup routine is and how it sets up the config. A clue was in test/models_test.rb, where I found:

    test 'set a default value for pepper' do
      assert_equal 'abcdef', Configurable.pepper
    end

Hmm, what is the Configurable thing? Naw, it's in test/test_models.rb, so it's just for the test cases. The real meat is in lib/devise. I leant from test_models.rb that I can specify the pepper: in the devise model, so if I have to I can put it together in my app.

I decided to grep for secrets:

grep -R -nH -e secrets *
rails.rb:33:      if app.respond_to?(:secrets)
rails.rb:34:        Devise.secret_key ||= app.secrets.secret_key_base

Which is nice, as it points to the secret_key_base, which I knew I had to initialize, but that is used for the cookies. I don't need to synchronize the cookies between staging and production. I was hoping to put the pepper into the secrets.yml.

Looking at this, it seems that I ought to be able to add pepper to this, so I tried:

module Devise
  class Engine < ::Rails::Engine
    initializer "devise.pepper" do |app|
      if app.respond_to?(:secrets)
        Devise.pepper ||= app.secrets.pepper
        puts "APP has new pepper: #{Devise.pepper}\n"
      end
    end
  end
end

I monkey patched this into my user.rb file, before I create the User. (I could fork and make a pull request on this, but I'll do that after I'm sure this is the right way) I wondered what app was, I suspect it comes from the ::Rails::Engine.

I stuffed my secrets.yml on my desktop with:

development:
  secret_key_base: mysecret
  pepper: "happyhappyjoyjoy"

and invoked rails console. Good news it didn't blow up yet! I dumped the pepper:

2.1.5 :001 > Devise.pepper
 => "42e1d47ee85f2bb825429384729345234935924310c651bcdb822a65919d8b4"
Well, that's not the pepper I set. I went and I removed it from config/initializers/devise.rb, and restarted rails console.
2.1.5 :001 > Devise.pepper
 => nil

Okay, so there is a change... but it didn't load my monkey patch yet. Maybe if I make it load that code:

2.1.5 :002 > User.first
...
2.1.5 :003 > Devise.pepper
 => nil

nope. So let's see if my idea was even sound. I stuffed the initializer code into the lib/devise/rails.rb in my local gem repo, and low and behold, it ran:

obiwan-[nv/clientportaltest/beaumont](2.1.5) mcr 10027 %rails console
APP has new pepper: happyhappyjoyjoy
Loading development environment (Rails 4.2.5)

Conclusion: I monkey patched too late. I put the same code at the top of config/initializers/devise.rb. Too late. How about at the end of config/application.rb? Yes. that worked.

I'm not too thrilled by this, I think it ought to go elsewhere, but one step forward at a time.

Tue, 19 Jan 2016

Libreoffice 5

After updating my desktop to http://devuan.org, ascii, from Debian Wheezy, I have Libreoffice 5. It's sure pretty.

But, the file dialogs are still broken if you have NFS or SSHFS: they want to walk the file system and get stuck on slow remote servers.

Sat, 19 Dec 2015

Non-Review of Star Wars VII

When starting to write this blog entry, my blog workflow would ask me which of the 20 odd categories I want to put this in. I saw "defectivebydesign" and thought, "haha, that's a good place". Previously, this category has included reviews of: Amazon Users Tag, Canadian Blood Services, DomainsAtCost and the Huawei 1250.

Star Wars VII was fun. Good use of 3D, although I think that the Millenium Falcon chase seen on the desert planet (what was it's name?) could have used more in-cockfit 3D, with Rae's hands in the field of view, like a first-person shooter. Definitely, the later on Rae/Finn gun sequence should have totally been first-person-shooter... That is, they should have actually picked a well-known first-person-shooter (in a space ship, of course, maybe Lego Star Wars..) and made it exactly the same icons, etc.

Female-Yoda-With-Glasses. Okay. But why did they go there? Who is she? They should have at least had a small conversation about that.

Why did they have to have the same band as in the Mos Eisley Cantina? That part was simply LAME. It was at that point that I said... well... this has made a turn for the worse.... and really it never recovered in my opinion.

Planet Killer. Yup. We know from the books that the two Death Stars were not prototypes, that there was more super-weapons hidden away, and we know that there is a Hyperspace Planet Killer in a Correllian moon that Anakin Solo (Han and Leia's third child in the books) could operate, and did operate by mistake. Takes genetics (thanks to Han's strange past in the aristocracy) and use of the Force... So that part seems Canon to me. It would have been more interesting if they had actually had Ben Solo (Kylo Ren) operate and/or aim it.... it would have made the character far a more interesting part of the First Order. Otherwise, it's not clear why Ben Solo is needed at all. Aiming a gun that kills things faster than light can travel would be hard... that's where the force comes in.

Oh, and while it can shoot through hyperspace, and so kill planets faster than light, I see no reason why it should kill multiple planets with a single shot. But, even if it did.... those planets would NOT SEE each other blow up.

As for Kylo Ren; he's clearly not dead, but I'd have liked them to have made that slightly more clear. The planet could have blown up slightly less completely.

Wed, 16 Dec 2015

Westgate Mall renovations

I went to the Westgate Reconstruction "meeting" shortly after 6pm on Dec. 16.

It was in the basement of the Macy Hotel in a smallish meeting room. It was not a presentation, but rather a poster-board meeting modelled after the worst methods of the city of Ottawa. I THOUGHT we were done with having such a stupid meeting format, but then I realized that this wasn't a city meeting at all.

There is a time and place for a well done PowerPoint presentation followed by an open mic and questions from the floor, and this is actually one of them.

If you missed it, you missed nothing. The posters are all online at:

http://www.cbc.ca/news/canada/ottawa/westgate-shopping-centre-development-riocan-1.3368082 and http://rileybrockington.ca/wp-content/uploads/2015/12/Westgate-Rio-Can-Proposal.pdf

There was really nothing that isn't in these pictures, except a few ridiculous claims on two posters which aren't that in that deck.

  1. that the development will be sustainable.
  2. that the development will be a transit node.
  3. The "Transportation Considerations", which failed to mention walking or cycling, and whose only mention of transit is that the developer thinks the city might build LRT on Carling. (If only the city was that clueful)

The plan is basically:

  1. in ~5 years: knock down Monkey Joe's, put up a tower.
  2. a few years later: knock down Shopper's Drug Mart end of mall, put up another tower.
  3. a few years later: do something with the rest of the mall, and add greenspace.

I skipped out after ten minutes, there weren't enough Rio-Can people there. My friend and neighbour Sharon Body said that there might be a "talk" at some point, but I took off to Rockin' Johnny's for a hotdog. Just before leaving, I checked google maps to see if I could catch a 151 home. Only 1x 151 per hour goes through Westgate now, and low and behold, at 7:08pm I could catch the bus, and it was just short of 7pm now. I went outside, and caught the 151. It seemed early, beacuse, well... it was. It was the 151 that goes in the other direction at 7:04pm, I realized this after we got to Kirkwood and turned the wrong way. I walked home, as it was faster than waiting another 5 minutes. (It's not a long walk anyway)

Why do I mention the 151? Because the real problem that westgate and the community has is that between OC-Transpo and Rio-Can they have basically written off all transit use at and through Westgate. It COULD be a significant TRANSFER hub if the mall and OC-Transpo would pay attention to it. It has the 101, the 151, the 176 and the 85 there. But, it's all mis-designed, the shelters are in the wrong places, and the buses simply do not connect.

Were I trying to make Westgate more valuable, I'd want to massively increase the pedestrian traffic in and out. That would involve some kind of walkway between Westgate and Hampton park. I'd prefer an at-grade tunnel under the 417, but some might feel that could be hard to keep secure. I'd go for a third storey walkway over it, but that won't be easily useable by cyclists. We could work something out though, I think, if we had a decent meeting.

Towards 14 Internet Exchanges

Why 14?

One in Ottawa/Gatineau for the Federal Government. It mostly exists already in the form of the Federal Gigapop.

http://www.gigafed.net/

There are 10 provinces. Ontario already has Torix at 151 Front Street. Quebec already has CANIX-1 at 625 Rene Levesque.

http://www.cybera.ca/projects/alberta-internet-exchange

Configuring Apache/FastCGI with Catalyst

I found a number of description of how to configure things, such as at:

http://search.cpan.org/~mramberg/Catalyst-Runtime-5.80012/lib/Catalyst/Engine/FastCGI.pm

the problem is that they are wrong. What occurs if you do this is that the thing you re-direct (usually, "/") gets sent through, but other longer URLs do not.

Some highlights of pictures from 2007

http://www.sandelman.ca/lrmr/photos/2007-09/img_4628-9-0.html http://www.sandelman.ca/lrmr/photos/2007-09/img_4638-9-0.html

In our house, a lot of trains are built. Many are operated by cookie monster.

The result, however, is usually disaster:

http://www.sandelman.ca/lrmr/photos/2007-09/img_4631-9-0.html

http://www.sandelman.ca/lrmr/photos/2007-08/img_4418-8-0.html

Oh, and Diesel is evil:

http://www.sandelman.ca/lrmr/photos/2007-04/img_3961-4-0.html

I made this:

http://www.sandelman.ca/lrmr/photos/2007-05/img_4044-5-0.html

and again, the next weekend, for the second party:

http://www.sandelman.ca/lrmr/photos/2007-05/img_4094-5-0.html

http://www.sandelman.ca/lrmr/photos/2007-05/img_4049-5-0.html

No trains at all:

http://www.sandelman.ca/lrmr/photos/2007-03/img_3838-3-0.html

web_site_is_back_online

web site is back online

Trying out GNU Emacs 23

For at least the last 15 years I have been an Xemacs user. You can read elsewhere about the great GNU vs Xemacs split... I was solidly on the X/Lucid Emacs side of things. But, Xemacs gets no attention, and although it does 97% of what I want, I decided to try out the extra 3%.

For the past week I've been running GNU Emacs 23 at CREDIL. I still login to my desktop at home to run gnuclient -nw, to get access to the Xemacs running there, the one that has my email in it. Once I'm happy with GNU Emacs 23 here, I guess I will try it at home.

GNU Emacs has a bunch of Xemacs upgrade facilities... it reads and understands most of my .xemacs custom stuff, and it seems to update that stuff too, having adopted that entire subsystem.

GNU Emacs had a bunch of git integration, which while it seems like a smart thing, seems to an awful lot of file I/O operations, and worse, invokes git diff and bunch of things. This is a problem if your source tree happens to be over sshfs. I've turned some of it off, but there are more things which it seems to do... maybe a statfs to determine if the directory is remote and turn that stuff off by default would be wise.

I can not convince MUSE mode to accept the changes that I did a few months ago when I moved my bloxsom blog from a CGI to a static site, until I do that, this entry won't get published.

; INVALID LISP CODE

Date: Tue, 24 Feb 2009 10:21:19 -0500

From: Norbert Winklareth <norbert.winklareth@agilerenaissance.com> User-Agent: Thunderbird 2.0.0.19 (Windows/20081209) To: codingdojo@strangeware.ca Subject: [Codingdojo] Mini-book review of "Chasing the Rabbit" Reply-To: codingdojo@strangeware.ca Sender: codingdojo-bounces@strangeware.ca

[1. text/plain] Hi,

I have finished Steven Spear's book "Chasing the Rabbit" and it is very good and I recommend it to anyone interested in how to make a group/organization effective. Spear is a principle-ist, someone who looks for the fundamental underlying principles, and he has both created a theory of set of underlying principles for high-velocity organizations, his terminology, and taught some organizations to use it to become high-velocity, thereby validating the theory as being more then just an academic model. Essentially, he found that all of these high-velocity are effective learning/doing or knowledge based organizations. He then created a theory that to have a sustaining knowledge-based organization requires a minimum of following 4 principles. The note below by Tom Poppendieck summarizes the book and the principles quite nicely. Note that the principles have been followed successfully by Web Development company, hospitals and doctors and so on. I don't think his theory can be simplified, nor do I think that it needs more principles, so it represents at this time, in my opinion, it is the best underlying theory of what is needed to create and sustain a knowledge based organization.

—&—


Forwarded message ———- From: Tom Poppendieck <tom@poppendieck.com> Date: Sat, Feb 21, 2009 at 1:30 PM Subject: [leandevelopment] Chasing the Rabbit To: leandevelopment@yahoogroups.com

I highly recommend a new book from Steven Spear called Chasing the Rabbit. Spear is with the Harvard Business School and has collaborated with Clayton Christianson and others. Spear spent a decade studying high velocity organizations (including Toyota and many others in other domains) and discovered they all exhibited 4 capabilities.

1) They all are skilled at designing work processes that incorporate both the best knowledge available in the organization and that incorporate tests to ensure that they can immediately recognize when their knowledge is incomplete.

2) Whenever a test reveals a problem, they immediately swarm on the issue close in time and space to its occurrence while the most information about it is still available to understand where their knowledge was incomplete and to fix the problem by improving their work design.

3) Whenever a team learns a better way, it has both means and responsibility to make that knowledge available across the rest of the organization.

4) All levels of the organizations management are responsible for and capable of making sure 1, 2, and 3 happen through ongoing training and hands-on coaching. Leaders focus on improving their teams work design, problem solving, and communication capabilities more than on the actual work output itself.

Spear observed that work design in high velocity organizations always seems to have 4 components.

1) Really understand the required output from the work. This includes tests to verify that the output meets the targeted need.

2) Identify a collection of steps or actions that will lead to the desired output. This is where expertise and organizational experience and knowledge apply.

3) Define the connections among the steps, how the actions flow or fit together and deal with handovers and/or collaboration required.

4) Select the best available methods to execute each activity in the workflow.

Spears observed that high velocity organizations applied these four characteristics and four steps in work design at all levels and scales from small tasks to entire organizational units and supply chains.

My take on this is twofold. First, for manufacturing or operations work, this leads to relentless improvement of standard work. Each team has a standard method they use to do every task until they learn something that leads to a better sequence of steps or better methods at which time they update their standard work. Those parts of software development that fall into this category usually can and should be automated.

Second, for development work, the challenging part is not the execution of the work but instead designing a work process that leads to the desired result. Each iteration targets a new output and requires a tailored set of activities to achieve the targeted output. While a development team will have a set of practices, disciplines, patterns, standards, and methods (which they should strive to constantly improve), the core of the design process is to select the set to be applied in the current iteration and to ensure the interactions and connections needed occur effectively.

- Tom

—&—

Regards Norbert


Norbert Winklareth Agile Renaissance

_______________________________________________ Codingdojo mailing list Codingdojo@strangeware.ca http://lists.strangeware.ca/mailman/listinfo/codingdojo