Hearing any abnormal noise while you drive is stressful. With so many moving parts making up your car, it can be nearly impossible to tell where that humming, whining, or whirring noise is coming from. A common issue that many drivers run into is a failing wheel bearing, which can present in a variety of ways. While many potential issues can cause an unusual noise while you drive, a bad wheel bearing is one possibility.

Although module linking and relocation share some features (filling in addresses we didn't know or which might have changed), they are quite different problems.

Most of the current systems are based on GNU's tools in one way or another, and even in its early days porting GCC could be tricky if your architecture didn't match. Thsi is a large set of programs, designed to construct large programs efficiently. Specifically it doesn't not have simplicity as one of its primary goals.

Having a similar system on embedded would be great. I could provide things like board support code and drivers in a bootloader. The application code could then be dynamically loaded and call these functions. The application would thus not need to be so closely coupled to hardware. This could have the positive devOps effect of keeping board-level differences and application changes nicely separated. Think N+M versions instead of N*M, where N and M are variations in hardware and application respectively. Such a solution could also reduce repeated code between the bootloader (which must stand alone) and the application (which needn't). E.g. the application could ask the bootloader to call printf.

Or worse, when a bad RTOS-based design kills someone because a critical thread quits running: https://www.autosafety.org/wp-content/uploads/import/Bookout%20PDF.pdf

Wheel bearings are a set of steel balls contained in a lubricated metal ring located in the hub. They support the weight of your vehicle and allow the wheels to rotate freely while you drive. In normal conditions, the bearing accomplishes this without making any excessive noise. If the grease lubricant escapes the bearing or debris as water or sand enters it, the bearing will wear out and fail quickly.

All of the following is just a sketch of a possible system based on how to get rid of "updating of addresses" (conventional linking) with "finding my modules".

Difference between staticloadanddynamic loadPDF

If I haven't convinced you otherwise, and still want to dynamically load modules as needed (that is, your system is ‘modal’), consider the kinds of bugs that can occur and how to approach them, not just in your design, but in your QA process as well.

Image

What is a staticload

Just to provide some explanation why dynamic-anything is usually frowned upon in embedded systems: it is because they are usually much higher integrity systems than your average Linux one.

So for instance you would say that at 0x1000 you will find the address of "printf", at 0x1002 the address of "set_io_high", at 0x1004 the address of "set_io_low", etc. You would need an information somewhere about the number of available calls or the version of the table, so you don't try to call functions which aren't available.

How much pain am I looking at if I want to replicate the basic features of ld.so on an embedded system? Those basic features being:

To have dynamic loading your first need to have loading... Many embedded platforms run the code directly from flash or ROM, they do not load the code in RAM to execute it.

It was common for a base system to search all of address space for a magic number for identifying its expansion ROMs. Much better is some defined way to add them in.

tl; dr: Yes, it's possible, but with great flexibility comes great responsibility to ensure your system remains reliable. In a constrained platform like yours it probably isn't worth it. Better to constrain the desired flexibility in a sandbox that can't kill the rest of your system.

Staticloadvsdynamic load

Let's imagine you completely eliminate relocation, by writing or getting your compiler to produce position-independent code. Thus each module can be put anywhere in memory and still function without any relocation. (Article about PIC on ARM)

Staticloadvsdynamic loadbearing

We can borrow from the early microcomputer days, where additional features were often sold as expansion ROMs. One of the best examples of this was Motorola's 6839 Floating Point "Unit", which is exactly the kind of library module we might want to update.

Many smaller RTOSs support dynamic modules. But given that memory is cheap while for-pay RTOSs cost, well, money, it’s no wonder that folks opt for Linux, BSD and other free-as-in-speech alternatives and pay a bit more for hardware that can run them.

If you can get hold of one of ARM's software interrupts you can generate a run-time linking mechanism which is pretty general and reduces the per-module overhead, but a lot of the detail depends on other issues.

For scenarios where you do want to change the code for whatever reason, different versions/builds of the code are handled with version control - hence the name. Resulting in one single binary executable. Then you just flash the whole MCU at once using single-wire interfaces such as SWD/JTAG. No need for icky, error-prone bootloaders that realistically will also require you to include a lot of checksums in the binary.

One way to approach this is to rewind to how we did things before it was routine for computers to have memory-management units and many megabytes of memory. There are four principal issues with the conventional dynamic linking-loader: 1) Relocation, 2) Linking of modules, 3) Potential sharing of modules, 4) Engineering.

A lot of the time, your car may not feel any different when the bearing is making noise. It’s easy to overlook or put off an issue that is not directly impacting your daily driving.

Not swapping out the code has the big advantage that all tests of code coverage, coding standards, static analysis, code review and so on need not get carried out over and over. Instead you can design tests covering all possible (and impossible) combinations of data sets.

When in doubt, bring your car to a technician. When it comes to wheel bearings, it’s better to be safe than sorry. If you aren’t sure whether the sound you are hearing is a bad wheel bearing, the technicians at Matson Point S will take a look and let you know exactly what is wrong with your car. Give us a call or schedule an appointment at our Riverton, Utah location today!

Motorola published a boot ROM with a monitor program, ASSIST09, which looked for an extension in this exact way; it also provided basic BIOS calls such as INCH and OUTCH (input/output a character) which were executed by a software interrupt followed by a function ID, pretty much the way systems calls were always done. (See Motorola's 6809 Programming Manual, Appendix B for description and listing.)

Remember, a bad bearing will make the same noises no matter what road surface you are on. If you hear a noise that changes when you get on a more smooth or more rough road, you might be hearing tire noise.

When the bearing fails and comes apart, it will cause play in the wheel. This can lead to severe instability when driving at high speeds and can come on suddenly if the bearing completely fails while you drive.

The problem of having different configurations for such systems are typically never solved by swapping out the executable code, but instead by providing different data sets (for example programmed in data flash/eeprom).

Loaddynamics

We could either a) always find our necessary modules and load them with the program, or b) have some kind of shared-across-all programs mechanism.

The brake discs on your car are part of the rotating assembly connected to the hub and wheel bearing. When your wheel bearing has failed to the point of lateral play, the disc will no longer be aligned correctly. This means when you press the pedal, it may feel soft and take longer for your car to stop.

Which brings up something else to think about. A new language, Rust, avoids many memory bugs that creep in to typical C/C++ based platforms. One major plus: Rust doesn’t use garbage collection. More here: https://doc.rust-lang.org/book/ch00-00-introduction.html

That being said, when you are moving, the sound will not cut in or out. If you only hear a noise when you are accelerating, decelerating, or braking, there may be another drivetrain issue.

The motivation for dynamic loading has as much to do with managing limited RAM memory resources as it does with being able to configure your run-time per platform. Otherwise, why bother? For a very small platform without an RTOS (or even with one), you just build your image with the modules you need and be done with it. While this seems unwieldy, in reality it better contains the QA problem when you have a known, tested 'golden image' that has gone through a proper software QA process. Any memory leaks, deadlocks, or other issues will have hopefully been flushed out prior to dropping the image.

I'm not sure that EE.SE is the best place for this, but it's a very interesting topic much more applicable to board-level designers than software engineers in general.

It's a ROM containing position independent code for the 6809, an 8-bit processor from the 1980s with 16-bit addresses. The ROM has a fixed jump-table at the beginning for the functions.

Some embedded platforms already have similar mechanisms for some features, like the "softdevices" on the Nordic nRF5 platform which provide some of the wireless functionality and can be updated independently from the rest of the application code.

Say you grow your system to having a full-featured OS with a file system, dynamic loading and other support. This enhances flexibility, but it also comes with downsides such as garbage collection (if you allow it - it would be a definite no-no with an RTOS expected to meet hard deadlines) and other problems like memory leaks.

If I was to do this, I certainly wouldn't start with current ld.so, though that is of course possible. I know of nothing readily available for what you're describing, but am thinking about what would be necessary to build a minimal one, if coding near bare metal.

The short answer is no. You should not drive your vehicle if you believe you have bad wheel bearing. The long answer is yes, but with the understanding that driving with a failed or failing wheel bearing can lead to serious safety issues as well as severe damage to your car.

What isdynamicloading in structures

If I understand your need, a simple way to do this would be for the "bootloader" to include all these functions you want with a platform-independent interface (API). Then you have a table at a fixed location in that bootloader with the addresses of all those functions, and in your code, you just call the function through that pointer.

Being part of the hub assembly, noise caused by a bad wheel bearing will only occur when you are moving. The sound may increase or decrease when you pick up speed or go around a turn. Paying attention to changes in noise or volume when going around corners. These changes can give insight into which side has gone failed. A bad wheel bearing can make any of the following noises depending on the cause or severity of the failure:

Alternatively, you could have a single fixed address of a function to call, and in the arguments to that function there would be the number of the function.

I'm imagining some structures along these lines, though the details would depend a lot on the your memory layout and what kind of run-time error reporting is possible.

If the noise you are hearing continues when you come to a stop, it is likely not caused by a bad wheel bearing. To produce noise, the wheels of your car need to be rotating.

Dynamic loadexamples

Some experiential context: The majority of my professional coding is on either baremetal or RTOS embedded systems, while most of my teaching has to do with Linux hosted code. One thing I deeply miss when on an embedded system is a dynamic loader, i.e. ld.so.

Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Dynamic loadformula

Does such a system already exist in the wild? Would it be too unreasonable to try and port the real ld.so to do this? My intuition is that this idea is right on the border between being useful and too difficult to be worth it.

Note however that it is probably not a good idea to include so much stuff in the bootloader itself. You want the bootloader to be as simple and small as possible (less risks for bugs and ending up with a bricked device), and require the least possible updates. So it would probably be more bootloader -> additional layer -> application.

But really, in the case of embedded, there are so many other things which require separate builds anyway (processor type/architecture, flash/ROM/RAM/SPI RAM/etc, addresses...) that I think it's more likely you need to address this on the build side of things than on the device itself. Even devices in the same family often require separate builds.

Problems like these even come up with commercial embedded RTOSs, such as the Pathfinder Mars Rover running VxWorks (a well-regarded, but expensive commercial RTOS) that became unresponsive due to an out-of-memory bug: https://www.computerworld.com/article/2574759/out-of-memory-problem-caused-mars-rover-s-glitch.html

This is an extreme case, but if you drive on a bad wheel bearing for long enough, the wheel could come off. If this were to happen on the freeway or at high speeds, it could be catastrophic for you, your car, and other drivers.

What you are talking about seems to rather be either a BIOS, an OS, system calls, a hardware abstraction layer, drivers or even a standard library (or a combination of the above).

Obviously, it's non-trivial. Whether it's difficult depends on how many other things you need to interface to, how much control you have over the libraries, how easy it is for your organisation to maintain the ABI -- all those module IDs, all those function IDs -- and how the modules get from flash to RAM.