Why do I call this a “so-called legend”? Because it was never a traditional folk belief until the twentieth century, when stories from Chinese pulp novels became accepted as fact. The original Shaolin legend about the origin of their martial arts involves a cook at the temple who used his staff to drive off bandits, then revealed his real identity as a Buddhist deity. I am a big believer in respecting the mythic and the legendary, but the legend about the cook is the original “Shaolin legend,” and the story about Bodhidharma is not.
As for historical fact- which is not superior to myth, but also should never be confused with it- this is what serious scholars of Chinese martial arts history currently think:
The Shaolin Temple, like a lot of other Buddhist temples, did maintain an armed militia to protect its landholdings from bandits and roving armies. Because a lot of military men retired to the temple, there were trained professionals available to teach the “soldier monks.” Because they were reasonably well-trained by the standards of that era, they were effective soldiers. As a result, the Chinese government called on them on several occasions to help fight rebels, pirates or bandits.
The soldier monks were mostly known for staff fighting, but at some point in the 17th century they also started to practice bare-handed pugilism. Boxing with your fists is not a battlefield skill, so this practice was more of a health/wellness exercise than a fighting art as such, unlike their staff combat.
The Shaolin Temple was something of a center for the development of Chan, the Chinese word for Zen. Bodhidharma, if he really existed, might have gone there. He didn't teach martial arts to anybody, and the Shaolin monks didn't start practicing martial arts till long after his time.
Despite this fact, it is the case that some of the later soldier monks viewed their martial arts training as a path to Chan cultivation. This is consistent with Zen's overall approach, which tends to use any activity in the practitioner's daily life as an opportunity for Zen practice. Modern Zen practitioners are told to use daily chores such as washing the dishes as opportunities for cultivation. To a soldier monk whose job was to protect the Temple's property, his martial training was his daily chore. Thus, it was also an opportunity to practice Zen.